public ItemTorrentDownload(TorrentEntry te, ProcessedEpisode pe, string desiredLocationNoExt, TorrentApp tApp)
 {
     Episode = pe;
     DesiredLocationNoExt = desiredLocationNoExt;
     Entry      = te;
     IconNumber = (tApp == TorrentApp.uTorrent) ? 2 : 10;
 }
        private bool CanRemove(TorrentEntry download, DirFilesCache dfc)
        {
            if (download.PercentDone < 100)
            {
                return(false);
            }
            if (!download.Finished)
            {
                return(false);
            }
            FileInfo x = new FileInfo(download.DownloadingTo);

            if (!x.IsMovieFile())
            {
                return(false);
            }

            List <ProcessedEpisode>?pes = MatchEpisodes(x);

            List <MovieConfiguration>?movies = MatchMovies(x);

            bool matchesSomeMovies = !(movies is null || movies.Count == 0);
            bool matchesSomeShows  = !(pes is null || pes.Count == 0);

            if (!matchesSomeMovies && !matchesSomeShows)
            {
                //File does not match any movies or shows
                return(false);
            }

            if (matchesSomeMovies && !movies !.All(movie => IsFound(dfc, movie)))
            {
                //Some Movies have not been copied yet - wait until they have
                return(false);
            }

            if (matchesSomeShows && !pes !.All(episode => IsFound(dfc, episode)))
            {
                //Some Episodes have not been copied yet - wait until they have
                return(false);
            }

            if (matchesSomeShows)
            {
                lastFoundEntry   = download;
                lastFoundEpisode = pes !.First();
                lastFoundMovie   = null;
                return(true);
            }

            lastFoundEntry   = download;
            lastFoundEpisode = null;
            lastFoundMovie   = movies !.First();
            return(true);
        }
Exemple #3
0
        public System.Collections.Generic.List<TorrentEntry> AllFilesBeingDownloaded(TVSettings settings, CommandLineArgs args)
        {
            System.Collections.Generic.List<TorrentEntry> r = new System.Collections.Generic.List<TorrentEntry>();

            BEncodeLoader bel = new BEncodeLoader();
            foreach (BTDictionaryItem it in this.ResumeDat.GetDict().Items)
            {
                if ((it.Type != BTChunk.kDictionaryItem))
                    continue;

                BTDictionaryItem dictitem = (BTDictionaryItem) (it);

                if ((dictitem.Key == ".fileguard") || (dictitem.Data.Type != BTChunk.kDictionary))
                    continue;

                string torrentFile = dictitem.Key;
                BTDictionary d2 = (BTDictionary) (dictitem.Data);

                BTItem p = d2.GetItem("prio");
                if ((p == null) || (p.Type != BTChunk.kString))
                    continue;

                BTString prioString = (BTString) (p);
                string directoryName = Path.GetDirectoryName(this.ResumeDatPath) + System.IO.Path.DirectorySeparatorChar;

                if (!File.Exists(torrentFile)) // if the torrent file doesn't exist
                    torrentFile = directoryName + torrentFile; // ..try prepending the resume.dat folder's path to it.

                if (!File.Exists(torrentFile))
                    continue; // can't find it.  give up!

                BTFile tor = bel.Load(torrentFile);
                if (tor == null)
                    continue;

                List<string> a = tor.AllFilesInTorrent();
                if (a != null)
                {
                    int c = 0;

                    p = d2.GetItem("path");
                    if ((p == null) || (p.Type != BTChunk.kString))
                        continue;
                    string defaultFolder = ((BTString) p).AsString();

                    BTItem targets = d2.GetItem("targets");
                    bool hasTargets = ((targets != null) && (targets.Type == BTChunk.kList));
                    BTList targetList = (BTList) (targets);

                    foreach (string s in a)
                    {
                        if ((c < prioString.Data.Length) && (prioString.Data[c] != BTPrio.Skip))
                        {
                            string saveTo = Helpers.FileInFolder(defaultFolder, settings.FilenameFriendly(s)).Name;
                            if (hasTargets)
                            {
                                // see if there is a target for this (the c'th) file
                                for (int i = 0; i < targetList.Items.Count; i++)
                                {
                                    BTList l = (BTList) (targetList.Items[i]);
                                    BTInteger n = (BTInteger) (l.Items[0]);
                                    BTString dest = (BTString) (l.Items[1]);
                                    if (n.Value == c)
                                    {
                                        saveTo = dest.AsString();
                                        break;
                                    }
                                }
                            }
                            int percent = (a.Count == 1) ? PercentBitsOn((BTString) (d2.GetItem("have"))) : -1;
                            TorrentEntry te = new TorrentEntry(torrentFile, saveTo, percent);
                            r.Add(te);
                        }
                        c++;
                    }
                }
            }

            return r;
        }
