private void Sw_DownloadClicked(StreamView sender, RpanData data) { Download dl = new Download(data); dl.DownloadEnded += Dl_DownloadEnded; downloads.Add(data.stream.stream_id, dl); tabs.Items.Add(dl.tab); }
public Download(RpanData data) { this.data = data; string title = System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(data.post.title.ToLowerInvariant()); //string args = "-o \"" + Properties.Settings.Default.downloadDir + title + ".mp4\" " + data.stream.hls_url; string headers = "\"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Accept - Language: en - us,en; q = 0.5 Accept - Encoding: gzip, deflate Accept: text / html,application / xhtml + xml,application / xml; q = 0.9,*/*;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.122 Safari/537.36\""; string args = "-y -headers " + headers + " -i " + data.stream.hls_url + " -c copy -f mp4 -bsf:a aac_adtstoasc \"file:" + Environment.ExpandEnvironmentVariables(Properties.Settings.Default.downloadDir) + title + ".mp4\""; ffProcess = new Process { StartInfo = new ProcessStartInfo { UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, FileName = Properties.Settings.Default.ffmpegPath, Arguments = args } }; ffProcess.OutputDataReceived += FfProcess_DataReceived; ffProcess.ErrorDataReceived += FfProcess_DataReceived; ffProcess.Exited += FfProcess_Exited; string finalTitle; if (title.Length > 15) { finalTitle = string.Concat(title.Take(15)) + "..."; } else { finalTitle = title; } tabHeader.Text = "Download \"" + finalTitle + "\""; tab.Header = new HeaderedContentControl { Content = tabHeader }; tabGrid.Children.Add(logBox); tab.Content = tabGrid; ffProcess.Start(); ffProcess.BeginOutputReadLine(); ffProcess.BeginErrorReadLine(); }
public StreamView(RpanData data, string currentSearchTerm) { rpanData = data; #region UI elements Background = new SolidColorBrush(Color.FromRgb(24, 24, 24)); Height = 80; Margin = new Thickness(10, 5, 10, 0); MouseEnter += StreamView_MouseEnter; MouseLeave += StreamView_MouseLeave; Image img = new Image { Width = 70, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(5) }; StackPanel info = new StackPanel { Margin = new Thickness(70, 5, 90, 5) }; WrapPanel userAndViews = new WrapPanel { Margin = new Thickness(0, 0, 0, -5) }; TextBlock username = new TextBlock { Text = "u/" + data.post.authorInfo.name, Foreground = new SolidColorBrush(Color.FromRgb(0, 200, 255)), Height = 18, Margin = new Thickness(0, 0, 5, 0), }; TextBlock viewers = new TextBlock { Text = data.continuous_watchers + " viewers - " + data.unique_watchers + " unique watchers", Foreground = new SolidColorBrush(Color.FromRgb(200, 200, 200)), Height = 18 }; TextBlock title = new TextBlock { FontFamily = new FontFamily("Segoe UI"), Text = System.Globalization.CultureInfo.InvariantCulture.TextInfo.ToTitleCase(data.post.title.ToLowerInvariant()), Foreground = new SolidColorBrush(Colors.White), Height = 25, Margin = new Thickness(0, 0, 0, -5), FontSize = 17, //FontWeight = FontWeights.Bold, }; WrapPanel buttons = new WrapPanel(); TextBlock messages = new TextBlock { Text = Math.Floor(double.Parse(data.post.commentCount)) + " chat messages", Foreground = new SolidColorBrush(Color.FromRgb(200, 200, 200)), Height = 18 }; openRpan.Visibility = Visibility.Hidden; openRpanMedia.Visibility = Visibility.Hidden; download.Visibility = Visibility.Hidden; openRpan.Click += (s, a) => { Process.Start("https://reddit.com" + data.share_link); }; openRpanMedia.Click += (s, a) => { Process.Start("https://reddit.com" + data.post.permalink); }; download.Click += (s, a) => { DownloadClicked?.Invoke(this, data); }; StackPanel votes = new StackPanel { Width = 80, HorizontalAlignment = HorizontalAlignment.Right, }; TextBlock netVotes = new TextBlock { Foreground = new SolidColorBrush(Color.FromRgb(255, 90, 0)), Text = (data.upvotes - data.downvotes).ToString(), FontWeight = FontWeights.Bold, FontSize = 24, TextAlignment = TextAlignment.Center, Margin = new Thickness(0, 10, 0, -5) }; TextBlock upvotes = new TextBlock { Foreground = new SolidColorBrush(Color.FromRgb(255, 90, 0)), Text = data.upvotes.ToString(), FontSize = 14, TextAlignment = TextAlignment.Center, Margin = new Thickness(0, 0, 0, -3) }; TextBlock downvotes = new TextBlock { Foreground = new SolidColorBrush(Color.FromRgb(0, 90, 255)), Text = data.downvotes.ToString(), FontSize = 14, TextAlignment = TextAlignment.Center }; #endregion if (data.downvotes > data.upvotes) { netVotes.Foreground = new SolidColorBrush(Color.FromRgb(0, 90, 255)); } BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(data.stream.thumbnail, UriKind.Absolute); bitmap.EndInit(); img.Source = bitmap; userAndViews.Children.Add(username); userAndViews.Children.Add(messages); buttons.Children.Add(openRpan); buttons.Children.Add(openRpanMedia); buttons.Children.Add(download); info.Children.Add(userAndViews); info.Children.Add(title); info.Children.Add(viewers); info.Children.Add(buttons); votes.Children.Add(netVotes); votes.Children.Add(upvotes); votes.Children.Add(downvotes); Children.Add(img); Children.Add(info); Children.Add(votes); if (!string.IsNullOrWhiteSpace(currentSearchTerm)) { lastSearchTerm = currentSearchTerm; checkSearchTerm(currentSearchTerm); } }