public Task DownloadItem(string youPath, string dirPath, PlaylistMenuItem dtype) { throw new NotImplementedException(); // var httpRequest = (HttpWebRequest)WebRequest.Create(MakeLink()); // httpRequest.Method = WebRequestMethods.Http.Post; // httpRequest.Referer = string.Format("{0}={1}", topicUrl, ID); // httpRequest.CookieContainer = cookie; // // Include post data in the HTTP request // const string postData = "dummy="; // httpRequest.ContentLength = postData.Length; // httpRequest.ContentType = "application/x-www-form-urlencoded"; // // Write the post data to the HTTP request // var requestWriter = new StreamWriter(httpRequest.GetRequestStream(), Encoding.ASCII); // requestWriter.Write(postData); // requestWriter.Close(); // var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); // Stream httpResponseStream = httpResponse.GetResponseStream(); // const int bufferSize = 1024; // var buffer = new byte[bufferSize]; // // Read from response and write to file // var dir = new DirectoryInfo(Path.Combine(dirPath, ParentID)); // if (!dir.Exists) // { // dir.Create(); // } // { // string dpath = AviodTooLongFileName(Path.Combine(dir.FullName, MakeTorrentFileName())); // FileStream fileStream = File.Create(dpath); // int bytesRead; // while (httpResponseStream != null && (bytesRead = httpResponseStream.Read(buffer, 0, bufferSize)) != 0) // { // fileStream.Write(buffer, 0, bytesRead); // } // end while // var fn = new FileInfo(dpath); // if (fn.Exists) // { // ItemState = "LocalYes"; // IsHasLocalFile = true; // LocalFilePath = fn.FullName; // } // else // { // ItemState = "LocalNo"; // IsHasLocalFile = false; // } // } }
// Called when the Add to Playlist action is highlighted. // Generates the menu of playlists to which you can add the selected tracks. private void OnAddToPlaylistMenu(object o, EventArgs args) { Source active_source = ServiceManager.SourceManager.ActiveSource; List <Source> children; lock (ActivePrimarySource.Children) { children = new List <Source> (ActivePrimarySource.Children); } // TODO find just the menu that was activated instead of modifying all proxies foreach (Widget proxy_widget in (o as Gtk.Action).Proxies) { MenuItem menu = proxy_widget as MenuItem; if (menu == null) { continue; } Menu submenu = new Menu(); menu.Submenu = submenu; submenu.Append(this ["AddToNewPlaylistAction"].CreateMenuItem()); bool separator_added = false; foreach (Source child in children) { PlaylistSource playlist = child as PlaylistSource; if (playlist != null) { if (!separator_added) { submenu.Append(new SeparatorMenuItem()); separator_added = true; } PlaylistMenuItem item = new PlaylistMenuItem(playlist); item.Image = new Gtk.Image("playlist-source", IconSize.Menu); item.Activated += OnAddToExistingPlaylist; item.Sensitive = playlist != active_source; submenu.Append(item); } } submenu.ShowAll(); } }
public static async Task DownloadPlaylist(IPlaylist playlist, IChannel selectedChannel, string youPath, PlaylistMenuItem dtype) { switch (playlist.Site) { case SiteType.YouTube: foreach (IVideoItem item in selectedChannel.ChannelItems.Where(item => playlist.PlItems.Contains(item.ID)) .Where(item => item.FileState == ItemState.LocalNo)) { item.FileState = ItemState.Planned; } foreach (IVideoItem item in selectedChannel.ChannelItems.Where(item => item.FileState == ItemState.Planned)) { await item.DownloadItem(youPath, selectedChannel.DirPath, dtype).ConfigureAwait(false); } break; } }
public async Task DownloadItem(string youPath, string dirPath, PlaylistMenuItem dtype) { downType = dtype; if (!string.IsNullOrEmpty(ProxyUrl)) { // isProxyReady = CommonExtensions.IsValidUrl(ProxyUrl) && CommonExtensions.IsUrlExist(ProxyUrl); isProxyReady = true; } FileState = ItemState.Downloading; DirectoryInfo dir = ParentID != null ? new DirectoryInfo(Path.Combine(dirPath, ParentID)) : new DirectoryInfo(dirPath); if (!dir.Exists) { dir.Create(); } var options = "--no-check-certificate --console-title --no-call-home --no-cache-dir"; if (isProxyReady) { options += " --proxy " + ProxyUrl; } string param; switch (dtype) { case PlaylistMenuItem.Audio: param = $"--extract-audio -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" --audio-format mp3 {options}"; break; case PlaylistMenuItem.DownloadHd: param = $"-f bestvideo+bestaudio, -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" {options}"; break; case PlaylistMenuItem.DownloadSubs: param = $"-f best, -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" {options} --all-subs"; break; case PlaylistMenuItem.Download: param = $"-f best, -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" {options}"; break; case PlaylistMenuItem.Video: param = $"-f bestvideo, -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" {options}"; break; case PlaylistMenuItem.DownloadSubsOnly: param = $"-f best, -o \"{dir}\\%(title)s.%(ext)s\" \"{MakeLink()}\" {options} --all-subs --skip-download"; break; default: throw new ArgumentOutOfRangeException(nameof(dtype), dtype, null); } if (Subtitles.Select(x => x.IsChecked).Contains(true) && dtype != PlaylistMenuItem.DownloadSubsOnly) { var sb = new StringBuilder(); foreach (ISubtitle sub in Subtitles.Where(sub => sub.IsChecked)) { sb.Append(sub.Language).Append(','); } string res = sb.ToString().TrimEnd(','); string srt = res == "Auto" ? "--write-auto-sub" : $"--write-sub --sub-lang {res}"; param = $"{param} {srt}"; } var startInfo = new ProcessStartInfo(youPath, param) { WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, ErrorDialog = false, CreateNoWindow = true }; taskbar = TaskbarManager.Instance; taskbar.SetProgressState(TaskbarProgressBarState.Normal); await Log("======").ConfigureAwait(false); await Task.Run(() => { var proc = new Process { StartInfo = startInfo, EnableRaisingEvents = true }; proc.OutputDataReceived += EncodeOnOutputDataReceived; proc.ErrorDataReceived += EncodeOnErrorDataReceived; proc.Exited += EncodeOnProcessExited; proc.Start(); proc.StandardInput.Close(); proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); }, cancelToken.Token).ConfigureAwait(false); }
public Task DownloadItem(string youPath, string dirPath, PlaylistMenuItem dtype) { throw new NotImplementedException(); }