예제 #1
0
        private void ManageEndDownloadFiles()
        {
            if (_trace)
            {
                pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 01 begin");
            }
            foreach (int downloadId in _currentDownloadFiles.Keys.ToArray())
            {
                DownloadLinkRef downloadLinkRef = _currentDownloadFiles[downloadId];
                DownloaderState state           = _downloadClient.GetDownloadStateById(downloadLinkRef.DownloadId);
                if (state == DownloaderState.Ended || state == DownloaderState.EndedWithError || state == DownloaderState.UnknowDownload)
                {
                    QueueDownloadFile downloadFile = GetQueueDownloadFile(downloadLinkRef.QueueDownloadFileId);
                    downloadFile.Modified = true;
                    DownloadFilePartLink filePartLink = GetDownloadFilePartLink(downloadLinkRef);
                    if (state == DownloaderState.Ended)
                    {
                        filePartLink.State = DownloadState.DownloadCompleted;
                    }
                    else
                    {
                        downloadFile.UncompleteDownload = true;
                        DownloadItemLink itemLink = GetDownloadItemLink(downloadLinkRef);
                        itemLink.UncompleteDownload = true;
                        filePartLink.State          = DownloadState.DownloadFailed;
                    }

                    EndDownloadFilePart(downloadId);
                }
            }
            if (_trace)
            {
                pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 06 end");
            }
        }
예제 #2
0
        private void EndDownloadFilePart(int downloadId)
        {
            try
            {
                DownloadLinkRef      downloadLinkRef   = _currentDownloadFiles[downloadId];
                QueueDownloadFile    queueDownloadFile = GetQueueDownloadFile(downloadLinkRef.QueueDownloadFileId);
                DownloadFilePartLink filePartLink      = GetDownloadFilePartLink(downloadLinkRef);

                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 02                   : end download file : state {0} file \"{1}\"", filePartLink.State, filePartLink.File);
                }

                filePartLink.DownloadedPath = _downloadClient.GetDownloadLocalFileById(downloadLinkRef.DownloadId);
                string file = filePartLink.DownloadedPath;
                if (queueDownloadFile.Directory != null)
                {
                    file = zpath.PathSetDirectory(file, queueDownloadFile.Directory);
                }
                filePartLink.DownloadedFile        = file;
                filePartLink.EndDownloadTime       = DateTime.Now;
                filePartLink.DownloadDuration      = filePartLink.EndDownloadTime - filePartLink.StartDownloadTime;
                queueDownloadFile.EndDownloadTime  = filePartLink.EndDownloadTime;
                queueDownloadFile.DownloadDuration = queueDownloadFile.EndDownloadTime - queueDownloadFile.StartDownloadTime;

                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 03                   : _currentDownloadFiles.Remove({0})", downloadId);
                }
                _currentDownloadFiles.Remove(downloadId);

                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 04                   : _mongoCurrentDownloadFileManager.Remove({0})", downloadLinkRef.DownloadId);
                }
                _mongoCurrentDownloadFileManager.Remove(downloadLinkRef.DownloadId);

                queueDownloadFile.DownloadNbInProgress--;

                _downloadClient.RemoveDownloadById(downloadLinkRef.DownloadId);

                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.ManageEndDownloadFiles() 05                   : downloadFile.Id {0} downloadFile.DownloadNbInProgress {1} downloadFile.AllDownloadLinkTreated {2} directory \"{3}\" filename \"{4}\"", queueDownloadFile.Id, queueDownloadFile.DownloadNbInProgress, queueDownloadFile.AllDownloadLinkTreated, queueDownloadFile.Directory, queueDownloadFile.Filename);
                }
                if (queueDownloadFile.DownloadNbInProgress == 0 && queueDownloadFile.AllDownloadLinkTreated)
                {
                    EndDownload(queueDownloadFile);
                }
                else
                {
                    SaveQueueDownloadFile(queueDownloadFile);
                }
            }
            catch (Exception exception)
            {
                pb.Trace.WriteLine("error in DownloadManager.EndDownloadFilePart() : {0}", exception.Message);
                pb.Trace.WriteLine(exception.StackTrace);
            }
        }
