private void downloadFiles() { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } textBox1.Text = textBox1.Text + "\r\ndownloading the latest version..."; MegaApiClient mega = new MegaApiClient(); mega.LoginAnonymous(); Uri link = new Uri(megaLink); IEnumerable <INode> nodes = mega.GetNodesFromLink(link); foreach (INode node in nodes.Where(x => x.Type == NodeType.File)) { if (node.ParentId == "OG4B2D6S" || node.ParentId == "KSpkxCwB" || File.Exists(Path.Combine(path, node.Name))) { continue; } mega.DownloadFile(node, Path.Combine(path, node.Name)); textBox1.Text = textBox1.Text + "."; } mega.Logout(); textBox1.Text = textBox1.Text + "\r\nfinished downloading"; }
public void GenerateLinks() { string megaFolderId = FolderIDInput; if (string.IsNullOrWhiteSpace(megaFolderId)) { LinkOutput = ResourceHelper.Get(StringKey.EnterMegaFolderIdToGenerateLinks); return; } MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); IEnumerable <INode> nodes = client.GetNodesFromLink(new Uri($"https://mega.nz/{megaFolderId}")); if (nodes?.Any() == false) { LinkOutput = $"{ResourceHelper.Get(StringKey.NoLinksFoundInFolder)}: {megaFolderId}"; client.Logout(); return; } LinkOutput = ""; foreach (INode node in nodes.Where(x => x.Type == NodeType.File)) { LinkOutput += String.Format("iros://MegaSharedFolder/{0},{1},{2}\r\n", megaFolderId, node.Id, node.Name); } client.Logout(); }
public void UploadFileToMega() { var client = new MegaApiClient(); client.Login("*****@*****.**", "Jony*1995"); IEnumerable <INode> nodes = client.GetNodes(); Uri uri = new Uri("https://mega.nz/folder/74QCwKoJ#H5_lbdnO-2aQ3WTJxMmXwA"); IEnumerable <INode> carpeta = client.GetNodesFromLink(uri); foreach (INode child in carpeta) { if (child.Name == "BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip") { client.Delete(child); } } INode myFile = client.UploadFile("C:/SFacturacion/BD/BackUpBaseDatos" + Properties.Settings.Default.NombreEmpresa.Replace(" ", "") + ".zip", nodes.Single(x => x.Id == "zswWCIDA")); client.Logout(); }
public void download_qr_codes(string linkki_u) { String linkki; linkki = linkki_u; var client = new MegaApiClient(); client.Login("ADD_MEGA_USERNAME_HERE", "PASSWORD_HERE"); Uri folderLink = new Uri(linkki); IEnumerable <INode> nodes = client.GetNodesFromLink(folderLink); foreach (INode node in nodes.Where(x => x.Type == NodeType.File)) { MessageBox.Show($"Downloading {node.Name}"); client.DownloadFile(node, node.Name); } client.Logout(); }
protected virtual async Task <bool> DownloadBinaryPost(TumblrPost downloadItem) { string url = Url(downloadItem); if (!CheckIfFileExistsInDB(url)) { string blogDownloadLocation = blog.DownloadLocation(); string fileLocationUrlList = FileLocationLocalized(blogDownloadLocation, downloadItem.TextFileLocation); DateTime postDate = PostDate(downloadItem); string fileName = FileName(downloadItem); string fileLocation = FileLocation(blogDownloadLocation, fileName); if (url.Contains("https://mega.nz/#")) { Uri link = new Uri(url); Crawler.MegaLinkType linkType = Crawler.MegaLinkType.Single; //Determines if the MEGA link is a folder or single file based on if the url is mega.nz/#! or mega.nz/#F Regex regType = new Regex("(http[A-Za-z0-9_/:.]*mega.nz/#(.*)([A-Za-z0-9_]*))"); foreach (Match rmatch in regType.Matches(url)) { string subStr = rmatch.Groups[2].Value[0].ToString(); if (subStr == "!") { linkType = Crawler.MegaLinkType.Single; } if (subStr == "F") { linkType = Crawler.MegaLinkType.Folder; } } MegaApiClient client = new MegaApiClient(); client.LoginAnonymous(); switch (linkType) { case Crawler.MegaLinkType.Single: INodeInfo nodeInfo = client.GetNodeFromLink(link); fileName = nodeInfo.Name; fileLocation = FileLocation(blogDownloadLocation, fileName); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url)) { updateBlog(fileLocation, postDate, downloadItem, fileName); return(true); } client.Logout(); return(false); case Crawler.MegaLinkType.Folder: //If the link is a folder, download all files from it. IEnumerable <INode> nodes = client.GetNodesFromLink(link); List <INode> allFiles = nodes.Where(n => n.Type == NodeType.File).ToList(); foreach (INode node in allFiles) { fileName = node.Name; fileLocation = FileLocation(blogDownloadLocation, fileName); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url, node)) { updateBlog(fileLocation, postDate, downloadItem, fileName); } } client.Logout(); return(false); default: throw new ArgumentOutOfRangeException(); } } if (url.Contains("https://drive.google.com/")) { UserCredential credentials = Authenticate(); DriveService service = OpenService(credentials); RequestInfo(service, url, blogDownloadLocation + "\\"); } UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url)) { updateBlog(fileLocation, postDate, downloadItem, fileName); return(true); } return(false); } else { string fileName = FileName(downloadItem); UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); } return(true); }
public DownloaderResult DownloadFolder(Uri uri) { var client = new MegaApiClient(); client.LoginAnonymous(); Logger.Debug("Successfully log into mega"); try { var nodes = client.GetNodesFromLink(uri) .Where(x => x.Type == NodeType.File && x.Name.EndsWith(".rar")) .ToArray(); if (nodes.Length > 1) { throw new Exception("There's more that 1 rar file on the mega folder"); } else if (nodes.Length <= 0) { throw new Exception("There's no rar in the remote mega folder"); } Logger.Debug("Found a rar file in {0}", uri); var node = nodes[0]; var path = Path.GetTempFileName(); Logger.Debug("Downloading {0} into {1}", node.Name, path); try { using var file = File.Open(path, FileMode.Truncate); { using var downloadStream = client.Download(node); downloadStream.CopyTo(file); } file.Seek(0, 0); using var rar = new ArchiveFile(file); var dir = path + ".extracted"; Logger.Debug("Extracting into {0}", dir); Directory.CreateDirectory(dir); try { rar.Extract(dir); return(new DownloaderResult(dir, node.Name, node.Id, node.Owner, node.ModificationDate ?? node.CreationDate)); } catch { Logger.Warning("Deleting {0} before throwing", dir); Directory.Delete(dir, true); throw; } } finally { Logger.Debug("Removing temporary file {0}", path); File.Delete(path); } } finally { client.Logout(); } }
/// <summary> /// Perform the database download /// </summary> /// <param name="url"></param> /// <param name="path"></param> /// <param name="username"></param> /// <param name="password"></param> private void InternalDownloadDatabase(string url, string path, string username = null, string password = null) { string error = null; var client = new MegaApiClient(); try { INode database = null; if (username is null) { client.LoginAnonymous(); database = client.GetNodesFromLink(new Uri(url)).Where(x => x.Name.EndsWith(".crypt")) .OrderByDescending(x => x.CreationDate) .FirstOrDefault(); } else { client.Login(username, password); database = client.GetNodes().Where(x => x.Name != null && x.Name.EndsWith(".crypt")) .OrderByDescending(x => x.CreationDate) .FirstOrDefault(); } if (database is null) { error = "CantFindFile"; } else { using (var stream = client.Download(database)) { using (var fileStream = File.Create(path)) { stream.CopyTo(fileStream); } } } } catch (ApiException) { error = "ApiError"; } catch (UriFormatException) { error = "InvalidUrl"; } catch (ArgumentException) { error = "InvalidUrl"; } catch (IOException) { error = "CantDownloadFile"; } catch (Exception) { error = "ApiError"; } finally { if (client.IsLoggedIn) { client.Logout(); } } DatabaseDownloadEnded?.Invoke(this, new DatabaseDownloadEndedEventArgs(string.IsNullOrEmpty(error), path, error)); }