public DownloadThread(string ID, string Name, string Location, string Format) //video from playlist { queuedForStop = false; PrepareAndDownload = null; NameSetter = null; FormatAndSizeSetter = null; downloadThread = null; DownloadAudio = null; didIdeleteFilesOnce = false; download = null; trim = null; UpdateSizePeriodically = false; //if size remains Unknown, this is true FormatErrorCounter = 0; //if it becomes 2, set status to 4 this.Name = Name; Size = "Unknown"; this.Format = "Unknown"; Progress = 0; DownloadSpeed = "Unknown"; ETA = "Unknown"; this.Location = Location.Replace('\\', '/'); Status = 1; //Vo format dozvoleno e: 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p i best (ili 720p60, 1080p60, 1440p60, 2160p60 i p60 (za best vo 60p)) PrepareAndDownload = new Thread(() => PrepareDownload(ID, Format)); //Main thread so that object is not blocked PrepareAndDownload.IsBackground = true; PrepareAndDownload.Start(); }
public DownloadThread(string ID, string Name, string Location, string Format, Trim Trim, string NullForAudioDifferantiation) //audio from playlist { queuedForStop = false; PrepareAndDownload = null; NameSetter = null; FormatAndSizeSetter = null; downloadThread = null; DownloadAudio = null; didIdeleteFilesOnce = false; download = null; trim = Trim; UpdateSizePeriodically = false; //doesn't matter FormatErrorCounter = 0; //doesn't matter Format = null; //doesn't matter this.Name = Name; Size = "Unknown"; this.Format = "Unknown"; Progress = 0; DownloadSpeed = "Unknown"; ETA = "Unknown"; this.Location = Location.Replace('\\', '/'); Status = 1; DownloadAudio = new Thread(() => StartAudioDownload(ID, this.Location)); DownloadAudio.IsBackground = true; DownloadAudio.Start(); }
private void btnDownload_Click(object sender, EventArgs e) { if (!Directory.Exists(AllUserConfig.downloadLocation)) { MessageBox.Show(AllUserConfig.languageRM.GetString("directoryDoesntExist")); return; } Button activityTabButton = Application.OpenForms["Main"].Controls["btnActivityTab"] as Button; Button downloadTabButton = Application.OpenForms["Main"].Controls["btnDownloadTab"] as Button; activityTabButton.BackColor = DefaultBackColor; activityTabButton.FlatAppearance.MouseOverBackColor = DefaultBackColor; downloadTabButton.BackColor = Color.DarkGray; downloadTabButton.FlatAppearance.MouseOverBackColor = Color.FromArgb(152, 152, 152); ActivityTab activityTab = Application.OpenForms["ActivityTab"] as ActivityTab; activityTab.Activate(); ActivityTab tempForm = Application.OpenForms["ActivityTab"] as ActivityTab; Trim trim = new Trim(tbStartTime.Text, tbEndTime.Text); string format; switch (ddQualitySelection.SelectedIndex) { case 1: format = "best"; break; case 2: format = "2160p"; break; case 3: format = "1440p"; break; case 4: format = "1080p"; break; case 5: format = "720p"; break; case 6: format = "480p"; break; case 7: format = "360p"; break; case 8: format = "240p"; break; case 9: format = "144p"; break; case 11: format = "mp3"; break; default: format = "best"; break; } if (cb60fps.Enabled && cb60fps.Checked && format != "best") { format = format + "60"; } else if ((cb60fps.Enabled && cb60fps.Checked && format == "best")) { format = "p60"; } if (trim.isValid()) { tempForm.startAddingVideos(IdExtractor.GetIdsAndTypes(tbLinks.Text), llDownloadLocation.Text, format, trim); } else { tempForm.startAddingVideos(IdExtractor.GetIdsAndTypes(tbLinks.Text), llDownloadLocation.Text, format, null); } tbLinks.Text = ""; tbStartTime.Text = "00:00:00"; tbEndTime.Text = "00:00:00"; }
public void startAddingVideos(Dictionary <string, string> videos, string Location, string Format, Trim trim) { bool downloadAsPlaylist = true; bool askForChoice = true; foreach (KeyValuePair <string, string> video in videos) //the key is the id, and the value is the type (playlist, video or playlistId) { if (!videoExists(video.Key)) { if (video.Value == "Video") { if (Format == "mp3") { addNewVideoToList(new Video(video.Key, Location, Format, trim)); } else { addNewVideoToList(new Video(video.Key, Location, Format)); } } else if (video.Value == "Playlist") { addNewPlaylistToList(video.Key, Location, Format); } else { if (askForChoice) { PlaylistAndVideoQuestionForm form = new PlaylistAndVideoQuestionForm(); if (form.ShowDialog() == DialogResult.OK) { addNewPlaylistToList(video.Value, Location, Format); } else { downloadAsPlaylist = false; if (Format == "mp3") { addNewVideoToList(new Video(video.Key, Location, Format, trim)); } else { addNewVideoToList(new Video(video.Key, Location, Format)); } } askForChoice = false; } else { if (downloadAsPlaylist) { addNewPlaylistToList(video.Value, Location, Format); } else { if (Format == "mp3") { addNewVideoToList(new Video(video.Key, Location, Format, trim)); } else { addNewVideoToList(new Video(video.Key, Location, Format)); } } } } } else { string alreadyAddedVideoTitle = video.Key; foreach (VideoListItem videoItem in lvActiveDownloads.Items) { if (((Video)videoItem.Tag).getID() == video.Key) { alreadyAddedVideoTitle = ((Video)videoItem.Tag).getName(); break; } } MessageBox.Show(AllUserConfig.languageRM.GetString("msgVideoAlreadyInActivityTab1") + alreadyAddedVideoTitle + AllUserConfig.languageRM.GetString("msgVideoAlreadyInActivityTab2")); } } }
private void takeActionOnVideo(string actionId) { switch (actionId) { case "pause": case "resumePause": { int videoStatus = ((Video)lvActiveDownloads.SelectedItems[0].Tag).getStatus(); if (videoStatus > 7) { string ID = null; string Location = null; string Format = null; string Type = null; Trim trim = null; foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ID = ((Video)video.Tag).getID(); Location = ((Video)video.Tag).getLocation(); Format = ((Video)video.Tag).getFormat(); Type = ((Video)video.Tag).getType(); trim = ((Video)video.Tag).getTrim(); video.Remove(); if (Type == "Video") { addNewVideoToList(new Video(ID, Location, Format)); } else { addNewVideoToList(new Video(ID, Location, Format, trim)); } } } else { foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).queueForStop(); } foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).pauseDownload(); } } break; } case "stop": { foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).queueForStop(); } foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).cancelDownload(); updateInfoOnce(video); } break; } case "openFolder": { Process.Start("explorer.exe", ((Video)lvActiveDownloads.SelectedItems[0].Tag).getLocation()); break; } case "deleteActivity": { foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).queueForStop(); } foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).pauseDownload(); video.Remove(); if (playlistThreads.ContainsKey(((Video)video.Tag).getID())) { playlistThreads[((Video)video.Tag).getID()].Abort(); playlistThreads.Remove(((Video)video.Tag).getID()); } } break; } case "deleteFile": { foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).queueForStop(); } foreach (VideoListItem video in lvActiveDownloads.SelectedItems) { ((Video)video.Tag).cancelDownload(); video.Remove(); if (playlistThreads.ContainsKey(((Video)video.Tag).getID())) { playlistThreads[((Video)video.Tag).getID()].Abort(); playlistThreads.Remove(((Video)video.Tag).getID()); } } break; } default: { break; } } }