private async Task DownloadFolderAsync(Uri uri, string downloadPath, bool overwrite)
        {
            INode[] nodes   = (await _client.GetNodesFromLinkAsync(uri)).ToArray();
            var     folders = new List <KeyValuePair <string, MegaFolder> >();

            foreach (INode node in nodes)
            {
                if (folders.Any(x => x.Key == node.Id) || node.Type == NodeType.File)
                {
                    continue;
                }

                folders.Add(new KeyValuePair <string, MegaFolder>(node.Id,
                                                                  new MegaFolder {
                    Name = node.Name, ParentId = node.ParentId
                }));
            }

            foreach (var folder in folders)
            {
                var path     = folder.Value.Name;
                var keyPath  = folder.Key;
                var parentId = folder.Value.ParentId;
                while (parentId != null)
                {
                    var parentFolder = folders.FirstOrDefault(x => x.Key == parentId);
                    path     = parentFolder.Value.Name + "/" + path;
                    keyPath  = parentFolder.Key + "/" + keyPath;
                    parentId = parentFolder.Value.ParentId;
                }

                folder.Value.Path = path;
            }

            (_, string id, _) = MegaUrlDataExtractor.Extract(uri.ToString());

            foreach (INode node in nodes.Where(x => x.Type == NodeType.File))
            {
                var path = Path.Combine(
                    downloadPath,
                    $"{id.Substring(0, 5)}_{folders.FirstOrDefault(x => x.Key == node.ParentId).Value.Path}",
                    node.Name);
                try
                {
                    await DownloadFileAsync(node, null, null, path, overwrite);
                }
                catch (Exception ex)
                {
                    _logger.Error($"Error while downloading {path}: {ex}", ex);
                }
            }
        }
        public async Task DownloadUrlAsync(ICrawledUrl crawledUrl, string downloadPath, bool overwriteFiles = false)
        {
            _logger.Debug($"[MEGA] Staring downloading {crawledUrl.Url}");

            Uri uri = new Uri(crawledUrl.Url);

            if (await IsUrlAFolder(uri))
            {
                await DownloadFolderAsync(uri, Path.Combine(downloadPath, crawledUrl.DownloadPath), overwriteFiles);
            }
            else
            {
                (_, string id, _) = MegaUrlDataExtractor.Extract(crawledUrl.Url);
                INodeInfo fileNodeInfo = await _client.GetNodeFromLinkAsync(uri);

                string path = Path.Combine(downloadPath, crawledUrl.DownloadPath,
                                           $"{id.Substring(0, 5)}_{fileNodeInfo.Name}");
                await DownloadFileAsync(null, uri, fileNodeInfo, path, overwriteFiles);
            }

            _logger.Debug($"[MEGA] Finished downloading {crawledUrl.Url}");
        }