Skip to content

Instantly share code, notes, and snippets.

View peaBerberian's full-sized avatar

Paul Berberian peaBerberian

View GitHub Profile
const playListGenerator = function(
original_playlist, // in format [{url, duration}, ...]
baseTime, // in format timestamp e.g 1516961850
occurences // number of loops to reproduce
){
function loopGeneration(datas, times){
const arrayContents = [];
const overlays = [];
const durations = datas
.map((data) => data.endTime - data.startTime);
const playListGenerator = function(
original_playlist, // in format [{url, duration}, ...]
baseTime, // in format timestamp e.g 1516961850
occurences // number of loops to reproduce
){
function loopGeneration(datas, times){
const arrayContents = [];
const overlays = [];
const durations = datas
.map((data) => data.endTime - data.startTime);
/**
* Find the right box in an isobmff file from its hexa-encoded name.
* @param {Uint8Array} buf - the isobmff
* @param {Number} boxName - the 'name' of the box (e.g. 'sidx' or 'moov'),
* hexa encoded
* @returns {Number} - offset where the corresponding box is (starting with its
* size), -1 if not found.
*/
function findBox(buf, boxName) {
const length = buf.length;
// example ten seconds content
const manifest = {
version: "1.0", // MAJOR.MINOR
// MAJOR = previous parser should not parse it
// MINOR = retro-compatible
duration: 10e3, // total duration of the content
// add timescale?
period: [{
var pb = function prettifyBuffered(buffered) {
var str = "";
var start, end, fixedStart, fixedEnd, fixedDuration, nextStart, fixedDiff;
for (var i = 0; i < buffered.length; i++) {
start = buffered.start(i);
end = buffered.end(i);
fixedStart = start.toFixed(2);
fixedEnd = end.toFixed(2);
fixedDuration = (end - start).toFixed(2);
str += `|${fixedStart}----(${fixedDuration})----|${fixedEnd}`;
const INIT_AUDIO_URL = "https://bitmovin-a.akamaihd.net/content/sintel/audio/stereo/en/128kbit/init.mp4";
const INIT_VIDEO_URL = "https://bitmovin-a.akamaihd.net/content/sintel/video/500kbit/init.mp4";
const VIDEO_SEGMENTS = [
"https://bitmovin-a.akamaihd.net/content/sintel/video/500kbit/segment_1.m4s",
];
const AUDIO_SEGMENTS = [
"https://bitmovin-a.akamaihd.net/content/sintel/audio/stereo/en/128kbit/segment_1.m4s",
];
/**
* Translate groups of 4 big-endian bytes to Integer.
* @param {Uint8Array} bytes
* @param {Number} offset - The offset (from the start of the given array)
* @returns {Number}
*/
function be4toi(bytes, offset) {
return (
(bytes[offset + 0] * 0x1000000) +
(bytes[offset + 1] * 0x0010000) +
// ==UserScript==
// @name Player Tools
// @namespace http://tampermonkey.net/
// @version 0.3.0
// @description try to take over the world!
// @author You
// @match https://www.youtube.com/*
// @match https://www.primevideo.com/*
// @match http://127.0.0.1:8000/
// @grant none
/**
* Pretty print a TimeRanges Object, to see the current content of it in a
* one-liner string.
*
* @param {TimeRanges} buffered
* @returns {string}
* @example
* This function is called by giving it directly the TimeRanges, such as:
* ```js
* prettyPrintBuffered(document.getElementsByTagName("video")[0].buffered);
setTimeout(() => {
console.log("timeout1");
}, 0);
function toto() {
Promise.resolve().then(() => {
console.log("promise2");
});
}
function titi() {
console.log(7);