Exemplo n.º 1
0
        public IEnumerable <string> GetKeywords(IPartialRssItem item)
        {
            var magnetLink = item.GetPropertyOrDefault(RssItemProperties.MagnetLink);

            if (!string.IsNullOrWhiteSpace(magnetLink))
            {
                yield return(magnetLink);

                if (MagnetUri.TryParse(magnetLink, out var ml))
                {
                    yield return(ml.InfoHash);
                }
            }
        }
Exemplo n.º 2
0
 public override int GetHashCode() => MagnetUri != null
     ? MagnetUri.GetHashCode()
     : 0;
Exemplo n.º 3
0
        /// <summary>
        /// Download a torrent
        /// </summary>
        /// <returns><see cref="Task"/></returns>
        public Task Download(T media, TorrentType torrentType, MediaType mediaType, string torrentPath,
                             int uploadLimit, int downloadLimit, IProgress <double> downloadProgress,
                             IProgress <BandwidthRate> bandwidthRate, IProgress <int> nbSeeds, IProgress <int> nbPeers, Action buffered,
                             Action cancelled,
                             CancellationTokenSource cts)
        {
            return(Task.Run(async() =>
            {
                Logger.Info(
                    $"Start downloading : {torrentPath}");
                using var session = new Session();
                downloadProgress.Report(0d);
                bandwidthRate.Report(new BandwidthRate
                {
                    DownloadRate = 0d,
                    UploadRate = 0d
                });
                nbSeeds.Report(0);
                nbPeers.Report(0);
                string savePath = string.Empty;
                switch (mediaType)
                {
                case MediaType.Movie:
                    savePath = _cacheService.MovieDownloads;
                    break;

                case MediaType.Show:
                    savePath = _cacheService.ShowDownloads;
                    break;

                case MediaType.Unkown:
                    savePath = _cacheService.DropFilesDownloads;
                    break;
                }

                if (torrentType == TorrentType.File)
                {
                    using var addParams = new AddTorrentParams
                          {
                              save_path = savePath,
                              ti = new TorrentInfo(torrentPath)
                          };
                    using var handle = session.add_torrent(addParams);
                    await HandleDownload(media, savePath, mediaType, uploadLimit, downloadLimit,
                                         downloadProgress,
                                         bandwidthRate, nbSeeds, nbPeers, handle, session, buffered, cancelled, cts);
                }
                else
                {
                    var magnet = new MagnetUri();
                    using var error = new ErrorCode();
                    var addParams = new AddTorrentParams
                    {
                        save_path = savePath,
                    };
                    magnet.parse_magnet_uri(torrentPath, addParams, error);
                    using var handle = session.add_torrent(addParams);
                    await HandleDownload(media, savePath, mediaType, uploadLimit, downloadLimit,
                                         downloadProgress,
                                         bandwidthRate, nbSeeds, nbPeers, handle, session, buffered, cancelled, cts);
                }
            }));
        }