/// <summary>
 /// Clears a selected task
 /// </summary>
 /// <param name="msg"></param>
 protected override void ClearDownload(ClearMessage msg)
 {
     foreach (var task in DownloadingItems.Where(task => task.DataContext == msg.DownloadItemViewModel).ToList())
     {
         var viewModel = (DownloadItemViewModel)task.DataContext;
         viewModel.Dispose();
         DownloadingItems.Remove(task);
     }
 }
Пример #2
0
 private void ReadyToNextDownload()
 {
     var downInfo = DownloadingItems.FirstOrDefault(v => v.DownloadState == DownloadState.Await);
     if (downInfo != null)
     {
         ReadyToDownload(downInfo);
     }
     else
     {
         _isDownloading = false;
     }
 }
        /// <summary>
        /// Adds a new download task
        /// </summary>
        /// <param name="msg"></param>
        protected override void NewDownload(DownloadMessage msg)
        {
            try
            {
                DownloadingItems.Add(new DownloadItemView {
                    DataContext = new DownloadItemViewModel(msg.Url)
                });
            }

            catch (Exception ex)
            {
                DialogService.ShowMessageBox(ex.Message);
            }
        }
        /// <summary>
        /// Clears all tasks that are not in progress
        /// </summary>
        public void Clear()
        {
            // Get all tasks which have either status finished, canceled or error
            var tasksToClear = from task in DownloadingItems
                               let dataContext = (DownloadItemViewModel)task.DataContext
                                                 where !dataContext.IsDownloading
                                                 select task;

            foreach (var task in tasksToClear.ToList())
            {
                var viewModel = (DownloadItemViewModel)task.DataContext;
                viewModel.Dispose();
                DownloadingItems.Remove(task);
            }
        }
Пример #5
0
 /// <summary>
 /// 删除不存在关联的本地文件
 /// </summary>
 private void CheckRubbishDownload()
 {
     try
     {
         using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
         {
             var locals = isoStore.GetFileNames("/PersonalCenter/MyDownload/*");
             var files = locals.Where(v => v.Contains(".mp4")).Select(v => v);
             var rubbishs = files.Except(DownloadingItems.Select(v => v.LocalFileName)).Except(DownloadedItems.Select(v => v.LocalFileName));
             foreach (var rubbish in rubbishs)
             {
                 isoStore.DeleteFile(rubbish);
             }
         }
     }
     catch { }
 }
Пример #6
0
        /// <summary>
        /// 删除不存在关联的本地文件
        /// </summary>
        private async void CheckRubbishDownload()
        {
            var folder = ApplicationData.Current.LocalFolder;

            try
            {
                var locals = await folder.GetFilesAsync();

                var files    = locals.Where(v => v.Name.Contains(".mp4")).Select(v => v.Name);
                var rubbishs = files.Except(DownloadingItems.Select(v => v.LocalFileName)).Except(DownloadedItems.Select(v => v.LocalFileName));
                foreach (var rubbish in rubbishs)
                {
                    var file = await folder.GetFileAsync(rubbish);

                    await file.DeleteAsync();
                }
            }
            catch { }
        }
Пример #7
0
        /// <summary>
        /// Invoked when BtnExtract is clicked
        /// Starts the extraction process of a video or playlist
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BtnExtract_Click(object sender, RoutedEventArgs e)
        {
            //The list of videos available for download
            IEnumerable <VideoInfo> videoList = null;

            //Prevent another video being downloaded
            DisableExtractionButton(WAIT_TEXT);

            //Get the video info
            videoList = await Task.Run(() => ResolveURL(ExtractionUrl));

            //Check that the return was not null
            if (videoList == null)
            {
                MessageBox.Show("The URL entered is not a valid YouTube video URL!");
                EnableExtractionButton(DOWNLOAD_TEXT_QUERY);
                return;
            }

            //The user download preferences selector
            WndwInfoSelector infoSelector = null;
            //The video to download
            VideoInfo video = null;

            while (true)
            {
                //Get the user preferences
                infoSelector = GetUserDownloadPreferences(videoList);

                //If we are to download video, else download audio
                if (infoSelector.SelectedDownloadType == DownloadType.Video)
                {
                    //Try to find the first element
                    try
                    {
                        //Get the first video with the selected resolution and format and highest bitrate
                        video = videoList.Where(info => info.Resolution == infoSelector.SelectedVideoResolution &&
                                                info.VideoExtension == infoSelector.SelectedVideoExtension && info.AudioBitrate == infoSelector.SelectedAudioBitrate)
                                .First();
                        break;
                    }
                    catch
                    {
                        MessageBox.Show("We couldn't find a video with the stats that you selected!");
                        continue;
                    }
                }
                else
                {
                    try
                    {
                        //Get the first video with the selected resolution and format and highest bitrate
                        video = videoList.Where(info => info.AudioBitrate == infoSelector.SelectedAudioBitrate &&
                                                info.AudioExtension == infoSelector.SelectedAudioExtension && info.CanExtractAudio)
                                .First();
                        break;
                    } catch
                    {
                        MessageBox.Show("We couldn't find an audio track with the stats that you selected!");
                        continue;
                    }
                }
            }

            //If the video has an encrypted signature, decode it
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            //Get the download folder location
            string downloadLocation = ShowFolderSelectionDialog();

            if (infoSelector.SelectedDownloadType == DownloadType.Video)
            {
                //Create the downloader
                VideoDownloader downloader = new VideoDownloader(video, Path.Combine(downloadLocation, DownloadItem.PathCleaner(video.Title) + video.VideoExtension));

                //Create a new DownloadVideo item
                DownloadVideoItem item = new DownloadVideoItem(DownloadType.Video, video.Title, downloader);

                //Add a new DownloadVideoItem
                DownloadingItems.Add(item);

                EnableExtractionButton(DOWNLOAD_TEXT_QUERY);
            }
            else
            {
                //Create the audio downloader
                AudioDownloader downloader = new AudioDownloader(video, Path.Combine(downloadLocation, DownloadItem.PathCleaner(video.Title) + video.AudioExtension));

                //Create a new DownloadAudio item
                DownloadAudioItem item = new DownloadAudioItem(DownloadType.Audio, video.Title, downloader);

                //Add the new DownloadAudioItem
                DownloadingItems.Add(item);

                EnableExtractionButton(DOWNLOAD_TEXT_QUERY);
            }
        }