LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2012, 10:02 PM   #1
nfs1mw
LQ Newbie
 
Registered: Nov 2012
Distribution: kubuntu
Posts: 7

Rep: Reputation: Disabled
how to selectively download files with aria2 ?


I have a text file with bunch of download links. Each file to download can vary in size from 1kB to 300MB. To download all files I just do
aria2c -i links.txt
But that downloads all files.

My requirement is I want to download only files less than 1MB at first. After completing that task i wanna do the same for <5MB and so on . The reason for it is I want to first download least size files because they will be many such compared to big files.

So how can I download files less than 1MB from a bunch of download links in a text file.?
 
Old 11-26-2012, 09:35 AM   #2
Velotrol
LQ Newbie
 
Registered: Apr 2011
Location: Rio, Brazil
Distribution: Gentoo
Posts: 15

Rep: Reputation: Disabled
It is impossible without knowing the filesize before arrange the download list, I guess, never had any contact with aria2c.
You can make a script that download and interrupt every file in the list, then find a way to know the filesize (should show on screen), get size and organize links.txt according to the size. I don't see much else you can do.
 
Old 11-26-2012, 04:49 PM   #3
dru8274
Member
 
Registered: Oct 2011
Location: New Zealand
Distribution: Debian
Posts: 105

Rep: Reputation: 37
Quote:
Originally Posted by Velotrol View Post
then find a way to know the filesize (should show on screen), get size and organize links.txt according to the size.
The size of a file is sometimes contained in the http-header. Such that you only need to fetch the header to find the filesize. And curl has an option to download only the header - very fast...
Quote:
-I, --head
(HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD
which this uses to get nothing but the header of a document.
And the typical command to view a files header might be...
Code:
$ curl -s -S -v -I http://popcon.debian.org/by_inst.gz

> HEAD /by_inst.gz HTTP/1.1
> User-Agent: curl/7.26.0
> Host: popcon.debian.org
> Accept: */*
> 
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Date: Mon, 26 Nov 2012 22:23:29 GMT
< Server: Apache
< Last-Modified: Mon, 26 Nov 2012 17:12:01 GMT
< ETag: "29e671b-1f4dac-4cf69081880ea"
< Accept-Ranges: bytes
< Content-Length: 2051500
< Content-Type: application/x-gzip
where the filesize in bytes is shown in red.

Such that using curl, I can write a small script to take a list of urls, obtain their file-sizes, and then sort them from smallest to largest. But if the file-size for an url cannot be found, then it defaults here to 10M. Nothing polished, but it does help address your problem.
Code:
#!/bin/bash

# A list of test urls
cat >/tmp/list.in <<EOF
http://popcon.debian.org/by_inst.gz
http://www.nasa.gov/templateimages/redesign/modules/header/header_logo.gif
http://2.bp.blogspot.com/-VL13sAi0cNQ/ULL0my3VCpI/AAAAAAAAGeA/5sb0AMI5c78/s1600/brittany_a.jpg
http://feedproxy.google.com/~r/linuxquestions/latest/~3/lUORnB0GYgI/showthread.php
EOF

>/tmp/list.out
while read urlx ; do
    numx="$(curl -s -S -v -I $urlx 2>&1 |
               awk '/Content-Length/ { sub(/\r$/,"") ; print $3}')"
    echo -e "${numx:-10000000}\t$urlx" >>/tmp/list.out
done < /tmp/list.in

sort -n /tmp/list.out | column -t

# OUTPUT
3710      http://www.nasa.gov/templateimages/redesign/modules/header/header_logo.gif
156494    http://2.bp.blogspot.com/-VL13sAi0cNQ/ULL0my3VCpI/AAAAAAAAGeA/5sb0AMI5c78/s1600/brittany_a.jpg
2051500   http://popcon.debian.org/by_inst.gz
10000000  http://feedproxy.google.com/~r/linuxquestions/latest/~3/lUORnB0GYgI/showthread.php
Happy with ur solution... then tick "yes" and mark as Solved!

Last edited by dru8274; 11-26-2012 at 04:51 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
listing files selectively and then zipping them. shravee Linux - Newbie 5 10-04-2010 04:23 AM
I lost a download with aria2 elaich Linux - Software 1 04-13-2010 10:44 AM
selectively check in multiple files using SVN sneakyimp Linux - Software 2 01-12-2010 04:19 PM
how to selectively print version numbers from log files craftereric Linux - General 1 04-21-2008 10:02 AM
Program that can selectively download email? oot Linux - Software 2 01-02-2004 11:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration