简体   繁体   English

Aria2c-如何下载大量文件并输出为0.pdf,1.pdf,2.pdf…?

[英]Aria2c - how to download a lot of files and ouput as 0.pdf, 1.pdf, 2.pdf …?

I'm having a little problem here. 我在这里有一个小问题。 I'm using the famous Aria2C file downloader and I have a list of links that I need to download. 我正在使用著名的Aria2C文件下载器,并且列出了需要下载的链接。 I know I can use: 我知道我可以使用:

aria2c -o myOutputFile.exe http://www.fooBar.com/fooBarVirus.exe

to download a single file and name it as myOutputFile.exe . 下载单个文件并将其命名为myOutputFile.exe The problem is that I must download some files and name it as 0.pdf, 1.pdf, 2.pdf, 3.pdf... because I will assemble all this pdf's later. 问题是我必须下载一些文件并将其命名为0.pdf,1.pdf,2.pdf,3.pdf ...,因为稍后将组装所有这些pdf。

I'll try explain better. 我会尽力解释。 If I give the following links to aria2c: 如果我给aria2c提供以下链接:

http://www.fooBar.com/myPDF.pdf
http://www.fooBar.com/kindness.pdf
http://www.fooBar.com/crazyPdf.pdf
...
http://www.fooBar.com/myLastPdf.pdf

I must download these files and name it as a sequence of integers FOLLOWING THE LINKS INSERTION ORDER. 我必须下载这些文件,并将其命名为按链接插入顺序排序的整数序列。 With that I mean the filenames is related to the links order, but I don't need to download them in order . 我的意思是文件名与链接顺序有关,但是我不需要按顺序下载它们

Let's suppose I give Aria2C the previous links. 假设我给Aria2C以前的链接。 The following output would be a valid output for my problem: 以下输出将是我的问题的有效输出:

 Time: 0
 Link: http://www.fooBar.com/crazyPdf.pdf
 Filename: 2.pdf

 Time: 1
 Link: http://www.fooBar.com/myPDF.pdf
 Filename: 0.pdf

 Time: 2
 Link: http://www.fooBar.com/kindness.pdf
 Filename: 1.pdf

 ...

 Time: N
 Link: http://www.fooBar.com/myLastPdf.pdf
 Filename: N.pdf

I know this is a confusing question, so if you have any doubt please make a comment and I'll try answer as soon as possible. 我知道这是一个令人困惑的问题,因此,如果您有任何疑问,请发表评论,我会尽快尝试回答。 Thanks! 谢谢!

Ok, let's start with a pdfs.txt file holding the URLs for the PDFs: 好的,让我们从包含PDF网址的pdfs.txt文件开始:

http://www.fooBar.com/myPDF.pdf
http://www.fooBar.com/kindness.pdf
http://www.fooBar.com/crazyPdf.pdf
http://www.fooBar.com/myLastPdf.pdf

I throw in a little helper script to turn the URLs from the pdfs.txt file into the file format Aria2c accepts. 我放入了一个小帮手脚本,将pdfs.txt文件中的URL转换为Aria2c接受的文件格式。 The script uses the numerical index of an URL in the array as the new filename for the PDF. 该脚本使用数组中URL的数字索引作为PDF的新文件名。

<?php
$urls = __DIR__ . '/pdfs.txt';
$downloads = file($urls);

$targetFolder = __DIR__; // define your taget folder
$ariaDownloadList = '';
foreach($downloads as $idx => $url)
{
    $pdfName = $idx . '.pdf'; // 0.pdf ... N.pdf

    // add new download entry
    $ariaDownloadList .= $url;
    $ariaDownloadList .= '  dir=' . pathinfo($targetFolder, PATHINFO_DIRNAME) . PHP_EOL;
    $ariaDownloadList .= '  out=' . $pdfName . PHP_EOL;
}

file_put_contents('ariaDownloadsFile.txt', $ariaDownloadList);

This outputs a file ariaDownloadsFile.txt with the following content: 输出的文件ariaDownloadsFile.txt具有以下内容:

http://www.fooBar.com/myPDF.pdf
  dir=C:\pdfs
  out=0.pdf
http://www.fooBar.com/kindness.pdf
  dir=C:\pdfs
  out=1.pdf
http://www.fooBar.com/crazyPdf.pdf
  dir=C:\pdfs
  out=2.pdf
http://www.fooBar.com/myLastPdf.pdf  
  dir=C:\pdfs
  out=3.pdf

Then simply run the following command: 然后只需运行以下命令:

aria2c -i ariaDownloadsFile.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM