Esempio n. 1
0
 public void Save()
 {
     DataService.SaveFilters(Filters.ToList());
     DataService.SaveFeeds(Feeds.ToList());
     DataService.SaveDownloadedTorrents(DownloadedTorrents.ToList());
     DataService.SaveState(State);
 }
Esempio n. 2
0
        public void ExecuteLoadHighestEpisodeCommand(object parameter)
        {
            Filter         filter        = parameter as Filter;
            int            indexOfFilter = Filters.IndexOf(filter);
            List <Torrent> downloads     = DownloadedTorrents.FindDownloadedTorrents(indexOfFilter);

            filter.LoadHighestEpisode(downloads);
        }
Esempio n. 3
0
        public void ExecuteRemoveDownloadsCommand(object parameter)
        {
            List <Torrent> downloads = (parameter as IList).Cast <Torrent>().ToList();

            foreach (Torrent torrent in downloads)
            {
                DownloadedTorrents.Remove(torrent);
            }
            onPropertyChanged("LatestDownload");
        }
Esempio n. 4
0
        public bool CanResetFilterCommand(object parameter)
        {
            if (parameter == null || IsUpdating || IsSaving)
            {
                return(false);
            }

            Filter         filter        = parameter as Filter;
            int            indexOfFilter = Filters.IndexOf(filter);
            List <Torrent> downloads     = DownloadedTorrents.FindDownloadedTorrents(indexOfFilter);

            return(downloads.Count > 0);
        }
Esempio n. 5
0
        public void ExecuteResetFilterCommand(object parameter)
        {
            Filter         filter        = parameter as Filter;
            int            indexOfFilter = Filters.IndexOf(filter);
            List <Torrent> downloads     = DownloadedTorrents.FindDownloadedTorrents(indexOfFilter);

            foreach (Torrent torrent in downloads)
            {
                DownloadedTorrents.Remove(torrent);
            }
            onPropertyChanged("DownloadedTorrents");
            onPropertyChanged("LatestDownload");
        }
Esempio n. 6
0
        public async Task <bool> Download(Torrent torrent)
        {
            string location = State.TorrentDropDirectory;
            bool   torrentSuccessfullyDownloaded = await torrent.DownloadTorrentFile(location);

            if (torrentSuccessfullyDownloaded)
            {
                torrent.Download.Location       = location;
                torrent.Download.TimeOfDownload = DateTime.Now;
                DownloadedTorrents.Add(torrent);
                Log.Download(torrent);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 7
0
        public bool CanLoadHighestEpisodeCommand(object parameter)
        {
            if (parameter == null)
            {
                return(false);
            }

            Filter         filter        = parameter as Filter;
            int            indexOfFilter = Filters.IndexOf(filter);
            List <Torrent> downloads     = DownloadedTorrents.FindDownloadedTorrents(indexOfFilter);

            if (downloads.Count == 0)
            {
                return(false);
            }

            return(filter.HasHigher(downloads));
        }
Esempio n. 8
0
        public async Task <bool> FilterFeed(Feed feed, Filter filter)
        {
            int                 indexOfFilter = Filters.IndexOf(filter);
            List <Torrent>      torrentsDownloadedByFilter = DownloadedTorrents.Where(x => x.Download.CaughtByFilter == indexOfFilter).ToList();
            List <Task <bool> > downloadTorrents           = new List <Task <bool> >();

            foreach (Torrent torrent in feed.Torrents)
            {
                if (filter.ShouldDownload(torrent, torrentsDownloadedByFilter))
                {
                    Torrent copy = new Torrent(torrent);
                    copy.Download = new Download()
                    {
                        CaughtByFilter = indexOfFilter
                    };

                    downloadTorrents.Add(Download(copy));

                    if (filter.DisableAfterFirstDownload())
                    {
                        break;                         // Break so that no more torrents are added to download list
                    }
                }
            }

            await Task.WhenAll(downloadTorrents);

            bool filterDownloadedAtLeastOneTorrent = downloadTorrents.Any(x => x.Result);

            if (filterDownloadedAtLeastOneTorrent)
            {
                if (filter.DisableAfterFirstDownload())
                {
                    filter.Enabled = false;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 9
0
        public bool ShouldDownload(Torrent item)
        {
            if (Enabled)
            {
                if (!DownloadedTorrents.Contains(item))
                {
                    string       title  = Utils.RemoveDiacritics(IgnoreCaps ? item.Title.ToLower() : item.Title);
                    RegexOptions option = IgnoreCaps ? RegexOptions.IgnoreCase : RegexOptions.None;

                    if (Regex.IsMatch(title, RegexPattern, option))
                    {
                        if (IncludeList.All(title.Contains))
                        {
                            if (!ExcludeList.Any(title.Contains))
                            {
                                if (IsTV)
                                {
                                    if (item.IsTV)
                                    {
                                        if (IsEpisodeToDownload(item))
                                        {
                                            return(true);
                                        }
                                    }
                                }
                                else
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }