There is an online radio. At the moment I am using streamripper with the following commands.

streamripper http://xxx.ru -M 100 -a audio 

The script downloads audio 100 MB in size and names the new files by index, i.e. audio1.mp3, audio2.mp3, etc.

Most of the files he began to dump into the incomplete folder, so I wanted to compare the bash script for the test. Tell me how to use either curl or wget to do the same? Those. take the stream, download it until the file size is 100MB and save it to the file with the index. And so on

1 answer 1

you can use the -r ( --range ) option of the curl program.

Download the first one hundred megabytes адресу :

 $ curl -r 0-104857599 адрес 

following hundred megabytes:

 $ curl -r 104857600-209715199 адрес 

etc.


values ​​must be specified in bytes. computing is easier to entrust the shell:

 $ curl -r 0-$((100*1024*1024-1)) адрес $ curl -r $((100*1024*1024))-$((200*1024*1024-1)) адрес 

And so on

and then for automation you need a cycle:

 #!/bin/bash u=$1 [ -n "$u" ] || { echo "использование: $0 адрес"; exit 1; } n=0 p="часть" s=100*1024*1024 while true; do printf -vf "%s%0.3d" $p $n echo -n "скачиваем $f" if ! curl -s -f -r $((n*s))-$(((n+1)*s-1)) "$u" > "$f"; then exit $?; fi echo ". готово. следующий номер: $((++n))" done 
  • and how to make an infinite loop? - Radzhab
  • In order for the loop to download audio1, then audio2, and so on - Radzhab
  • and how to make an infinite loop? - we are on the site of programmers, or where? while true; do ...; done while true; do ...; done - aleksandr barakin
  • The problem is in the index. How to make numbered files - Radzhab
  • @Radzhab, in the answer files are numbered. - aleksandr barakin