private void DeleteVideo(object sender, RoutedEventArgs e) { MenuItem currentItem = (MenuItem)sender; InnerTubeVideo deleteVideo = (InnerTubeVideo)currentItem.CommandParameter; Deleted.Delete(App.InnerTubeFeeds, deleteVideo); }
public static bool ConvertedFilesExist(InnerTubeVideo video, Setting settings) { //iTunes needs WMV & MP4 if (settings.iTunesInstalled) { if (File.Exists(video.DownloadedWmv) && File.Exists(video.DownloadedMp4)) { return(true); } else { return(false); } } else { if (File.Exists(video.DownloadedWmv)) { return(true); } else { return(false); } } }
private object downloadImages(object state) { checkForCancellation(); //Convert to Feed Type InnerTubeVideo vid = (InnerTubeVideo)state; Download.DownloadImage(vid); string status; if (File.Exists(vid.DownloadedImage)) { status = String.Format("Image for Video: {0} SUCCESSFULLY downloaded to {1}", vid.Title, vid.DownloadedImage); } else { status = String.Format("Image for Video: {0} FAILED to download to {1}", vid.Title, vid.DownloadedImage); } WriteStatus(status); return(status); }
public static void ConvertFlv(InnerTubeVideo source, ConversionType conversion) { string title = FileHelper.ReplaceIllegalCharacters(source.Title); string author = FileHelper.ReplaceIllegalCharacters(source.Author); string description = FileHelper.ReplaceIllegalCharacters(source.Description); //set values based on switch string cmdLineArgs = String.Empty; string destination = String.Empty; switch (conversion) { case ConversionType.Mp4: //ffmpeg.exe -title "Chocolate Rain" -author "TayZonday" -comment "Original Song by Tay Zonday" -i "Chocolate Rain.flv" "Chocolate Rain.mp4" destination = source.DownloadedMp4; cmdLineArgs = String.Format(" -title \"{0}\" -author \"{1}\" -comment \"{2}\" -i \"{3}\" \"{4}\"", title, author, description, source.DownloadedFlv, destination); break; case ConversionType.Wmv: //ffmpeg.exe -title "Chocolate Rain" -author "TayZonday" -comment "Original Song by Tay Zonday" -i "Chocolate Rain.flv" -vcodec wmv2 "Chocolate Rain.wmv" destination = source.DownloadedWmv; cmdLineArgs = String.Format(" -title \"{0}\" -author \"{1}\" -comment \"{2}\" -i \"{3}\" -vcodec wmv2 \"{4}\"", title, author, description, source.DownloadedFlv, destination); break; } ConvertFlv(source.DownloadedFlv, destination, cmdLineArgs); }
public static void DownloadImage(InnerTubeVideo source, string destination) { //if we haven't downloaded the image yet, download it if (!File.Exists(destination)) { using (WebClient wc = new WebClient()) { wc.DownloadFile(new Uri(source.ThumbnailLink), destination); } } }
private object downloadVideo(object state) { //parse values InnerTubeVideo vid = (InnerTubeVideo)state; WriteStatus("Starting download for: " + vid.Title); //Call download task, may take a few minutes to execute Download.DownloadVideo(vid); WriteStatus("video downloaded to fullPath: " + vid.DownloadedFlv); return(vid.DownloadedFlv); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { InnerTubeVideo v = (InnerTubeVideo)value; if (!String.IsNullOrEmpty(v.DownloadedWmv)) { return(v.DownloadedWmv); } else { return(v.DownloadedImage); } }
private object convertVideo(object state) { checkForCancellation(); InnerTubeVideo video = (InnerTubeVideo)state; WriteStatus("Starting conversion for file: " + video.Title); VideoConverter.ConvertFlv(video, ConversionType.Wmv); string status; //only convert to MP4 if they've said to add to iTunes if (settings.iTunesInstalled) { VideoConverter.ConvertFlv(video, ConversionType.Mp4); if (File.Exists(video.DownloadedMp4) && (FileHelper.FileSize(video.DownloadedMp4) > 0) && File.Exists(video.DownloadedWmv) && (FileHelper.FileSize(video.DownloadedWmv) > 0)) { //Delete Flv if (video.DownloadedFlv != null) { File.Delete(video.DownloadedFlv); } status = String.Format("Conversion COMPLETE for: {0} at: {1} and {2}", video.Title, video.DownloadedMp4, video.DownloadedWmv); } else { status = String.Format("Conversion FAILED for: {0} at: {1} and {2}", video.Title, video.DownloadedMp4, video.DownloadedWmv); } } else { if (File.Exists(video.DownloadedWmv) && (FileHelper.FileSize(video.DownloadedWmv) > 0)) { //WMV created, delete the FLV File.Delete(video.DownloadedFlv); status = String.Format("Conversion COMPLETE for: {0} at: {1}", video.Title, video.DownloadedWmv); } else { //WMV not created status = String.Format("Conversion FAILED for: {0} at: {1}", video.Title, video.DownloadedWmv); } } WriteStatus(status); return(status); }
public static void DownloadVideo(InnerTubeVideo source, string destination) { if (!File.Exists(destination)) { UriBuilder final = new UriBuilder(source.DownloadLink); final.Query = "video_id=" + source.Id + "&" + CreateTokenRequest(source); WebRequest request = WebRequest.Create(final.ToString()); request.Timeout = 500000; try { WebResponse response = request.GetResponse(); using (Stream webStream = response.GetResponseStream()) { try { int _bufferSize = 65536; using (FileStream fs = File.Create(destination, _bufferSize)) { int readBytes = -1; byte[] inBuffer = new byte[_bufferSize]; //Loop until we hit the end while (readBytes != 0) { //read data from web into filebuffer, then write to file readBytes = webStream.Read(inBuffer, 0, _bufferSize); fs.Write(inBuffer, 0, readBytes); } } } catch (Exception ex) { Debug.WriteLine("Error in Buffer Download"); Debug.Indent(); Debug.WriteLine(ex.Message); } } } catch (Exception ex) { Debug.WriteLine("Error in request.GetResponse()"); Debug.Indent(); Debug.WriteLine(ex.Message); } } }
private static void InnerTubeVideoFileChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MediaPlayer player = (MediaPlayer)d; InnerTubeVideo newVideo = (InnerTubeVideo)e.NewValue; //reset UI player.PreviewImage.Visibility = Visibility.Visible; player.PlayButton.IsChecked = false; player.PreviewImage.Source = null; if (newVideo != null) { //Set Image ImageSourceConverter imageConvert = new ImageSourceConverter(); if (File.Exists(newVideo.DownloadedImage)) { player.PreviewImage.Source = (ImageSource)imageConvert.ConvertFromString(newVideo.DownloadedImage); } else { string defaultImage = System.IO.Path.Combine(App.Settings.SubPath, FileHelper.DefaultImage); if (File.Exists(defaultImage)) { player.PreviewImage.Source = (ImageSource)imageConvert.ConvertFromString(defaultImage); } else { player.PreviewImage.Source = null; } } //Set and enable Video if we have one if (!String.IsNullOrEmpty(newVideo.DownloadedWmv) && !File.Exists(newVideo.DownloadedWmv)) { player.isVideo = false; player.SetEnabledPlayButton(false); } else { //Set Video File player.VideoPlayer.Source = new Uri(newVideo.DownloadedWmv); player.isVideo = true; player.SetEnabledPlayButton(true); } } }
private static string CreateTokenRequest(InnerTubeVideo video) { //YouTube variables const string jsVariable = "swfArgs"; const string argName = "t"; //get raw html from YouTube video page string rawHtml; using (WebClient wc = new WebClient()) { rawHtml = wc.DownloadString(video.Link); } //extract the JavaScript name/value pairs int jsIndex = rawHtml.IndexOf(jsVariable); int startIndex = rawHtml.IndexOf("{", jsIndex); int endIndex = rawHtml.IndexOf("}", startIndex); string fullString = rawHtml.Substring(startIndex + 1, endIndex - startIndex - 1); //remove all quotes (") fullString = fullString.Replace("\"", ""); //split all values string[] allArgs = fullString.Split(','); //loop through javascript parameters foreach (string swfArg in allArgs) { if (swfArg.Trim().StartsWith(argName)) { var nameValuePair = swfArg.Split(':'); return(string.Format("{0}={1}", argName, nameValuePair[1].Trim())); } } throw new Exception(string.Format("token not found in swfArgs, make sure {0} is accessible", video.Link)); }
public static void Delete(System.Collections.ObjectModel.ObservableCollection <InnerTubeFeed> feedList, InnerTubeVideo deleteMe) { for (int i = 0; i < feedList.Count; i++) { feedList[i].FeedVideos.Remove(deleteMe); } }
public static void DownloadVideo(InnerTubeVideo source) { DownloadVideo(source, source.DownloadedFlv); }
public static void DownloadImage(InnerTubeVideo source) { DownloadImage(source, source.DownloadedImage); }