Skip to content

Commit

Permalink
display multiple file download in progress msg
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptowyrm committed Nov 1, 2018
1 parent 584df02 commit 61c8e4f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/DownloadRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
36 changes: 31 additions & 5 deletions src/VideoDownload.vala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace CopyPasteGrab {

public void stop() {
status = DownloadStatus.PAUSED;
this.video.file_count = 0;
video_download_command.stop ();
}

Expand Down Expand Up @@ -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 ();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 (" "));

Expand Down
2 changes: 2 additions & 0 deletions src/VideoInfo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {

Expand Down

0 comments on commit 61c8e4f

Please sign in to comment.