Skip to content

Commit

Permalink
enable live stream support
Browse files Browse the repository at this point in the history
  • Loading branch information
mp3butcher committed Oct 22, 2024
1 parent c79d278 commit 2fd6657
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Please be aware that this app is only tested on windows, linux and macOS. If you
## Planned features
- Select individual audio and video codecs (advanced mode)
- List all audio qualities
- Support for downloading livestreams

Feel free to [request a new feature](https://github.com/StefanLobbenmeier/youtube-dl-gui/issues).

Expand Down
3 changes: 3 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ function startCriticalHandlers(env) {
case "stop":
queryManager.stopDownload(args.identifier);
break;
case "remove":
queryManager.removeDownload(args.identifier);
break;
case "open":
queryManager.openVideo(args);
break;
Expand Down
12 changes: 10 additions & 2 deletions modules/QueryManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class QueryManager {
this.removeVideo(metadataVideo);
break;
case "livestream":
this.environment.errorHandler.raiseError({code: "Not supported", description: "Livestreams are not yet supported."}, metadataVideo.identifier);
this.manageSingle(initialQuery, url, headers);
this.removeVideo(metadataVideo);
break;
default:
//This.environment.errorHandler.raiseUnhandledError("Youtube-dl returned an empty object\n" + JSON.stringify(Utils.detectInfoType(initialQuery), null, 2), metadataVideo.identifier);
Expand Down Expand Up @@ -357,14 +358,21 @@ class QueryManager {
}
}

stopDownload(identifier) {
removeDownload(identifier) {
let video = this.getVideo(identifier);
if (video.query != null) {
video.query.cancel();
}
this.removeVideo(video);
}

stopDownload(identifier) {
let video = this.getVideo(identifier);
if (video.query != null) {
video.query.cancel();
}
}

async openVideo(args) {
let video = this.getVideo(args.identifier);
let file = video.filename;
Expand Down
17 changes: 16 additions & 1 deletion modules/download/DownloadQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,26 @@ class DownloadQuery extends Query {
let destinationCount = 0;
let initialReset = false;
let result = null;
const regexliverec = /size=\s*(\d+\w)iB\s*time=(\d+:\d+:\d+.\d+)\s*bitrate=\s*(\d+.\d+\w)bits\/s\s*speed=\d+.\d+x/;
try {
result = await this.environment.downloadLimiter.schedule(() => this.start(this.url, args, (liveData) => {
this.environment.logger.log(this.video.identifier, liveData);
this.video.setFilename(liveData);

if(this.video.is_live) {
if (!initialReset) {
initialReset = true;
this.progressBar.reset();
return;
}
try{
const livrec = liveData.match(regexliverec);
if (typeof (`${livrec[1]}`) == "undefined") return;
this.progressBar.updateDownload('livestream', `${livrec[2]}`, `${livrec[3]}bits\/s`, this.video.audioOnly || this.video.downloadingAudio);
} catch(e) {
return;
}
return;
}
if (!liveData.includes("[download]")) return;

if (liveData.includes("Destination")) destinationCount += 1;
Expand Down
7 changes: 5 additions & 2 deletions modules/types/Query.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const child_process = require('child_process');
const execa = require('execa');
const UserAgent = require('user-agents');

Expand All @@ -12,7 +13,9 @@ class Query {
stop() {
this.stopped = true;
if(this.process != null) {
this.process.cancel();
if (this.progressBar.video.is_live)
process.kill(this.process.pid, 'SIGINT');///Only way to stop ffmpeg lives
else this.process.kill();
}
}

Expand Down Expand Up @@ -79,7 +82,7 @@ class Query {
//Return data while the query is running (live)
//Return "done" when the query has finished
return await new Promise((resolve) => {
this.process = execa(command, args);
this.process = child_process.spawn(command, args);
this.process.stdout.setEncoding('utf8');
this.process.stdout.on('data', (data) => {
const lines = data
Expand Down
2 changes: 2 additions & 0 deletions modules/types/Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Video {
this.error = false;
this.filename = null;
this.identifier = Utils.getRandomID(32);
this.is_live = false;
}

setFilename(liveData) {
Expand Down Expand Up @@ -120,6 +121,7 @@ class Video {
this.formats = Utils.parseAvailableFormats(metadata);
this.audioCodecs = Utils.parseAvailableAudioCodecs(metadata);
this.selected_format_index = this.selectHighestQuality();
this.is_live = (metadata.is_live != null && metadata.is_live === true);
}

selectHighestQuality() {
Expand Down
3 changes: 2 additions & 1 deletion renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,11 @@ function removeVideo(card) {
if(btn.hasClass("clicked") || $(card).find(".custom-select.download-type").is(":visible") || $(card).find(".btn.btn-dark.folder").is(":visible") || $(card).find(".row.error.d-none").is(":visible") || $(card).find(".url").length) {
$(btn).popover('hide');
$(card).remove();
window.main.invoke("videoAction", {action: "stop", identifier: $(card).prop("id")});
window.main.invoke("videoAction", {action: "remove", identifier: $(card).prop("id")});
} else {
$(btn).popover('show');
$(btn).addClass("clicked");
window.main.invoke("videoAction", {action: "stop", identifier: $(card).prop("id")});
}
}

Expand Down

0 comments on commit 2fd6657

Please sign in to comment.