Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LinkItem"/> class.
        /// </summary>
        /// <param name="link">The link.</param>
        public LinkItem(Link link) : base(link.Source)
        {
            Release = link.Release;
            Quality = link.Quality;
            Size    = link.Size;
            InfoURL = link.InfoURL;
            FileURL = link.FileURL;
            Infos   = link.Infos;
            Color   = "White";

            if (!Signature.IsActivated)
            {
                return;
            }

            switch (Source.Type)
            {
                case Types.Torrent:
                    if (Infos.StartsWith("0 seed") && Settings.Get("Fade Dead Torrents", true))
                    {
                        Color = "#50FFFFFF";
                    }
                    else if (Infos.Contains("Free") && Settings.Get<bool>("Highlight Free Torrents"))
                    {
                        Color = "GreenYellow";
                    }
                    break;

                case Types.Usenet:
                    var ret = Settings.Get("Usenet Retention", 0);

                    if (ret != 0 && Infos.Contains("day") && int.Parse(Infos.Replace(",", string.Empty).Split(" ".ToCharArray()).First()) > ret)
                    {
                        Color = "#50FFFFFF";
                    }
                    break;

                case Types.DirectHTTP:
                    var typ = Settings.Get("One-Click Hoster List Type", "white");
                    var lst = Settings.Get<List<string>>("One-Click Hoster List");

                    if (typ == "white")
                    {
                        if (string.IsNullOrWhiteSpace(FileURL) || !lst.Any(d => FileURL.Contains(d)))
                        {
                            Color = "#50FFFFFF";
                        }
                    }
                    else if (typ == "black")
                    {
                        if (string.IsNullOrWhiteSpace(FileURL) || lst.Any(d => FileURL.Contains(d)))
                        {
                            Color = "#50FFFFFF";
                        }
                    }
                    break;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LinkItem"/> class.
 /// </summary>
 /// <param name="link">The link.</param>
 public LinkItem(Link link)
     : base(link.Source)
 {
     Release = link.Release;
     Quality = link.Quality;
     Size    = link.Size;
     InfoURL = link.InfoURL;
     FileURL = link.FileURL;
     Infos   = link.Infos;
     Color   = "White";
 }
        /// <summary>
        /// Downloads the specified link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="token">The token.</param>
        public void Download(Link link, string token)
        {
            if (link.FileURL.StartsWith("magnet:"))
            {
                DownloadFileCompleted(null, new EventArgs<string, string, string>(link.FileURL, null, token));
                return;
            }

            _td = new TaskDialog
                {
                    Title           = "Downloading...",
                    Instruction     = link.Release,
                    Content         = "Sending request to " + new Uri(link.FileURL).DnsSafeHost.Replace("www.", string.Empty) + "...",
                    CommonButtons   = TaskDialogButton.Cancel,
                    ShowProgressBar = true
                };

            _td.SetMarqueeProgressBar(true);
            _td.Destroyed   += TaskDialogDestroyed;
            _td.ButtonClick += TaskDialogDestroyed;

            new Thread(() => _res = _td.Show().CommonButton).Start();

            var prm = true;

            _dl                          = link.Source.Downloader;
            _dl.DownloadFileCompleted   += DownloadFileCompleted;
            _dl.DownloadProgressChanged += (s, a) =>
                {
                    if (_td != null && _td.IsShowing)
                    {
                        if (prm)
                        {
                            _td.SetMarqueeProgressBar(false);
                            _td.Navigate(_td);
                            prm = false;
                        }

                        _td.Content = "Downloading file... ({0}%)".FormatWith(a.Data);
                        _td.ProgressBarPosition = a.Data;
                    }
                };

            _dl.Download(link, Utils.GetRandomFileName(link.Source.Type == Types.Torrent ? "torrent" : link.Source.Type == Types.Usenet ? "nzb" : null), !string.IsNullOrWhiteSpace(token) ? token : "DownloadFile");

            Utils.Win7Taskbar(state: TaskbarProgressBarState.Indeterminate);
        }
 /// <summary>
 /// Creates a temporary container and sends it to the default associated application to DLC.
 /// </summary>
 /// <param name="link">The link.</param>
 private void SendToLinkContainerDownloader(Link link)
 {
     var tmp = Path.Combine(Path.GetTempPath(), Utils.CreateSlug(link.Release.Replace('.', ' ').Replace('_', ' ') + " " + link.Source.Name + " " + Utils.Rand.Next().ToString("x"), false) + ".dlc");
     File.WriteAllText(tmp, DLCAPI.CreateDLC(link.Release, link.FileURL.Split('\0')));
     Utils.Run(tmp);
 }
 /// <summary>
 /// Rewrites a list of HTTP links to a local DLC container path.
 /// </summary>
 /// <param name="link">The link.</param>
 /// <returns>New copy of the link pointing to a DLC container.</returns>
 private Link RewriteHTTPLinksToDLC(Link link)
 {
     var tmp = Path.Combine(Path.GetTempPath(), Utils.CreateSlug(link.Release.Replace('.', ' ').Replace('_', ' ') + " " + link.Source.Name + " " + Utils.Rand.Next().ToString("x"), false) + ".dlc");
     File.WriteAllText(tmp, DLCAPI.CreateDLC(link.Release, link.FileURL.Split('\0')));
     return new Link(link.Source)
         {
             Release = link.Release,
             InfoURL = link.InfoURL,
             FileURL = tmp,
             Infos   = link.Infos,
             Quality = link.Quality,
             Size    = link.Size
         };
 }
        /// <summary>
        /// Processes the link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="callback">The callback.</param>
        private void ProcessLink(Link link, Action<Link> callback)
        {
            if (link.Source is ILinkExpander<Link>)
            {
                var url = string.Empty;

                new GenericAsyncTaskDialog(
                    "Expanding links...",
                    "Bypassing the link protection on " + new Uri(link.FileURL.Split('\0')[0]).Host + "...",
                    () => url = ((ILinkExpander<Link>)link.Source).ExpandLinks(link),
                    () => { link.FileURL = url; callback(link); }
                ).Run();
            }
            else
            {
                callback(link);
            }
        }
        /// <summary>
        /// Downloads the specified file to the default download path.
        /// </summary>
        /// <param name="link">The link.</param>
        public static void DownloadFile(Link link)
        {
            var file = Path.Combine(Settings.Get("Automatic Download Path"), Utils.SanitizeFileName(link.Release.CutIfLonger(200)).Replace('/', '-'));

            switch (link.Source.Type)
            {
                case Types.Torrent:
                case Types.Usenet:
                    link.Source.Downloader.Download(link, file + (link.Source.Type == Types.Torrent ? ".torrent" : link.Source.Type == Types.Usenet ? ".nzb" : string.Empty));
                    break;

                case Types.DirectHTTP:
                    File.WriteAllText(file + ".rsdf", DLCAPI.CreateRSDF(link.FileURL.Split('\0')));
                    break;

                case Types.HTTP:
                    File.WriteAllText(file + ".url", "[InternetShortcut]\r\nURL=" + (link.FileURL ?? link.InfoURL));
                    return;
            }
        }
 /// <summary>
 /// Determines whether the specified link matches the rule set for the specified show
 /// </summary>
 /// <param name="episode">The episode.</param>
 /// <param name="link">The link.</param>
 /// <returns>
 ///   <c>true</c> if the specified link matches the rule; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsMatchingRule(Episode episode, Link link)
 {
     return link.Quality == PreferredQuality ||
            ((DateTime.Now - episode.Airdate) > WaitForPreferred && link.Quality == SecondPreferredQuality);
 }
        /// <summary>
        /// Downloads the specified link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="token">The token.</param>
        public void Download(Link link, string token)
        {
            if (link.FileURL.StartsWith("magnet:"))
            {
                DownloadFileCompleted(null, new EventArgs<string, string, string>(link.FileURL, null, token));
                return;
            }

            _active = true;
            _tdtit = link.Release;
            _tdstr = "Sending request to " + new Uri(link.FileURL).DnsSafeHost.Replace("www.", string.Empty) + "...";
            var showmbp = false;
            var mthd = new Thread(() => TaskDialog.Show(new TaskDialogOptions
                {
                    Title                   = "Downloading...",
                    MainInstruction         = _tdtit,
                    Content                 = _tdstr,
                    CustomButtons           = new[] { "Cancel" },
                    ShowMarqueeProgressBar  = true,
                    ShowProgressBar         = true,
                    EnableCallbackTimer     = true,
                    AllowDialogCancellation = true,
                    Callback                = (dialog, args, data) =>
                        {
                            if (!showmbp && _tdpos == 0)
                            {
                                dialog.SetProgressBarMarquee(true, 0);

                                showmbp = true;
                            }

                            if (_tdpos > 0 && showmbp)
                            {
                                dialog.SetMarqueeProgressBar(false);
                                dialog.SetProgressBarState(VistaProgressBarState.Normal);
                                dialog.SetProgressBarPosition(_tdpos);

                                showmbp = false;
                            }

                            if (_tdpos > 0)
                            {
                                dialog.SetProgressBarPosition(_tdpos);
                            }

                            dialog.SetContent(_tdstr);

                            if (args.ButtonId != 0)
                            {
                                if (_active)
                                {
                                    try { _dl.CancelAsync(); } catch { }
                                }

                                return false;
                            }

                            if (!_active)
                            {
                                dialog.ClickButton(500);
                                return false;
                            }

                            return true;
                        }
                }));
            mthd.SetApartmentState(ApartmentState.STA);
            mthd.Start();

            _dl                          = link.Source.Downloader;
            _dl.DownloadFileCompleted   += DownloadFileCompleted;
            _dl.DownloadProgressChanged += (s, a) =>
                {
                    _tdstr = "Downloading file... ({0}%)".FormatWith(a.Data);
                    _tdpos = a.Data;
                };

            _dl.Download(link, Path.Combine(Path.GetTempPath(), Utils.CreateSlug(link.Release + " " + link.Source.Name + " " + Utils.Rand.Next().ToString("x"), false) + (link.Source.Type == Types.Torrent ? ".torrent" : link.Source.Type == Types.Usenet ? ".nzb" : string.Empty)), !string.IsNullOrWhiteSpace(token) ? token : "DownloadFile");

            Utils.Win7Taskbar(state: TaskbarProgressBarState.Indeterminate);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Determines whether the specified link matches the rule set for the specified show
        /// </summary>
        /// <param name="episode">The episode.</param>
        /// <param name="link">The link.</param>
        /// <returns>
        ///   <c>true</c> if the specified link matches the rule; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsMatchingRule(Episode episode, Link link)
        {
            // TODO

            return link.Quality == Qualities.WebDL720p || (DateTime.Now - episode.Airdate) > WaitForPreferred;
        }