Siirry sisältöön

Koodilistaus:Jamoget

Mummilan wikistä
Versio hetkellä 5. toukokuuta 2009 kello 07.33 – tehnyt Jani Uusitalo (keskustelu | muokkaukset) (Ak: Uusi sivu: <metadesc content="Bash-komentojono, joka lataa Jamendosta albumin Ogg Vorbis -muodossa ja panee sen sitten jakoon." /> Tämä Bash-komentojono lataa sille parametreina tai tiedostos...)
(ero) ← Vanhempi versio | Nykyinen versio (ero) | Uudempi versio → (ero)

<metadesc content="Bash-komentojono, joka lataa Jamendosta albumin Ogg Vorbis -muodossa ja panee sen sitten jakoon." />

Tämä Bash-komentojono lataa sille parametreina tai tiedostossa (nykyisessä hakemistossa oleva idlist-niminen tiedosto) listatut albumit Jamendosta Ogg Vorbis -muotoisina, ja pudottaa ne sen jälkeen Bittorrent-asiakasohjelman jakoon. Albumit tulee antaa pelkästään niiden tunnusnumeroilla, esimerkiksi näin: jamoget 42673 43733

Mikäli albumit luetellaan tiedostossa, ne tulee erotella toisistaan rivinvaihdoilla.

Komentojonon käyttöönotto vaatii melko varmasti mukailua hakemistoviittausten osalta.

Tämä on oma muunnelmani Jamendon foorumilta löytyneestä alkuperäisteoksesta, jonka on luonut The Chilling Spirit. Alkuperäisen lisenssi on tuntematon, todennäköisesti kuitenkin vapaa.

Lataa tiedostona: [{{#file: jamoget}} jamoget]

{{#fileanchor: jamoget}}

#!/bin/bash
# This will download album ZIP files from Jamendo directly. By default it gets Ogg Vorbis, remove the last parameter from the wget lines to get MP3
# It will then also grab the .torrent file, unzip the album and move the .torrent to your client's watch directory.

# ----- Usage -----
# Create the following directories. ./extracted/, ./errorsonunzip/
# The paths to your torrent and watch directory are in line XX, make sure to check.
# If you do not want to keep the ZIP files, change 
# 	mv "${zipfile}" extracted/
# to
# 	rm "${zipfile}"
# in line XX. You won't need the ./extracted/ directory then either.

# If there were errors on unzipping, the script will move both ZIP and the .torrent to ./errorsonunzip/

# Put the IDs of all the albums you want into a file called idlist, one id per line.
# Then simply run this with the bash
idlist=`mktemp -t`
if [ -e idlist ]
then
	cp idlist $idlist
else
	if [ $# -lt 1 ]
	then
		echo "usage: `basename ${0}` id..."
		exit 1
	fi
	for id in $@ ; do
		echo $id >> $idlist
	done
fi

while read albumid ; do
	mkdir -p "/tmp/jamoget-${albumid}/extracted" "/tmp/jamoget-${albumid}/errorsonunzip" || { echo "ERROR: Creating temporary output directories."; exit; }
	pushd "/tmp/jamoget-${albumid}"

	echo "INFO: Downloading Ogg Vorbis album ZIP"
	wget --continue "http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${albumid}/?p2pnet=bittorrent&are=ogg3"
	
	echo "INFO: Downloading torrent for Ogg Vorbis album"
	wget -nv --continue -O ${albumid}.torrent "http://api.jamendo.com/get2/bittorrent/file/redirect/?album_id=${albumid}&type=archive&class=ogg3"
	
	echo "INFO: Unzipping"
	find . -maxdepth 1 -name "*.zip" > ziplistfile
	while read zipfile ; do
		echo "INFO: Unzipping to torrents directory and moving ZIP to extracted directory, .torrent to watch directory"
		unzip -q -n "${zipfile}" -d "/home/jani/Työpöytä/Työn alla/Torrent/${zipfile%.zip}" && mv "${zipfile}" extracted/ && mv ${albumid}.torrent "/home/jani/Työpöytä/"
	done < ziplistfile
	rm ziplistfile

	mv *.zip errorsonunzip/ > /dev/null 2>&1
	mv *.torrent errorsonunzip/ > /dev/null 2>&1
	if [ "$(ls -A errorsonunzip/)" ]; then
		echo "ERROR: While unzipping. Downloaded files saved in /tmp/jamoget-${albumid}/errorsonunzip/."
	else
		cd /tmp && rm -rf "jamoget-${albumid}"
	fi
	popd > /dev/null 2>&1
done < $idlist

rm $idlist
echo "INFO: Script finished"