Files
shaka-player/lib/hls/hls_utils.js
T
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00

94 lines
2.0 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.hls.Utils');
goog.require('shaka.util.ManifestParserUtils');
shaka.hls.Utils = class {
/**
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {string} name
* @return {!Array.<!shaka.hls.Tag>}
*/
static filterTagsByName(tags, name) {
return tags.filter((tag) => {
return tag.name == name;
});
}
/**
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {string} type
* @return {!Array.<!shaka.hls.Tag>}
*/
static filterTagsByType(tags, type) {
return tags.filter((tag) => {
const tagType = tag.getRequiredAttrValue('TYPE');
return tagType == type;
});
}
/**
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {string} name
* @return {?shaka.hls.Tag}
*/
static getFirstTagWithName(tags, name) {
const tagsWithName = shaka.hls.Utils.filterTagsByName(tags, name);
if (!tagsWithName.length) {
return null;
}
return tagsWithName[0];
}
/**
* Get the numerical value of the first tag with given name if available.
* Return the default value if the tag is not present.
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {string} name
* @param {number=} defaultValue
* @return {number}
*/
static getFirstTagWithNameAsNumber(tags, name, defaultValue = 0) {
const tag = shaka.hls.Utils.getFirstTagWithName(tags, name);
const value = tag ? Number(tag.value) : defaultValue;
return value;
}
/**
* @param {string} parentAbsoluteUri
* @param {string} uri
* @return {string}
*/
static constructAbsoluteUri(parentAbsoluteUri, uri) {
const uris = shaka.util.ManifestParserUtils.resolveUris(
[parentAbsoluteUri], [uri]);
return uris[0];
}
/**
* Matches a string to an HLS comment format and returns the result.
*
* @param {string} line
* @return {boolean}
*/
static isComment(line) {
return /^#(?!EXT)/m.test(line);
}
};