コード例 #1
0
        private async void Download_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MainWindow.AddPage(new PleaseWait());
            var     ser     = Database.GetSeries((int)episode.seriesId);
            Torrent torrent = await Torrent.SearchSingle(ser, episode, Settings.DownloadQuality);

            if (torrent != null)
            {
                TorrentDownloader downloader = new TorrentDownloader(torrent);
                await downloader.Download();

                NotificationSender se = new NotificationSender("Download started", Helper.GenerateName(Database.GetSeries((int)episode.seriesId), episode));
                se.ClickedEvent += (s, ev) => {
                    Dispatcher.Invoke(() => {
                        MainWindow.RemoveAllPages();
                        MainWindow.SetPage(new DownloadsView());
                    }, DispatcherPriority.Send);
                };
                se.Show();
            }
            else
            {
                await MessageBox.Show("Sorry, torrent not found");
            }
            MainWindow.RemovePage();
        }
コード例 #2
0
 public async static Task RenameAfterDownload(TorrentDownloader torrent)
 {
     await Task.Run(async() => {
         string path = torrent.Status.SavePath + "\\" + torrent.Status.Name;
         TorrentDownloader.TorrentSession.RemoveTorrent(torrent.Handle);
         bool moved = false;
         while (!moved)
         {
             try {
                 if (File.Exists(path))
                 {
                     Directory.CreateDirectory(Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "\\");
                     File.Move(path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "\\" + Path.GetFileName(path));
                     path = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "\\";
                 }
                 var files   = FilterSeries(torrent.TorrentSource.Series, GetFilesInDirectory(path));
                 var episode = Database.GetEpisode(torrent.TorrentSource.Series.id, torrent.TorrentSource.Episode.id);
                 files.ForEach(x => x.episode = episode);
                 foreach (var item in files)
                 {
                     var result = await Rename(item);
                     episode    = AddToDatabase(episode, result);
                 }
                 Database.EditEpisode(torrent.TorrentSource.Series.id, episode.id, episode);
                 Directory.Delete(path, true);
                 moved = true;
             } catch (IOException e) {
                 await Task.Delay(100);
             }
         }
     });
 }
コード例 #3
0
        private async void Stream_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            MainWindow.AddPage(new PleaseWait());
            Torrent tor = await Torrent.SearchSingle(Database.GetSeries((int)episode.seriesId), episode, Settings.StreamQuality);

            MainWindow.RemovePage();
            TorrentDownloader td = new TorrentDownloader(tor);
            await td.Stream();
        }
コード例 #4
0
        private async void Download_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            TorrentDownloader td = new TorrentDownloader(torrent);

            MainWindow.AddPage(new PleaseWait());
            await td.Download();

            await Task.Run(() => Thread.Sleep(500));

            MainWindow.RemovePage();
        }
コード例 #5
0
        /// <summary>
        /// Continues all unifinished torrents
        /// </summary>
        public async static void ContinueUnfinished()
        {
            var torrents = TorrentDatabase.Load();

            torrents = torrents.Where(x => x.HasFinished == false).ToList();
            foreach (var item in torrents)
            {
                TorrentDatabase.Remove(item.Magnet);
                TorrentDownloader downloader = new TorrentDownloader(item);
                await downloader.Download();
            }
        }
