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,6 +319,10 @@ var YouTubeClient = GObject.registerClass({
codec: 'h264',
type: settings.get_string('yt-quality-type'),
};
uri = this.getHLSUri(info, itagOpts);
if(!uri) {
const dashInfo = await this.getDashInfoAsync(info, itagOpts).catch(debug);
if(dashInfo) {
@@ -338,6 +342,7 @@ var YouTubeClient = GObject.registerClass({
debug('got dash file');
}
}
}
if(!uri)
uri = this.getBestCombinedUri(info, itagOpts);
@@ -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)
{
debug(`obtaining best combined URL for resolution: ${itagOpts.width}x${itagOpts.height}`);
@@ -708,14 +734,21 @@ var YouTubeClient = GObject.registerClass({
_getIsCipher(data)
{
/* Check only first best combined,
* AFAIK there are no videos without it */
if(data.formats[0].url)
const stream = (data.formats.length)
? data.formats[0]
: data.adaptiveFormats[0];
if(!stream) {
debug(new Error('no streams'));
return false;
}
if(stream.url)
return false;
if(
data.formats[0].signatureCipher
|| data.formats[0].cipher
stream.signatureCipher
|| stream.cipher
)
return true;