private async void DownloadSubs(Subtitles subtitles)
        {
            MainWindow.AddPage(new PleaseWait());
            HttpWebResponse result = (HttpWebResponse)(await subtitles.DownloadLink.GetResponseAsync());
            StreamReader    reader = new StreamReader(result.GetResponseStream());
            string          text   = await reader.ReadToEndAsync();

            reader.Close();
            var tempFile = Path.GetTempPath() + "\\" + subtitles.Language + " - " + subtitles.Version + ".srt";

            File.WriteAllText(tempFile, text, Encoding.GetEncoding(result.CharacterSet));
            await Renamer.RenameSingle(tempFile, Database.GetSeries((int)episode.seriesId), episode);

            MainWindow.RemovePage();
            ReturnFromSubsView();
        }
예제 #2
0
        /// <summary>
        /// Updates database if it hasnt been updated in the last day and autodownloads every Series that has autodownload enabled
        /// </summary>
        /// <returns></returns>
        public async static Task Update()
        {
            if (Settings.LastCheck.AddDays(1).Date <= DateTime.Now.Date)
            {
                await Task.Run(async() => {
                    List <int> ids       = Series.GetUpdates(Settings.LastCheck);
                    List <Series> series = Database.GetSeries();
                    ids = ids.Where(x => series.Any(y => y.id == x)).ToList();
                    foreach (int id in ids)
                    {
                        await UpdateFullSeries(id);
                    }
                });
                await DownloadLastWeek();

                Settings.LastCheck = DateTime.Now;
            }
            await Renamer.ScanAndRename(Database.GetSeries());
        }
        private string GetSource()
        {
            string path = downloader.Status.SavePath + "\\" + downloader.Status.Name;

            if (File.Exists(path))
            {
                return(path);
            }
            else if (Directory.Exists(path))
            {
                var      files         = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
                string[] fileExtension = new string[7] {
                    ".mkv", ".m4v", ".avi", ".mp4", ".mov", ".wmv", ".flv"
                };
                foreach (var file in files)
                {
                    if (Renamer.IsMatchToIdentifiers(file) && fileExtension.Contains(Path.GetExtension(file).ToLower()))
                    {
                        return(file);
                    }
                }
            }
            return(null);
        }
예제 #4
0
        /// <summary>
        /// Creates database from ids provided USAGE: await CreateDatabase(...)
        /// </summary>
        /// <param name="ids">List of TVDb ids</param>
        /// <returns></returns>
        private async Task GetFullShows(List <Tuple <int, string> > ids)
        {
            ProgressBarPage pbar  = new ProgressBarPage(ids.Count);
            int             total = 0;

            AddPage(pbar);
            //Wait for this task to complete without blocking main thread
            await Task.Run(() => {
                List <Task> tasks = new List <Task>();
                foreach (Tuple <int, string> combination in ids)
                {
                    tasks.Add(Task.Run(() => {
                        int id = combination.Item1;
                        //Create 4 tasks, wait for them to complete and then set value of ProgressBar
                        Task[] secondTasks = new Task[4];
                        secondTasks[0]     = Task.Run(() => {
                            Series s      = Series.GetSeries(id);
                            s.libraryPath = combination.Item2;
                            Database.AddSeries(s);
                        });
                        secondTasks[1] = Task.Run(() => {
                            List <Actor> list = Actor.GetActors(id);
                            if (list != null)
                            {
                                Database.AddActor(id, list);
                            }
                        });
                        secondTasks[2] = Task.Run(() => {
                            List <Episode> list = Episode.GetEpisodes(id);
                            if (list != null)
                            {
                                Database.AddEpisode(id, list);
                            }
                        });
                        secondTasks[3] = Task.Run(() => {
                            List <Poster> list = Poster.GetPosters(id);
                            if (list != null)
                            {
                                Database.AddPoster(id, list);
                            }
                        });
                        Task.WaitAll(secondTasks);
                        Dispatcher.Invoke(new Action(() => {
                            total++;
                            pbar.SetValue(total);
                        }), DispatcherPriority.Send);
                    }));
                }
                //Wait for all tasks created in foreach to complete
                tasks.WaitAll();
                Thread.Sleep(500);
            });

            //This code runs after all API calls are done and stuff is saved
            PleaseWait pleaseWait = new PleaseWait();

            AddPage(pleaseWait);
            var seriesList = Database.GetSeries().Where(x => ids.Any(y => y.Item1 == x.id)).ToList();
            await Renamer.ScanAndRename(seriesList);

            RemoveAllPages();
            SetPage(new Library());
        }