コード例 #6
0
 private async void Render()
 {
     while (IsLoaded)
     {
         var list = TorrentDownloader.GetTorrents();
         if (list.Count > userControls.Count)
         {
             var torrents = new List <Torrent>();
             userControls.Values.ToList().ForEach(x => torrents.Add(x.TorrentSource));
             List <TorrentDownloader> changes = list.Where(x => !torrents.Contains(x.TorrentSource)).ToList();
             foreach (var item in changes)
             {
                 Dispatcher.Invoke(() => {
                     TorrentUserControl tcu = new TorrentUserControl(item, Panel);
                     tcu.Height             = 65;
                     tcu.Opacity            = 0;
                     tcu.Margin             = new Thickness(10, 0, 10, 0);
                     Panel.Children.Add(tcu);
                     userControls.Add(tcu, item);
                     Storyboard sb = (Storyboard)FindResource("OpacityUp");
                     sb.Begin(tcu);
                 }, DispatcherPriority.Send);
             }
         }
         if (list.Count < userControls.Count)
         {
             var torrents   = new List <Torrent>();
             var secondList = new List <Torrent>();
             list.ForEach(x => secondList.Add(x.TorrentSource));
             userControls.Values.ToList().ForEach(x => torrents.Add(x.TorrentSource));
             List <Torrent> changes = torrents.Except(secondList).ToList();
             Dictionary <TorrentUserControl, TorrentDownloader> values = userControls.Where(x => changes.Contains(x.Value.TorrentSource)).ToDictionary(x => x.Key, x => x.Value);
             foreach (var item in values)
             {
                 Storyboard sb    = (Storyboard)FindResource("OpacityDown");
                 var        clone = sb.Clone();
                 clone.Completed += (s, ev) => {
                     Dispatcher.Invoke(() => {
                         Panel.Children.Remove(item.Key);
                     });
                 };
                 Application.Current.Dispatcher.Invoke(() => {
                     clone.Begin(item.Key);
                     userControls.Remove(item.Key);
                 }, DispatcherPriority.Send);
             }
         }
         await Task.Run(() => {
             Thread.Sleep(250);
         });
     }
 }
コード例 #7
0
        private async void UpSpeed_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!String.IsNullOrEmpty(UpSpeed.Text))
            {
                if (Int32.TryParse(UpSpeed.Text, out int result))
                {
                    string oldString = UpSpeed.Text;
                    await Task.Delay(1000);

                    if (oldString == UpSpeed.Text)
                    {
                        TorrentDownloader.SetUploadSpeedLimit(result);
                    }
                }
                else
                {
                    await MessageBox.Show("Input is not number");
                }
            }
        }
コード例 #8
0
 private async static Task DownloadLastWeek()
 {
     await Task.Run(async() => {
         var series   = Database.GetSeries().Where(x => x.autoDownload);
         var episodes = new Dictionary <Series, List <Episode> >();
         foreach (var se in series)
         {
             //adds episodes that dont have files and have been released in last week
             episodes.Add(se, Database.GetEpisodes(se.id).Where(x => x.files.Count == 0 && !String.IsNullOrEmpty(x.firstAired) && Helper.ParseAirDate(x.firstAired) > DateTime.Now.AddDays(-7) && Helper.ParseAirDate(x.firstAired).AddDays(1) < DateTime.Now).ToList());
         }
         foreach (var combination in episodes)
         {
             foreach (var episode in combination.Value)
             {
                 if (TorrentDatabase.Load().Where(x => x.Episode.id == episode.id).ToList().Count == 0)
                 {
                     TorrentDownloader downloader = new TorrentDownloader(await Torrent.SearchSingle(combination.Key, episode, Settings.DownloadQuality));
                     await downloader.Download();
                 }
             }
         }
     });
 }
コード例 #9
0
        private void BaseGrid_Loaded(object sender, RoutedEventArgs e)
        {
            //Application.Current.Resources["TransparentBG"] = new SolidColorBrush(SystemParameters.WindowGlassColor);

            if (true)
            {
                NotificationSender.ShortCutCreator.TryCreateShortcut("TVSPlayer.app", "TVS-Player");
                if (!CheckConnection())
                {
                    AddPage(new StartupInternetError());
                }
                else
                {
                    Settings.Load();
                    UpdateApplication.StartUpdate();
                    UpdateApplication.CheckForUpdates();
                    SetPage(new Library());
                    if (String.IsNullOrEmpty(Settings.Library))
                    {
                        AddPage(new Intro());
                        Helper.SetPerformanceMode();
                        Settings.LastCheck = DateTime.Now;
                        UpdateDatabase.StartUpdateBackground(false);
                    }
                    else
                    {
                        UpdateDatabase.StartUpdateBackground();
                        TorrentDownloader.ContinueUnfinished();
                    }
                }
            }
            else
            {
                Settings.Load();
                TestFunctions();
            }
        }
コード例 #10
0
 public TorrentStreamer(TorrentDownloader downloader)
 {
     InitializeComponent();
     this.downloader = downloader;
 }
コード例 #11
0
 public TorrentUserControl(TorrentDownloader torrent, StackPanel panel)
 {
     InitializeComponent();
     downloader = torrent;
     this.panel = panel;
 }