예제 #3
0
        public static DownloadItemLink[] CreateDownloadItemLinkArray(IRequestDownloadLinks requestDownloadLinks)
        {
            IRequestDownloadItemLink[] requestItemLinks = requestDownloadLinks.GetLinks();

            DownloadItemLink[] itemsLinks = new DownloadItemLink[requestItemLinks.Length];
            for (int i1 = 0; i1 < requestItemLinks.Length; i1++)
            {
                IRequestDownloadItemLink requestItemLink = requestItemLinks[i1];
                DownloadItemLink         itemLink        = new DownloadItemLink();
                itemLink.Name = requestItemLink.GetName();
                //itemLink.Downloaded = false;
                IRequestDownloadServerLink[] requestFileLinks = requestItemLink.GetServerLinks();
                itemLink.ServerLinks = new DownloadServerLink[requestFileLinks.Length];
                for (int i2 = 0; i2 < requestFileLinks.Length; i2++)
                {
                    IRequestDownloadServerLink requestFileLink = requestFileLinks[i2];
                    DownloadServerLink         serverLink      = new DownloadServerLink();
                    serverLink.Name = requestFileLink.GetName();
                    string[] filePartLinks = requestFileLink.GetFilePartLinks();
                    serverLink.FilePartLinks = new DownloadFilePartLink[filePartLinks.Length];
                    for (int i3 = 0; i3 < filePartLinks.Length; i3++)
                    {
                        DownloadFilePartLink filePartLink = new DownloadFilePartLink();
                        filePartLink.DownloadLink = filePartLinks[i3];
                        //filePartLink.Downloaded = false;
                        //filePartLink.State = DownloadState.NotDownloaded;
                        serverLink.FilePartLinks[i3] = filePartLink;
                    }
                    itemLink.ServerLinks[i2] = serverLink;
                }
                itemsLinks[i1] = itemLink;
            }
            return(itemsLinks);
        }
예제 #4
0
        private bool UnprotectLink(QueueDownloadFile downloadFile, DownloadServerLink serverLink, DownloadFilePartLink filePartLink, int filePartLinkIndex)
        {
            if (_protectLink != null && _protectLink.IsLinkProtected(filePartLink.DownloadLink))
            {
                string[] links = _protectLink.UnprotectLink(filePartLink.DownloadLink);

                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.UnprotectLink() 01                            : _protectLink.UnprotectLink(\"{0}\") : {1}", filePartLink.DownloadLink, links.zToStringValues());
                }

                if (links == null || links.Length == 0)
                {
                    pb.Trace.WriteLine("error unable to unprotect link \"{0}\"", filePartLink.DownloadLink);
                    return(false);
                }
                downloadFile.Modified = true;
                filePartLink.ProtectedDownloadLink = filePartLink.DownloadLink;
                filePartLink.DownloadLink          = links[0];
                if (links.Length > 1)
                {
                    List <DownloadFilePartLink> filePartLinks = new List <DownloadFilePartLink>();
                    for (int i = 0; i <= filePartLinkIndex; i++)
                    {
                        filePartLinks.Add(serverLink.FilePartLinks[i]);
                    }
                    for (int i = 1; i < links.Length; i++)
                    {
                        DownloadFilePartLink filePartLink2 = new DownloadFilePartLink();
                        filePartLink2.Downloaded   = false;
                        filePartLink2.DownloadLink = links[i];
                        filePartLink2.State        = DownloadState.NotDownloaded;
                        filePartLinks.Add(filePartLink2);
                    }
                    for (int i = filePartLinkIndex + 1; i < serverLink.FilePartLinks.Length; i++)
                    {
                        filePartLinks.Add(serverLink.FilePartLinks[i]);
                    }
                    serverLink.FilePartLinks = filePartLinks.ToArray();
                }
            }
            return(true);
        }
예제 #5
0
        // filePartLinks : links of a multi part zip, example file.part1.rar file.part2.rar ...
        public static DownloadItemLink CreateDownloadItemLink(string[] filePartLinks)
        {
            DownloadItemLink itemLink = new DownloadItemLink();

            itemLink.Name = null;

            // only one server
            DownloadServerLink serverLink = new DownloadServerLink();

            serverLink.Name      = null;
            itemLink.ServerLinks = new DownloadServerLink[] { serverLink };

            serverLink.FilePartLinks = new DownloadFilePartLink[filePartLinks.Length];
            for (int i3 = 0; i3 < filePartLinks.Length; i3++)
            {
                DownloadFilePartLink filePartLink = new DownloadFilePartLink();
                filePartLink.DownloadLink    = filePartLinks[i3];
                serverLink.FilePartLinks[i3] = filePartLink;
            }

            return(itemLink);
        }
