YT: support live HLS videos

This commit is contained in:
Rafał Dzięgiel
2021-04-17 16:14:21 +02:00
parent 643c2029d0
commit 62b6de6db2

View File

@@ -319,23 +319,28 @@ var YouTubeClient = GObject.registerClass({
codec: 'h264', codec: 'h264',
type: settings.get_string('yt-quality-type'), type: settings.get_string('yt-quality-type'),
}; };
const dashInfo = await this.getDashInfoAsync(info, itagOpts).catch(debug);
if(dashInfo) { uri = this.getHLSUri(info, itagOpts);
debug('parsed video info to dash info');
const dash = Dash.generateDash(dashInfo);
if(dash) { if(!uri) {
debug('got dash data'); const dashInfo = await this.getDashInfoAsync(info, itagOpts).catch(debug);
const dashFile = await FileOps.saveFilePromise( if(dashInfo) {
'tmp', null, 'clapper.mpd', dash debug('parsed video info to dash info');
).catch(debug); const dash = Dash.generateDash(dashInfo);
if(dashFile) if(dash) {
uri = dashFile.get_uri(); debug('got dash data');
debug('got dash file'); const dashFile = await FileOps.saveFilePromise(
'tmp', null, 'clapper.mpd', dash
).catch(debug);
if(dashFile)
uri = dashFile.get_uri();
debug('got dash file');
}
} }
} }
@@ -437,6 +442,27 @@ var YouTubeClient = GObject.registerClass({
}; };
} }
getHLSUri(info, itagOpts)
{
const isLive = info.videoDetails.isLiveContent;
debug(`video is live: ${isLive}`);
/* YouTube only uses HLS for live content */
if(!isLive)
return null;
const hlsUri = info.streamingData.hlsManifestUrl;
if(!hlsUri) {
debug(new Error('no HLS manifest URL'));
return null;
}
/* TODO: download manifest and select best resolution
* for monitor when adaptive streaming is disabled */
return hlsUri;
}
getBestCombinedUri(info, itagOpts) getBestCombinedUri(info, itagOpts)
{ {
debug(`obtaining best combined URL for resolution: ${itagOpts.width}x${itagOpts.height}`); debug(`obtaining best combined URL for resolution: ${itagOpts.width}x${itagOpts.height}`);
@@ -708,14 +734,21 @@ var YouTubeClient = GObject.registerClass({
_getIsCipher(data) _getIsCipher(data)
{ {
/* Check only first best combined, const stream = (data.formats.length)
* AFAIK there are no videos without it */ ? data.formats[0]
if(data.formats[0].url) : data.adaptiveFormats[0];
if(!stream) {
debug(new Error('no streams'));
return false;
}
if(stream.url)
return false; return false;
if( if(
data.formats[0].signatureCipher stream.signatureCipher
|| data.formats[0].cipher || stream.cipher
) )
return true; return true;