Files
YouTube.js/lib/parser/contents/classes/PlayerStoryboardSpec.js
LuanRT 359020193b dev: start parser refactor on the main codebase, see #65 and #44
Things were getting a bit complicated and slow with the old parser so I decided to continue #44's work on the main codebase.
2022-06-06 04:19:14 -03:00

44 lines
1.1 KiB
JavaScript

'use strict';
class PlayerStoryboardSpec {
type = 'playerStoryboardSpecRenderer';
constructor(data) {
const parts = data.spec.split('|');
const url = new URL(parts.shift());
this.boards = parts.map((part, i) => {
let [
thumbnail_width,
thumbnail_height,
thumbnail_count,
columns,
rows,
interval,
name,
sigh,
] = part.split('#');
url.searchParams.set('sigh', sigh);
thumbnail_count = parseInt(thumbnail_count, 10);
columns = parseInt(columns, 10);
rows = parseInt(rows, 10);
const storyboard_count = Math.ceil(thumbnail_count / (columns * rows));
return {
template_url: url.toString().replace('$L', i).replace('$N', name),
thumbnail_width: parseInt(thumbnail_width, 10),
thumbnail_height: parseInt(thumbnail_height, 10),
thumbnail_count,
interval: parseInt(interval, 10),
columns,
rows,
storyboard_count,
};
});
}
}
module.exports = PlayerStoryboardSpec;