예제 #6
0
        private void ControlDownloadFiles()
        {
            foreach (int downloadId in _currentDownloadFiles.Keys.ToArray())
            {
                DownloadLinkRef downloadLinkRef = _currentDownloadFiles[downloadId];
                DownloaderState state           = _downloadClient.GetDownloadStateById(downloadLinkRef.DownloadId);
                if (state == DownloaderState.NeedToPrepare)
                {
                    if (_downloadClient.GetDownloadRetryCountById(downloadLinkRef.DownloadId) == _downloadClient.GetMaxRetryCount())
                    {
                        QueueDownloadFile downloadFile = GetQueueDownloadFile(downloadLinkRef.QueueDownloadFileId);
                        downloadFile.Modified = true;
                        DownloadFilePartLink filePartLink = GetDownloadFilePartLink(downloadLinkRef);

                        downloadFile.UncompleteDownload = true;
                        DownloadItemLink itemLink = GetDownloadItemLink(downloadLinkRef);
                        itemLink.UncompleteDownload = true;
                        filePartLink.State          = DownloadState.DownloadFailed;

                        EndDownloadFilePart(downloadId);
                    }
                }
            }
        }
예제 #7
0
        private bool DebridLink(QueueDownloadFile queueDownloadFile, DownloadItemLink itemLink, DownloadServerLink serverLink, DownloadFilePartLink filePartLink, out string debridedLink, out string file)
        {
            if (!filePartLink.Debrided)
            {
                // http://s19.alldebrid.com/dl/f3nmdg2f05/Herc-FULLBluRay.part01.rar
                debridedLink               = _debrider.DebridLink(filePartLink.DownloadLink);
                filePartLink.Debrided      = true;
                queueDownloadFile.Modified = true;
                if (debridedLink != null)
                {
                    filePartLink.DebridedDownloadLink = debridedLink;

                    //file = queueDownloadFile.File;
                    file = queueDownloadFile.Filename;
                    string urlFileName = zPath.GetFileName(zurl.GetAbsolutePath(debridedLink));
                    if (file == null)
                    {
                        file = zPath.GetFileNameWithoutExtension(urlFileName);
                    }

                    if (queueDownloadFile.DownloadItemLinks.Length > 1)
                    {
                        file += "_" + itemLink.Name;
                    }
                    if (serverLink.FilePartLinks.Length > 1)
                    {
                        //file += ZipManager.GetZipFilePartName(zurl.GetFileName(debridedLink));
                        //file += ZipManager.GetZipFilePartName(urlFileName);
                        file += ZipArchive.GetZipFilePartName(urlFileName);
                    }
                    //file += zurl.GetExtension(debridedLink);
                    file += zPath.GetExtension(urlFileName);
                    if (queueDownloadFile.Directory != null)
                    {
                        file = zPath.Combine(queueDownloadFile.Directory, file);
                    }
                    filePartLink.File = file;

                    if (_trace)
                    {
                        pb.Trace.WriteLine("DownloadManager.DebridLink() 01                               : _debrider.DebridLink(\"{0}\") : \"{1}\"", filePartLink.DownloadLink, debridedLink);
                    }

                    return(true);
                }
            }
            debridedLink = null;
            file         = null;
            return(false);
        }
