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); }
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"); } }
//public static void QueueDownloadFile(string[] filePartLinks, string file = null) public static void QueueDownloadFile(MongoCollectionManager <QueueDownloadFile> mongoQueueDownloadFileManager, string[] filePartLinks, string directory = null, string filename = null) { //ServerKey key = null; //key = new ServerKey { }; //Uri uri = new Uri(url); //string file = uri.Segments[uri.Segments.Length - 1]; //IRequestDownloadLinks downloadLinks = null; //DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks); //string[] downloadLinks2 = null; //PostDownloadLinks postDownloadLinks = PostDownloadLinks.Create(downloadLinks2); //DownloadItemLink[] downloadItemLinks2 = DownloadItemLink.CreateDownloadItemLinkArray(postDownloadLinks); DownloadItemLink itemLink = DownloadItemLink.CreateDownloadItemLink(filePartLinks); // Key (ServerKey) of QueueDownloadFile is null, no save to _mongoDownloadedFileManager in DownloadManager QueueDownloadFile downloadFile = new QueueDownloadFile { DownloadItemLinks = new DownloadItemLink[] { itemLink }, RequestTime = DateTime.Now, Directory = directory, Filename = filename //Directory = file != null ? zPath.GetDirectoryName(file) : null, //Filename = file != null ? zPath.GetFileName(file) : null }; downloadFile.Id = mongoQueueDownloadFileManager.GetNewId(); mongoQueueDownloadFileManager.Save(downloadFile.Id, downloadFile); }
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); }
public void AddFileToDownload(ServerKey key, IRequestDownloadLinks downloadLinks, string file = null) { DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks); QueueDownloadFile downloadFile = new QueueDownloadFile { Key = key, DownloadItemLinks = downloadItemLinks, RequestTime = DateTime.Now, Directory = file != null?zPath.GetDirectoryName(file) : null, Filename = file != null?zPath.GetFileName(file) : null }; downloadFile.Id = _mongoQueueDownloadFileManager.GetNewId(); downloadFile.Modified = true; SaveQueueDownloadFile(downloadFile); }
// 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); }
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); } } } }
// 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; }
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; }
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; }