Exemple #4
0
 public void RemoveCompletedDownload(TorrentEntry name)
 {
     throw new NotSupportedException();
 }
 public ActionTRemove(IDownloadProvider source, TorrentEntry lastFoundEntry, ProcessedEpisode episode)
 {
     Episode = episode;
     client  = source;
     name    = lastFoundEntry;
 }
 public ActionTRemove(IDownloadProvider source, TorrentEntry lastFoundEntry, MovieConfiguration m)
 {
     Movie  = m;
     client = source;
     name   = lastFoundEntry;
 }
 public ItemuTorrenting(TorrentEntry te, ProcessedEpisode pe, string desiredLocationNoExt)
 {
     this.Episode = pe;
     this.DesiredLocationNoExt = desiredLocationNoExt;
     this.Entry = te;
 }
Exemple #8
0
        public List <TorrentEntry> AllFilesBeingDownloaded()
        {
            List <TorrentEntry> r = new List <TorrentEntry>();

            BEncodeLoader bel = new BEncodeLoader();

            foreach (BTDictionaryItem dictitem in ResumeDat.GetDict().Items)
            {
                if ((dictitem.Type != BTChunk.kDictionaryItem))
                {
                    continue;
                }

                if ((dictitem.Key == ".fileguard") || (dictitem.Data.Type != BTChunk.kDictionary))
                {
                    continue;
                }

                if (dictitem.Data is BTError err)
                {
                    logger.Error($"Error finding BT items: {err.Message}");
                    return(r);
                }

                BTDictionary d2 = (BTDictionary)(dictitem.Data);

                BTItem p = d2.GetItem("prio");
                if ((p is null) || (p.Type != BTChunk.kString))
                {
                    continue;
                }

                BTString prioString    = (BTString)(p);
                string   directoryName = Path.GetDirectoryName(ResumeDatPath) + System.IO.Path.DirectorySeparatorChar;

                string torrentFile = dictitem.Key;
                if (!File.Exists(torrentFile))                 // if the torrent file doesn't exist
                {
                    torrentFile = directoryName + torrentFile; // ..try prepending the resume.dat folder's path to it.
                }
                if (!File.Exists(torrentFile))
                {
                    continue; // can't find it.  give up!
                }
                BTFile tor = bel.Load(torrentFile);
                if (tor is null)
                {
                    continue;
                }

                List <string> a = tor.AllFilesInTorrent();
                if (a is null)
                {
                    continue;
                }

                int c = 0;

                p = d2.GetItem("path");
                if ((p is null) || (p.Type != BTChunk.kString))
                {
                    continue;
                }

                string defaultFolder = ((BTString)p).AsString();

                BTItem targets    = d2.GetItem("targets");
                bool   hasTargets = ((targets != null) && (targets.Type == BTChunk.kList));
                BTList targetList = (BTList)(targets);

                //foreach (var i in d2.Items)
                //{
                //logger.Info($"   {i.Key}  {i.Data.AsText()}");
                //}

                foreach (string s in a)
                {
                    if ((c < prioString.Data.Length) && (prioString.Data[c] != BTPrio.Skip))
                    {
                        try
                        {
                            string saveTo = FileHelper
                                            .FileInFolder(defaultFolder, TVSettings.Instance.FilenameFriendly(s)).Name;

                            if (hasTargets)
                            {
                                // see if there is a target for this (the c'th) file
                                foreach (BTItem t in targetList.Items)
                                {
                                    BTList    l    = (BTList)(t);
                                    BTInteger n    = (BTInteger)(l.Items[0]);
                                    BTString  dest = (BTString)(l.Items[1]);
                                    if (n.Value == c)
                                    {
                                        saveTo = dest.AsString();
                                        break;
                                    }
                                }
                            }

                            int          percent   = (a.Count == 1) ? PercentBitsOn((BTString)(d2.GetItem("have"))) : -1;
                            bool         completed = ((BTInteger)d2.GetItem("order")).Value == -1;
                            TorrentEntry te        = new TorrentEntry(torrentFile, saveTo, percent, completed, torrentFile);
                            r.Add(te);
                        }
                        catch (System.IO.PathTooLongException ptle)
                        {
                            //this is not the file we are looking for
                            logger.Debug(ptle);
                        }
                    }

                    c++;
                }
            }

            return(r);
        }
Exemple #9
0
 public ItemuTorrenting(TorrentEntry te, ProcessedEpisode pe, string desiredLocationNoExt)
 {
     this.Episode = pe;
     this.DesiredLocationNoExt = desiredLocationNoExt;
     this.Entry = te;
 }