예제 #8
0
        private DownloadLinkRef GetNextDownloadLink(QueueDownloadFile queueDownloadFile)
        {
            if (queueDownloadFile.AllDownloadLinkTreated)
            {
                return(null);
            }
            int itemIndex = 0;

            foreach (DownloadItemLink itemLink in queueDownloadFile.DownloadItemLinks)
            {
                if (!itemLink.Downloaded)
                {
                    if (!itemLink.NoDownloadLinkFound)
                    {
                        if (itemLink.SelectedServerIndex == -1)
                        {
                            var q           = (from server in itemLink.ServerLinks select new { server = server, rate = DownloadFileServerInfo.GetLinkRate(server.Name) }).OrderBy(server => server.rate).Select(server => server.server);
                            int serverIndex = 0;
                            foreach (DownloadServerLink serverLink in q)
                            {
                                DownloadFilePartLink filePartLink = serverLink.FilePartLinks[0];
                                if (!UnprotectLink(queueDownloadFile, serverLink, filePartLink, 0))
                                {
                                    continue;
                                }
                                string debridedLink = null;
                                string file         = null;
                                if (DebridLink(queueDownloadFile, itemLink, serverLink, filePartLink, out debridedLink, out file))
                                {
                                    itemLink.SelectedServerIndex = serverIndex;
                                    queueDownloadFile.Modified   = true;
                                    return(new DownloadLinkRef
                                    {
                                        QueueDownloadFileId = queueDownloadFile.Id, ItemIndex = itemIndex, ServerIndex = serverIndex, FilePartIndex = 0, DebridedDownloadLink = debridedLink, File = file
                                    });
                                }
                                serverIndex++;
                            }
                            itemLink.NoDownloadLinkFound         = true;
                            queueDownloadFile.UncompleteDownload = true;
                            queueDownloadFile.Modified           = true;
                            string message = string.Format("can't find download link for item no {0}", itemIndex + 1);
                            //pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - {1,-50} - {2,-25} - file \"{3}\" key {4}", DateTime.Now, message, null, queueDownloadFile.File, queueDownloadFile.Key);
                            pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - {1,-50} - {2,-25} - directory \"{3}\" filename \"{4}\" key {5}", DateTime.Now, message, null, queueDownloadFile.Directory, queueDownloadFile.Filename, queueDownloadFile.Key);
                        }
                        else
                        {
                            DownloadServerLink serverLink = itemLink.ServerLinks[itemLink.SelectedServerIndex];
                            // dont use foreach because UnprotectLink() may change serverLink.FilePartLinks
                            for (int filePartIndex = 0; filePartIndex < serverLink.FilePartLinks.Length; filePartIndex++)
                            {
                                DownloadFilePartLink filePartLink = serverLink.FilePartLinks[filePartIndex];
                                if (filePartLink.State != DownloadState.NotDownloaded)
                                {
                                    continue;
                                }
                                string errorMessage = null;
                                if (UnprotectLink(queueDownloadFile, serverLink, filePartLink, filePartIndex))
                                {
                                    string debridedLink = null;
                                    string file         = null;
                                    if (DebridLink(queueDownloadFile, itemLink, serverLink, filePartLink, out debridedLink, out file))
                                    {
                                        return(new DownloadLinkRef {
                                            QueueDownloadFileId = queueDownloadFile.Id, ItemIndex = itemIndex, ServerIndex = itemLink.SelectedServerIndex, FilePartIndex = filePartIndex, DebridedDownloadLink = debridedLink, File = file
                                        });
                                    }
                                    else
                                    {
                                        errorMessage = "can't find download link";
                                    }
                                }
                                else
                                {
                                    errorMessage = "error unable to unprotect link";
                                }
                                if (errorMessage != null)
                                {
                                    queueDownloadFile.UncompleteDownload = true;
                                    queueDownloadFile.Modified           = true;
                                    errorMessage = errorMessage + string.Format(" for item no {0} server no {1} part no {2}", itemIndex + 1, itemLink.SelectedServerIndex + 1, filePartIndex + 1);
                                    //pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - {1,-50} - {2,-25} - link \"{3}\" file \"{4}\" key {5}", DateTime.Now, errorMessage, null, filePartLink.DownloadLink, queueDownloadFile.File, queueDownloadFile.Key);
                                    pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - {1,-50} - {2,-25} - link \"{3}\" directory \"{4}\" filename \"{5}\" key {6}", DateTime.Now, errorMessage, null, filePartLink.DownloadLink, queueDownloadFile.Directory, queueDownloadFile.Filename, queueDownloadFile.Key);
                                }
                            }
                        }
                    }
                }
                itemIndex++;
            }
            queueDownloadFile.AllDownloadLinkTreated = true;
            queueDownloadFile.Modified = true;
            return(null);
        }
