Skip to content

Commit

Permalink
refactor(HLS): Refactor URLs management in HLS (#5864)
Browse files Browse the repository at this point in the history
It also improves the detection of duplicate playlists, and improves
redirect management, leaving the original URL available in case it is
needed.
  • Loading branch information
avelad authored Nov 14, 2023
1 parent c79e5a5 commit 0dba256
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 287 deletions.
36 changes: 25 additions & 11 deletions lib/hls/hls_classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ goog.require('shaka.util.Error');
*/
shaka.hls.Playlist = class {
/**
* @param {string} absoluteUri An absolute, final URI after redirects.
* @param {!shaka.hls.PlaylistType} type
* @param {!Array.<shaka.hls.Tag>} tags
* @param {!Array.<shaka.hls.Segment>=} segments
*/
constructor(absoluteUri, type, tags, segments) {
/**
* An absolute, final URI after redirects.
*
* @const {string}
*/
this.absoluteUri = absoluteUri;

constructor(type, tags, segments) {
/** @const {shaka.hls.PlaylistType} */
this.type = type;

Expand Down Expand Up @@ -86,10 +78,11 @@ shaka.hls.Tag = class {
* As in some cases (like in tests) the tag never existed in string form, it
* is far easier to recreate the tag from the parsed form.
*
* @param {?Set.<string>=} attributesToSkip
* @return {string}
* @override
*/
toString() {
toString(attributesToSkip) {
/**
* @param {shaka.hls.Attribute} attr
* @return {string}
Expand All @@ -106,7 +99,12 @@ shaka.hls.Tag = class {
// 4) <NAME>:<VALUE>,<ATTRIBUTE_LIST>

let tagStr = '#' + this.name;
const appendages = this.attributes ? this.attributes.map(attrToStr) : [];
const appendages = this.attributes ? this.attributes.filter((attr) => {
if (!attributesToSkip) {
return true;
}
return !attributesToSkip.has(attr.name);
}).map(attrToStr) : [];

if (this.value) {
appendages.unshift(this.value);
Expand All @@ -119,6 +117,22 @@ shaka.hls.Tag = class {
return tagStr;
}

/**
* Create the string key of the tag.
*
* @return {string}
*/
getTagKey() {
const attributesToSkip = new Set()
.add('AUDIO')
.add('VIDEO')
.add('SUBTITLES')
.add('PATHWAY-ID')
.add('GROUP-ID')
.add('URI');
return this.toString(attributesToSkip);
}

/**
* Adds an attribute to an HLS Tag.
*
Expand Down
Loading

0 comments on commit 0dba256

Please sign in to comment.