// GET: YouTubeVideo public ActionResult Index() { var model = new YouTubeVideoModel { Videos = new List <VideoItem>() }; if (!string.IsNullOrEmpty(WidgetType)) { _wigetType = (YouTubeWidgetType)JsonConvert.DeserializeObject <int>(WidgetType); } model.WidgetType = _wigetType; if (_wigetType == YouTubeWidgetType.List) { LoadListModel(model); } else if (_wigetType == YouTubeWidgetType.Single) { LoadSingleModel(model); } return(View(model)); }
private void LoadListModel(YouTubeVideoModel model) { if (!string.IsNullOrEmpty(NumberToShow)) { _numberToShow = JsonConvert.DeserializeObject <int>(NumberToShow); } if (!string.IsNullOrEmpty(PlayListID)) { model.Videos = YouTubeDataService.GetPlaylistVideos(PlayListID); } else if (!string.IsNullOrEmpty(ChannelID)) { model.Videos.AddRange(YouTubeDataService.GetChannelVideos(ChannelID).Take(_numberToShow).ToList()); } }
protected string GetThumbnailUrl(ref YouTubeVideoModel vid) { switch (UserSettings.ThumbnailQuality) { case 0: return(vid.MaxResThumbnailUrl ?? vid.StandardThumbnailUrl ?? vid.HighThumbnailUrl ?? vid.MediumThumbnailUrl ?? vid.DefaultThumbnailUrl); case 1: return(vid.StandardThumbnailUrl ?? vid.HighThumbnailUrl ?? vid.MediumThumbnailUrl ?? vid.DefaultThumbnailUrl); case 2: return(vid.HighThumbnailUrl ?? vid.MediumThumbnailUrl ?? vid.DefaultThumbnailUrl); case 3: return(vid.MediumThumbnailUrl ?? vid.DefaultThumbnailUrl ?? vid.HighThumbnailUrl); case 4: return(vid.DefaultThumbnailUrl ?? vid.MediumThumbnailUrl ?? vid.HighThumbnailUrl); default: return(vid.StandardThumbnailUrl ?? vid.HighThumbnailUrl ?? vid.MediumThumbnailUrl ?? vid.DefaultThumbnailUrl); } }
//Returns VideoInfo object (Only for video model) public static VideoInfo GetVideoInfo(YouTubeVideoModel videoModel) { //Select the first .mp4 video with 360p resolution VideoInfo video = videoModel.VideoInfo.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360); return video; }
//Returns VideoDownloader object (Only for video model) public static VideoDownloader GetVideoDownloader(YouTubeVideoModel videoModel) { return new VideoDownloader(videoModel.Video, videoModel.FilePath); }
//Downloads Video (Only for video model) public static void DownloadVideo(YouTubeVideoModel vidDownloader) { Task.Run(() => vidDownloader.VideoDownloaderType.Execute()); }
private void LoadSingleModel(YouTubeVideoModel model) { model.Videos.Add(YouTubeDataService.GetSingleVideoItem(VideoID)); }
private void Download(string validatedLink) { if (cmb_FileType.SelectedIndex == 0) { YouTubeVideoModel VideoDownloader = new YouTubeVideoModel(); VideoDownloader.Link = validatedLink; VideoDownloader.FolderPath = tb_DownloadPath.Text; DownloadVideo(VideoDownloader); } else { YouTubeAudioModel AudioDownloader = new YouTubeAudioModel(); AudioDownloader.Link = validatedLink; AudioDownloader.FolderPath = tb_DownloadPath.Text; DownloadAudio(AudioDownloader); } }
private void DownloadVideo(YouTubeVideoModel videoDownloader) { try { //Store VideoInfo object in model videoDownloader.VideoInfo = FileDownloader.GetVideoInfos(videoDownloader); //Stores VideoInfo object in model videoDownloader.Video = FileDownloader.GetVideoInfo(videoDownloader); //Update label within console UpdateLable(videoDownloader.Video.Title + videoDownloader.Video.VideoExtension); //Stores FilePath in model videoDownloader.FilePath = FileDownloader.GetPath(videoDownloader); videoDownloader.FilePath += videoDownloader.Video.VideoExtension; //Stores VideoDownloaderType object in model videoDownloader.VideoDownloaderType = FileDownloader.GetVideoDownloader(videoDownloader); //Stop time after download is complete videoDownloader.VideoDownloaderType.DownloadFinished += (sender, args) => timer1.Stop(); //Enable controls once download is complete videoDownloader.VideoDownloaderType.DownloadFinished += (sender, args) => EnableAccessAbility(); //Open folder with downloaded file selected videoDownloader.VideoDownloaderType.DownloadFinished += (sender, args) => OpenFolder(videoDownloader.FilePath); //Link progress bar up to download progress videoDownloader.VideoDownloaderType.DownloadProgressChanged += (sender, args) => pg_Download.Value = (int)args.ProgressPercentage; CheckForIllegalCrossThreadCalls = false; //Download Video FileDownloader.DownloadVideo(videoDownloader); } catch (Exception) { MessageBox.Show("Download cancelled"); EnableAccessAbility(); } }