예제 #9
0
        private void ManageNewDownloadFiles()
        {
            if (_trace)
            {
                pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 01 begin");
            }

            int nb = _downloadClient.GetDownloadCount();

            if (_trace)
            {
                pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 02                   : search new download link : current download count {0}", nb);
            }

            if (nb >= _maxSimultaneousDownload)
            {
                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 09 end");
                }
                return;
            }

            foreach (QueueDownloadFile queueDownloadFile in _mongoQueueDownloadFileManager.Find("{}", sort: "{ _id: 1 }"))
            {
                QueueDownloadFile queueDownloadFile2 = queueDownloadFile;
                if (_queueDownloadFiles.ContainsKey(queueDownloadFile2.Id))
                {
                    queueDownloadFile2 = GetQueueDownloadFile(queueDownloadFile2.Id);
                }

                while (true)
                {
                    if (!_queueDownloadFiles.ContainsKey(queueDownloadFile2.Id))
                    {
                        if (!_queueDownloadFiles.TryAdd(queueDownloadFile2.Id, queueDownloadFile2))
                        {
                            pb.Trace.WriteLine("error adding QueueDownloadFile id {0} to ConcurrentDictionary _queueDownloadFiles", queueDownloadFile2.Id);
                        }
                        if (_trace)
                        {
                            //pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 05                   : add to _queueDownloadFiles, queueDownloadFile.Id {0} queueDownloadFile.Key {1} queueDownloadFile.File \"{2}\"", queueDownloadFile2.Id, queueDownloadFile2.Key, queueDownloadFile2.File);
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 05                   : add to _queueDownloadFiles, queueDownloadFile.Id {0} queueDownloadFile.Key {1} queueDownloadFile.Directory \"{2}\" queueDownloadFile.Filename \"{3}\"", queueDownloadFile2.Id, queueDownloadFile2.Key, queueDownloadFile2.Directory, queueDownloadFile2.Filename);
                        }
                    }

                    DownloadLinkRef downloadLinkRef = GetNextDownloadLink(queueDownloadFile2);
                    if (downloadLinkRef == null)
                    {
                        if (_trace)
                        {
                            //pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 03                   : no more link to download for \"{0}\"", queueDownloadFile2.File);
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 03                   : no more link to download for \"{0}\" \"{1}\"", queueDownloadFile2.Directory, queueDownloadFile2.Filename);
                            //pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 04                   : downloadFile.Id {0} downloadFile.DownloadNbInProgress {1} downloadFile.AllDownloadLinkTreated {2} file \"{3}\"", queueDownloadFile2.Id, queueDownloadFile2.DownloadNbInProgress, queueDownloadFile2.AllDownloadLinkTreated, queueDownloadFile2.File);
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 04                   : downloadFile.Id {0} downloadFile.DownloadNbInProgress {1} downloadFile.AllDownloadLinkTreated {2} directory \"{3}\" filename \"{4}\"", queueDownloadFile2.Id, queueDownloadFile2.DownloadNbInProgress, queueDownloadFile2.AllDownloadLinkTreated, queueDownloadFile2.Directory, queueDownloadFile2.Filename);
                        }

                        // sauver dans mongo Downloaded _mongoDownloadedFileManager
                        if (queueDownloadFile2.DownloadNbInProgress == 0)
                        {
                            EndDownload(queueDownloadFile2);
                        }
                        else
                        {
                            SaveQueueDownloadFile(queueDownloadFile2);
                        }
                        break;
                    }
                    else
                    {
                        downloadLinkRef.DownloadId  = _downloadClient.AddDownload(downloadLinkRef.DebridedDownloadLink, downloadLinkRef.File, startNow: true);
                        queueDownloadFile2.Modified = true;

                        if (_trace)
                        {
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 06                   : start download DownloadId {0} file \"{1}\"", downloadLinkRef.DownloadId, downloadLinkRef.File);
                        }

                        DownloadFilePartLink filePartLink = GetDownloadFilePartLink(downloadLinkRef);
                        if (filePartLink != null)
                        {
                            filePartLink.State             = DownloadState.DownloadStarted;
                            filePartLink.StartDownloadTime = DateTime.Now;
                        }
                        if (queueDownloadFile2.StartDownloadTime == null)
                        {
                            queueDownloadFile2.StartDownloadTime = DateTime.Now;
                        }
                        queueDownloadFile2.DownloadNbInProgress++;
                        SaveQueueDownloadFile(queueDownloadFile2);

                        if (_trace)
                        {
                            //pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 07                   : downloadFile.Id {0} downloadFile.DownloadNbInProgress {1} downloadFile.AllDownloadLinkTreated {2} file \"{3}\"", queueDownloadFile2.Id, queueDownloadFile2.DownloadNbInProgress, queueDownloadFile2.AllDownloadLinkTreated, queueDownloadFile2.File);
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 07                   : downloadFile.Id {0} downloadFile.DownloadNbInProgress {1} downloadFile.AllDownloadLinkTreated {2} directory \"{3}\" filename \"{4}\"", queueDownloadFile2.Id, queueDownloadFile2.DownloadNbInProgress, queueDownloadFile2.AllDownloadLinkTreated, queueDownloadFile2.Directory, queueDownloadFile2.Filename);
                            pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 08                   : _currentDownloadFiles.Add({0})", downloadLinkRef.DownloadId);
                        }

                        _currentDownloadFiles.Add(downloadLinkRef.DownloadId, downloadLinkRef);
                        _mongoCurrentDownloadFileManager.Save(BsonValue.Create(downloadLinkRef.DownloadId), downloadLinkRef);

                        if (++nb >= _maxSimultaneousDownload)
                        {
                            break;
                        }
                    }
                }
                if (nb >= _maxSimultaneousDownload)
                {
                    break;
                }
            }
            if (_trace)
            {
                pb.Trace.WriteLine("DownloadManager.ManageNewDownloadFiles() 09 end");
            }
        }
