Jump to content

OCR downloader bash script for Linux and Windows(Cygwin)


pookiepaul1
 Share

Recommended Posts

Hello all! I am a longlonglong time listener of OCR! :) I absolutely love what you guys do here, and I am a musician myself! My one gripe is about the site is the infrequency that the official torrents get put up. So far, only OCR00001-OCR01900 are available in torrent form. in order to get the rest of the excellent collection, it requires you to sift through page after page, manually downloading each song, which is hella time consuming.

I decided to put my (limited) Linux bash scripting knowledge to use and create an auto-downloader for the site. This script is designed to be used IN CONJUNCTIION WITH THE TORRENTS in order to ease bandwidth on the site. PLEASE PLEASE PLEASE do not abuse this script and use it properly. And please only use it if you intended to complete your collection in the first place.

This script is a bash script that should run on any native linux machine and also Cygwin for Windows (This is what I use and how the script was written). Instructions will be below the code.

#!/bin/bash
#OCRemix downloader script
#requires wget, sed and curl commands to run
#takes 1 or 2 arguments for single song number or range of song numbers to download from OCR
#ocr 458 would download whatever mp3 was ocr00458
#ocr 1 2000 will download mp3s ocr00001 - ocr02000
#Please change FOLDER var to the folder with your ocr songs in it.
#This script WILL NOT download any songs currently in the folder pointed at by the FOLDER var.
#This means that you can use it in conjunction with the torrents.
#please use this script responsibly and use the official torrents to ease the bandwidth use of ocremix.org
#This script is intended only to ease the download of songs that are not yet included in official torrents.
#At time of writing, ocr01901-ocr02508 are not available in torrents. 10/16/2012
#author: Paul Vanpoucker

die ()
{
echo >&2 "$@"
exit 0
}

[ -n "$1" ] || die "at least 1 argument required"
echo $1 | grep -E -q '^[0-9]+$' || die "numeric argument required, $1 provided"
i=$1;

if [ -n "$2" ]; then
echo $2 | grep -E -q '^[0-9]+$' || die "numeric argument required, $2 provided"
[ "$2" -ge "$i" ] || die "argument 2 must be greater than argument 1"
END=$2;
else
END=$1;
fi

#Variables.
FOLDER="OCRemix"; #folder that MP3s will be downloaded to.
SOURCE="ocrmirror.org"; #Mirror domain to be downloaded from.

[ -d $FOLDER ] || mkdir $FOLDER
cd $FOLDER

for (($i;i<=$END;i++)) do

LEN=${#i};

for ((j=0;j<5-$LEN;j++)) do
LEAD=${LEAD}"0";
done

FILE=$LEAD$i;

echo "Checking OCR$FILE";
URL=$(curl --silent http://ocremix.org/remix/OCR$FILE/ | grep $SOURCE | sed 's/<a href=\"\(.*\)\">\(.*\)/\1/');

if [ -n "$URL" ]; then
echo "Retrieving MP3";
wget -c -q $URL
else
echo "No file exists at OCR$FILE";
fi

done
die "Downloads complete!"

Linux users:

1. Make sure grep, sed, wget and curl commands are installed.

2. copy code into a file using your favorite editor (Like vi!)

3. edit the FOLDER variable to match the path where your current OCRemix tracks are located. NOTE: Make sure all the loose MP3 files are in this folder together...NO SUBFOLDERS.

4. save file as ocr (or whatever you'd like to call it)

5. run the file by typing: bash ocr # # EXAMPLE: bash ocr 1901 2508 would download OCR01901-OCR02508.

Windows users:

1. install Cygwin (make sure during installation to also install the wget and curl packages).

2. copy code into a file using an editor (Like vi!)

3. edit the FOLDER variable to match the path where your current OCRemix tracks are located. NOTE: Make sure all the loose MP3 files are in this folder together...NO SUBFOLDERS. Also: If you are using a path in windows, make sure it is an ABSOLUTE path such as C:/users/<username>/music/ocr/

4. save file as ocr (or whatever you'd like to call it)

5. run the file by typing in cygwin: bash ocr # # EXAMPLE: bash ocr 1901 2508 would download OCR01901-OCR02508.

Link to comment
Share on other sites

Well balls...That is unfortunate timing for this. Oh well, it was good practice and fun and the script will now be here if anyone needs something like this for whatever reason (university students where torrenting is disabled) (Who knows how many songs will be released before the next torrent after this goes up).

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...