Exemplo n.º 1
0
 public static void Remove(RssUrlEntry entry)
 {
     if (entries.ContainsKey(entry.Url))
     {
         entries.Remove(entry.Url);
         EntriesList.Remove(entry);
         Save();
     }
 }
Exemplo n.º 2
0
 public static void Add(RssUrlEntry entry)
 {
     lock (entries)
     {
         if (!entries.ContainsKey(entry.Url))
         {
             entries.Add(entry.Url, entry);
             EntriesList.Add(entry);
             Save();
         }
     }
 }
Exemplo n.º 3
0
 public static void Add(RssUrlEntry entry)
 {
     lock (entries)
     {
         if (!entries.ContainsKey(entry.Url))
         {
             entries.Add(entry.Url, entry);
             EntriesList.Add(entry);
             Save();
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Used by the feed manager
        /// </summary>
        /// <param name="path"></param>
        /// <param name="entry"></param>
        /// <returns>Return weither the torrent was loaded</returns>
        public bool AddTorrentRss(string path, Services.RSS.RssUrlEntry entry)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            Ragnar.TorrentInfo torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path));

            if (torrent.IsValid)
            {
                if (this.ContainTorrent(torrent.InfoHash))
                {
                    return(false);
                }
                else
                {
                    Directory.CreateDirectory(entry.DownloadDirectory);

                    Ragnar.TorrentHandle handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams()
                    {
                        SavePath    = entry.DownloadDirectory,
                        TorrentInfo = torrent,

                        DownloadLimit  = entry.DefaultSettings.MaxDownloadSpeed,
                        MaxConnections = entry.DefaultSettings.MaxConnections,
                        MaxUploads     = entry.DefaultSettings.UploadSlots,
                        UploadLimit    = entry.DefaultSettings.MaxUploadSpeed
                    });

                    set_files_priorities(handle, 3);

                    if (!entry.AutoDownload)
                    {
                        handle.AutoManaged = false;
                        handle.Pause();
                    }

                    // normally, adding a torrent will fire the TorrentAdded Event, so this line
                    // is somewhat unecessary.

                    //this.Torrents.Add(new TorrentInfo(handle));
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
 public static void ForceUpdate(RssUrlEntry entry)
 {
     entry.ForceUpdate();
 }
Exemplo n.º 6
0
        private static void Process_NewRssItems(RssUrlEntry entry, RssTorrent[] new_items)
        {
            foreach (var nitem in new_items)
            {
                if (url_404.Contains(nitem.TorrentFileUrl)) { continue; }

                string save_path = Path.Combine(RssTorrentsStorageDirectory, Utility.CleanFileName(nitem.Name) + ".torrent");
                nitem.TorrentFilePath = save_path;

                if (File.Exists(save_path))
                {
                    //re-load from downloaded file
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        nitem.LastResponseMessage = "Data was already saved";
                        nitem.LastResponseType = DownloadRssResponse.ResonseType.OK;
                        nitem.Success = AppState.AddTorrentRss(save_path, entry);
                    }));
                    continue;
                }

                if (!IsQueued(nitem))
                {
                    QueuedItems.Add(nitem);

                    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
                    {
                        Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' has been started", nitem.Name, "");

                        var res = download(nitem.IsMagnetOnly ? nitem.TorrentMagnetUrl : nitem.TorrentFileUrl);
                        nitem.LastResponse = res;

                        Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' resp type is {1}", nitem.Name, res.Type);

                        if (res.Type == DownloadRssResponse.ResonseType.OK || res.Type == DownloadRssResponse.ResonseType.MagnetLink)
                        {
                            byte[] data = res.Data;
                            if (data.Length > 0)
                            {
                                File.WriteAllBytes(save_path, data);
                                Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' succesfully downloaded", nitem.Name, "");

                                App.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    nitem.Success = AppState.AddTorrentRss(save_path, entry);
                                }));
                            }
                            else
                            {
                                if (res.Type == DownloadRssResponse.ResonseType.MagnetLink)
                                {
                                    Debug.WriteLine("[Rssdownloader-TQ]: Cannot add torrent ({0}) magnet ('{1}')",
                                        nitem.Name, nitem.TorrentMagnetUrl);
                                }
                                //What should we do?
                            }
                        }
                        else if (res.Type == DownloadRssResponse.ResonseType.NotFound)
                        {
                            if (!url_404.Contains(nitem.TorrentFileUrl))
                            {
                                url_404.Add(nitem.TorrentFileUrl);
                                Debug.WriteLine("[Rssdownloader-TQ]: URL '{0}' not found, therefore banned.", nitem.TorrentFileUrl, "");
                            }
                        }

                        QueuedItems.Remove(nitem);
                        return;
                    }));
                }
            }
        }
Exemplo n.º 7
0
 public static void Remove(RssUrlEntry entry)
 {
     if (entries.ContainsKey(entry.Url))
     {
         entries.Remove(entry.Url);
         EntriesList.Remove(entry);
         Save();
     }
 }
Exemplo n.º 8
0
        private static void Process_NewRssItems(RssUrlEntry entry, RssTorrent[] new_items)
        {
            foreach (var nitem in new_items)
            {
                if (url_404.Contains(nitem.TorrentFileUrl))
                {
                    continue;
                }

                string save_path = Path.Combine(RssTorrentsStorageDirectory, Utility.CleanFileName(nitem.Name) + ".torrent");
                nitem.TorrentFilePath = save_path;

                if (File.Exists(save_path))
                {
                    //re-load from downloaded file
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        nitem.LastResponseMessage = "Data was already saved";
                        nitem.LastResponseType    = DownloadRssResponse.ResonseType.OK;
                        nitem.Success             = AppState.AddTorrentRss(save_path, entry);
                    }));
                    continue;
                }

                if (!IsQueued(nitem))
                {
                    QueuedItems.Add(nitem);

                    System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
                    {
                        Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' has been started", nitem.Name, "");

                        var res            = download(nitem.IsMagnetOnly ? nitem.TorrentMagnetUrl : nitem.TorrentFileUrl);
                        nitem.LastResponse = res;

                        Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' resp type is {1}", nitem.Name, res.Type);

                        if (res.Type == DownloadRssResponse.ResonseType.OK || res.Type == DownloadRssResponse.ResonseType.MagnetLink)
                        {
                            byte[] data = res.Data;
                            if (data.Length > 0)
                            {
                                File.WriteAllBytes(save_path, data);
                                Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' succesfully downloaded", nitem.Name, "");

                                App.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    nitem.Success = AppState.AddTorrentRss(save_path, entry);
                                }));
                            }
                            else
                            {
                                if (res.Type == DownloadRssResponse.ResonseType.MagnetLink)
                                {
                                    Debug.WriteLine("[Rssdownloader-TQ]: Cannot add torrent ({0}) magnet ('{1}')",
                                                    nitem.Name, nitem.TorrentMagnetUrl);
                                }
                                //What should we do?
                            }
                        }
                        else if (res.Type == DownloadRssResponse.ResonseType.NotFound)
                        {
                            if (!url_404.Contains(nitem.TorrentFileUrl))
                            {
                                url_404.Add(nitem.TorrentFileUrl);
                                Debug.WriteLine("[Rssdownloader-TQ]: URL '{0}' not found, therefore banned.", nitem.TorrentFileUrl, "");
                            }
                        }

                        QueuedItems.Remove(nitem);
                        return;
                    }));
                }
            }
        }
Exemplo n.º 9
0
 public static void ForceUpdate(RssUrlEntry entry)
 {
     entry.ForceUpdate();
 }