예제 #10
0
        // filePartLinks : links of a multi part zip, example file.part1.rar file.part2.rar ...
        public static DownloadItemLink CreateDownloadItemLink(string[] filePartLinks)
        {
            DownloadItemLink itemLink = new DownloadItemLink();
            itemLink.Name = null;

            // only one server
            DownloadServerLink serverLink = new DownloadServerLink();
            serverLink.Name = null;
            itemLink.ServerLinks = new DownloadServerLink[] { serverLink };

            serverLink.FilePartLinks = new DownloadFilePartLink[filePartLinks.Length];
            for (int i3 = 0; i3 < filePartLinks.Length; i3++)
            {
                DownloadFilePartLink filePartLink = new DownloadFilePartLink();
                filePartLink.DownloadLink = filePartLinks[i3];
                serverLink.FilePartLinks[i3] = filePartLink;
            }

            return itemLink;
        }
예제 #11
0
        private bool DebridLink(QueueDownloadFile queueDownloadFile, DownloadItemLink itemLink, DownloadServerLink serverLink, DownloadFilePartLink filePartLink, out string debridedLink, out string file)
        {
            if (!filePartLink.Debrided)
            {
                // http://s19.alldebrid.com/dl/f3nmdg2f05/Herc-FULLBluRay.part01.rar
                debridedLink = _debrider.DebridLink(filePartLink.DownloadLink);
                filePartLink.Debrided = true;
                queueDownloadFile.Modified = true;
                if (debridedLink != null)
                {
                    filePartLink.DebridedDownloadLink = debridedLink;

                    //file = queueDownloadFile.File;
                    file = queueDownloadFile.Filename;
                    string urlFileName = zPath.GetFileName(zurl.GetAbsolutePath(debridedLink));
                    if (file == null)
                        file = zPath.GetFileNameWithoutExtension(urlFileName);

                    if (queueDownloadFile.DownloadItemLinks.Length > 1)
                        file += "_" + itemLink.Name;
                    if (serverLink.FilePartLinks.Length > 1)
                        //file += ZipManager.GetZipFilePartName(zurl.GetFileName(debridedLink));
                        //file += ZipManager.GetZipFilePartName(urlFileName);
                        file += ZipArchive.GetZipFilePartName(urlFileName);
                    //file += zurl.GetExtension(debridedLink);
                    file += zPath.GetExtension(urlFileName);
                    if (queueDownloadFile.Directory != null)
                        file = zPath.Combine(queueDownloadFile.Directory, file);
                    filePartLink.File = file;

                    if (_trace)
                        pb.Trace.WriteLine("DownloadManager.DebridLink() 01                               : _debrider.DebridLink(\"{0}\") : \"{1}\"", filePartLink.DownloadLink, debridedLink);

                    return true;
                }
            }
            debridedLink = null;
            file = null;
            return false;
        }
