From 61c8e4f9e903013ded8fcba485d7da583651f69a Mon Sep 17 00:00:00 2001 From: CryptoWyrm Date: Thu, 1 Nov 2018 13:22:54 +0100 Subject: [PATCH] display multiple file download in progress msg --- src/DownloadRow.vala | 10 +++++++++- src/VideoDownload.vala | 36 +++++++++++++++++++++++++++++++----- src/VideoInfo.vala | 2 ++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/DownloadRow.vala b/src/DownloadRow.vala index f5a2ef1..d8194dc 100644 --- a/src/DownloadRow.vala +++ b/src/DownloadRow.vala @@ -117,7 +117,15 @@ namespace CopyPasteGrab { this.video_download.progress.connect ((progress, msg) => { progress_bar.set_fraction (progress / 100.0); - progress_bar.text = "Downloading: " + msg; + string progress_msg; + + if (video_download.video.dual == true) { + progress_msg = @"Downloading $(video_download.video.file_count)/2 $(msg)"; + } else { + progress_msg = @"Downloading $(msg)"; + } + + progress_bar.text = progress_msg; }); this.video_download.video_info.connect ((info) => { diff --git a/src/VideoDownload.vala b/src/VideoDownload.vala index db41983..02239e0 100644 --- a/src/VideoDownload.vala +++ b/src/VideoDownload.vala @@ -104,6 +104,7 @@ namespace CopyPasteGrab { public void stop() { status = DownloadStatus.PAUSED; + this.video.file_count = 0; video_download_command.stop (); } @@ -143,6 +144,7 @@ namespace CopyPasteGrab { parser.load_from_file (json_path); } catch (Error e) { print ("Unable to parse data: %s\n", e.message); + return; } Json.Node node = parser.get_root (); @@ -151,22 +153,39 @@ namespace CopyPasteGrab { foreach (string member in reader.list_members ()) { switch (member) { case "title": - if (reader.read_member ("title")) { + if (reader.read_member ("title") && !reader.get_null_value ()) { string video_title = reader.get_string_value (); - print ("Video title: %s\n", video_title); + reader.end_member (); this.video.title = video_title; + } else { reader.end_member (); } break; case "is_live": - if (reader.read_member ("is_live")) { + if (reader.read_member ("is_live") && !reader.get_null_value ()) { + bool is_live = reader.get_boolean_value (); + reader.end_member (); if (is_live == true) { status = DownloadStatus.ERROR; error ("Downloading live streams isn't supported"); + return; } + } else { + reader.end_member (); + } + break; + case "format_id": + if (reader.read_member ("format_id") && !reader.get_null_value ()) { + string format_id = reader.get_string_value (); + reader.end_member (); + if (format_id != null) { + if (format_id.index_of ("+") > -1) { + this.video.dual = true; + } + } + } else { reader.end_member (); - return; } break; } @@ -211,7 +230,14 @@ namespace CopyPasteGrab { if(status != DownloadStatus.DOWNLOADING) { status = DownloadStatus.DOWNLOADING; } - + + // dual video file merging + if (line.index_of ("[download] Destination: ") > -1) { + this.video.file_count += 1; + print ("file_count: %d\n", this.video.file_count); + } + + // progress double progress_value = double.parse(line.slice(line.index_of(" "), line.index_of("%")).strip()); string progress_msg = line.substring (line.index_of (" ")); diff --git a/src/VideoInfo.vala b/src/VideoInfo.vala index 86ee69a..052630a 100644 --- a/src/VideoInfo.vala +++ b/src/VideoInfo.vala @@ -26,6 +26,8 @@ namespace CopyPasteGrab { public string title { get; set; } public string? thumbnail { get; set; } public string json { get; set; } + public bool dual { get; set; default = false; } + public int file_count { get; set; default = 0; } public VideoInfo () {