예제 #12
0
        private bool UnprotectLink(QueueDownloadFile downloadFile, DownloadServerLink serverLink, DownloadFilePartLink filePartLink, int filePartLinkIndex)
        {
            if (_protectLink != null && _protectLink.IsLinkProtected(filePartLink.DownloadLink))
            {
                string[] links = _protectLink.UnprotectLink(filePartLink.DownloadLink);

                if (_trace)
                    pb.Trace.WriteLine("DownloadManager.UnprotectLink() 01                            : _protectLink.UnprotectLink(\"{0}\") : {1}", filePartLink.DownloadLink, links.zToStringValues());

                if (links == null || links.Length == 0)
                {
                    pb.Trace.WriteLine("error unable to unprotect link \"{0}\"", filePartLink.DownloadLink);
                    return false;
                }
                downloadFile.Modified = true;
                filePartLink.ProtectedDownloadLink = filePartLink.DownloadLink;
                filePartLink.DownloadLink = links[0];
                if (links.Length > 1)
                {
                    List<DownloadFilePartLink> filePartLinks = new List<DownloadFilePartLink>();
                    for (int i = 0; i <= filePartLinkIndex; i++)
                        filePartLinks.Add(serverLink.FilePartLinks[i]);
                    for (int i = 1; i < links.Length; i++)
                    {
                        DownloadFilePartLink filePartLink2 = new DownloadFilePartLink();
                        filePartLink2.Downloaded = false;
                        filePartLink2.DownloadLink = links[i];
                        filePartLink2.State = DownloadState.NotDownloaded;
                        filePartLinks.Add(filePartLink2);
                    }
                    for (int i = filePartLinkIndex + 1; i < serverLink.FilePartLinks.Length; i++)
                        filePartLinks.Add(serverLink.FilePartLinks[i]);
                    serverLink.FilePartLinks = filePartLinks.ToArray();
                }
            }
            return true;
        }
예제 #13
0
        public static DownloadItemLink[] CreateDownloadItemLinkArray(IRequestDownloadLinks requestDownloadLinks)
        {
            IRequestDownloadItemLink[] requestItemLinks = requestDownloadLinks.GetLinks();

            DownloadItemLink[] itemsLinks = new DownloadItemLink[requestItemLinks.Length];
            for (int i1 = 0; i1 < requestItemLinks.Length; i1++)
            {
                IRequestDownloadItemLink requestItemLink = requestItemLinks[i1];
                DownloadItemLink itemLink = new DownloadItemLink();
                itemLink.Name = requestItemLink.GetName();
                //itemLink.Downloaded = false;
                IRequestDownloadServerLink[] requestFileLinks = requestItemLink.GetServerLinks();
                itemLink.ServerLinks = new DownloadServerLink[requestFileLinks.Length];
                for (int i2 = 0; i2 < requestFileLinks.Length; i2++)
                {
                    IRequestDownloadServerLink requestFileLink = requestFileLinks[i2];
                    DownloadServerLink serverLink = new DownloadServerLink();
                    serverLink.Name = requestFileLink.GetName();
                    string[] filePartLinks = requestFileLink.GetFilePartLinks();
                    serverLink.FilePartLinks = new DownloadFilePartLink[filePartLinks.Length];
                    for (int i3 = 0; i3 < filePartLinks.Length; i3++)
                    {
                        DownloadFilePartLink filePartLink = new DownloadFilePartLink();
                        filePartLink.DownloadLink = filePartLinks[i3];
                        //filePartLink.Downloaded = false;
                        //filePartLink.State = DownloadState.NotDownloaded;
                        serverLink.FilePartLinks[i3] = filePartLink;
                    }
                    itemLink.ServerLinks[i2] = serverLink;
                }
                itemsLinks[i1] = itemLink;
            }
            return itemsLinks;
        }