Siirry sisältöön

Ero sivun ”Koodilistaus:Jamoget” versioiden välillä

Mummilan wikistä
ma 2.11.2009 14:04:20 +0200
to 28.1.2010 15.03.17 +0200
Rivi 13: Rivi 13:
{{#fileanchor: jamoget}}<pre>#!/bin/bash
{{#fileanchor: jamoget}}<pre>#!/bin/bash


# Jamoget ma 2.11.2009 14:04:20 +0200
# TODO:
# - convert --limit to kbps, pass on to scp
# - test rc for sanity
#
#
#
# Jamoget to 28.1.2010 15.03.17 +0200
#
# Changes since to 21.1.2010 18.52.51 +0200
# - fused external downloading
#
# Changes since ke 20.1.2010 21.34.36 +0200
# - incorporate/externalize remote downloading
#
# Changes since ke 20.1.2010 20.54.19 +0200
# - be wewy wewy quiet
#
# Changes since ma 18.1.2010 21.18.33 +0200
# - fix handling of uris readily pointing at the archive (/?p2pnet=...)
#
# Changes since ma 18.1.2010 20.52.53 +0200
# - configurable continue
#
# Changes since ma 2.11.2009 14:04:20 +0200
# - experimental workaround for braindead unzip
#
#
# Changes since ti 27.10.2009 13:38:33 +0200
# Changes since ti 27.10.2009 13:38:33 +0200
Rivi 48: Rivi 72:


# CONFIGURATION
# CONFIGURATION
downloadtarget=/home/jani/Työpöytä/Arkisto/Vapaat/Musiikki/Jamendo
downloadtarget=/home/jani/Julkinen/Musiikki
torrentfiletarget=/home/jani/Työpöytä
torrentfiletarget=/home/jani/Lataukset
 
# either --continue or empty for "no continue"
continue=
 
# non-empty for true
DEBUG=true
 
# YOU WILL ALSO NEED TO EDIT ~/.jamssirc!
 
# END CONFIGURATION
# END CONFIGURATION






QUIET="> /dev/null 2>&1"
if [[ "x$DEBUG" == "x" ]]
then
QUIET=
fi
# jamssi actual
function jamssia {
if [ $# -lt 2 ]
then
exit 1
fi
. ~/.jamssirc
ssh -n $USER@$SERVER "mkdir -p 'jamssia-${1}'" || { echo "ERROR: Unable to create working directory."; exit 1; }
echo -n "INFO: Remotely downloading .zip... "
ssh -n $USER@$SERVER "cd 'jamssia-${1}' && wget -T 0 -t 0 $limit 'http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${1}/?p2pnet=bittorrent${2}' $QUIET" || { echo "failed. Skipping."; return 1; }
echo "done."
ALBUM=`ssh -n $USER@$SERVER "cd jamssia-${1} && echo *.zip"`
ALBUM="${ALBUM%.zip}"
ssh -n $USER@$SERVER "mkdir -p 'jamssia-${1}/${ALBUM}'"
ssh -n $USER@$SERVER "mv 'jamssia-${1}/${ALBUM}.zip' 'jamssia-${1}/${ALBUM%.zip}/${1}.zip'"
echo -n "INFO: Unzipping..."
ssh -n $USER@$SERVER "cd 'jamssia-${1}/${ALBUM}' && unzip -q '${1}.zip'" || { echo "failed. Skipping."; return 1; }
echo "done."
ssh -n $USER@$SERVER "cd 'jamssia-${1}/${ALBUM}' && rm -f '${1}.zip'"
echo -n "INFO: Recompressing..."
ssh -n $USER@$SERVER "cd 'jamssia-${1}' && tar cjf '${1}.tar.bz2' '${ALBUM}'" || { echo "failed. Skipping."; return 1; }
echo "done."
echo "INFO: Downloading .tar.bz2:"
scp $USER@$SERVER:jamssia-${1}/${1}.tar.bz2 . || { echo "failed. Skipping."; return 1; }
echo "done."
ssh -n $USER@$SERVER "rm -rf 'jamssia-${1}'"
return 0;
}


limit=
limit=
Rivi 72: Rivi 146:
if [ -e idlist ]
if [ -e idlist ]
then
then
cp idlist $idlist
uniq idlist > $idlist
else
else
if [ $# -lt 1 ]
if [ $# -lt 1 ]
Rivi 91: Rivi 165:
   torrentformat=
   torrentformat=
fi
fi
echo "idlist=$idlist"
while read albumid ; do


while read albumid ; do
albumid=`basename "${albumid%/?p2pnet=bittorrent${downloadformat}}"`
albumid=`basename ${albumid}`
if [[ "${printuris}" == "true" ]]
if [[ "${printuris}" == "true" ]]
then
then
Rivi 102: Rivi 177:


mkdir -p "/tmp/jamoget-${albumid}/extracted" "/tmp/jamoget-${albumid}/errorsonunzip" || { echo "ERROR: Creating temporary output directories."; exit; }
mkdir -p "/tmp/jamoget-${albumid}/extracted" "/tmp/jamoget-${albumid}/errorsonunzip" || { echo "ERROR: Creating temporary output directories."; exit; }
pushd "/tmp/jamoget-${albumid}"
pushd "/tmp/jamoget-${albumid}" $QUIET
 
echo -n "INFO: Downloading .torrent... "
wget --quiet -t 0 -nv --continue -O ${albumid}.torrent "http://api.jamendo.com/get2/bittorrent/file/redirect/?album_id=${albumid}&type=archive${torrentformat}" $QUIET || { echo "failed. Skipping."; popd $QUIET; continue; }
echo "done."
 
if [[ "`basename $0`" == "jamssi" ]]
then
jamssia "${albumid}" "${downloadformat}" || { popd $QUIET; continue; }
cp "${albumid}.tar.bz2" "${downloadtarget%/}/"
pushd "${downloadtarget}" $QUIET
echo "INFO: Bunzipping+untarring to torrents directory and moving tar.bz2 to extracted directory, .torrent to watch directory"
tar xf "${albumid}.tar.bz2" && { popd $QUIET && rm "${albumid}.tar.bz2" && mv ${albumid}.torrent "${torrentfiletarget%/}/" && pushd "${downloadtarget}" $QUIET; } && rm "${albumid}.tar.bz2"
popd $QUIET
else
echo -n "INFO: Downloading .zip... "
LC_ALL=C wget -t 0 $limit $continue "http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${albumid}/?p2pnet=bittorrent${downloadformat}" $QUIET || { echo "failed. Skipping."; popd $QUIET; continue; }


echo "INFO: Downloading Ogg Vorbis album ZIP"
echo "INFO: Unzipping"
wget -t 0 $limit --continue "http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${albumid}/?p2pnet=bittorrent${downloadformat}"
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 unzipped && mv unzipped "${downloadtarget%/}/${zipfile%.zip}" && mv "${zipfile}" extracted/ && mv ${albumid}.torrent "${torrentfiletarget%/}/"
done < ziplistfile
rm ziplistfile


echo "INFO: Downloading torrent for Ogg Vorbis album"
fi
wget -t 0 -nv --continue -O ${albumid}.torrent "http://api.jamendo.com/get2/bittorrent/file/redirect/?album_id=${albumid}&type=archive${torrentformat}"
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 "${downloadtarget%/}/${zipfile%.zip}" && mv "${zipfile}" extracted/ && mv ${albumid}.torrent "${torrentfiletarget%/}/"
done < ziplistfile
rm ziplistfile


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



Versio 28. tammikuuta 2010 kello 13.08

<metadesc content="Bash-komentojono, joka lataa Jamendosta albumin Ogg Vorbis -muodossa ja panee sen sitten jakoon." /> Lataa tiedostona: [{{#file: jamoget}} jamoget]

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 (CONFIGURATION-osio) 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.

{{#fileanchor: jamoget}}

#!/bin/bash

# TODO:
#	- convert --limit to kbps, pass on to scp
#	- test rc for sanity
#
#
#
# Jamoget to 28.1.2010 15.03.17 +0200
#
# Changes since to 21.1.2010 18.52.51 +0200
#	- fused external downloading
#
# Changes since ke 20.1.2010 21.34.36 +0200
#	- incorporate/externalize remote downloading
#
# Changes since ke 20.1.2010 20.54.19 +0200
#	- be wewy wewy quiet
#
# Changes since ma 18.1.2010 21.18.33 +0200
#	- fix handling of uris readily pointing at the archive (/?p2pnet=...)
#
# Changes since ma 18.1.2010 20.52.53 +0200
#	- configurable continue
#
# Changes since ma 2.11.2009 14:04:20 +0200
#	- experimental workaround for braindead unzip
#
# Changes since ti 27.10.2009 13:38:33 +0200
#	- --printuris parameter
#
# Changes since ma 26.10.2009 11:03:29 +0200
#	- accept album URLs as parameters
#
# Changes since ma 26.10.2009 10:55:26 +0200
#	- retry infinitely
#
# Changes since ma 12.10.2009 09:18:07 +0300
#	- fix: Ogg downloading bug
#
# Changes since ke 20.5.2009 11:16:31 +0300
#	- download mp3 if ran as jampget
#
# Changes since ke 13.5.2009 12:55:14 +0300
#	- save idlist if errors occur
#
# Changes since ke 13.5.2009 11:11:02 +0300
#	- download and torrent file target directories now configurable through variables
#
# Changes since ke 13.5.2009 10:30:00 +0300:
#	- mentioning of limit-rate in usage
#
# Changes since ke 13.5.2009 10:20:04 +0300:
#	- implements limit-rate for wget
#
# 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.
# Put the IDs of all the albums you want into a file called idlist, one id per line.

# CONFIGURATION
downloadtarget=/home/jani/Julkinen/Musiikki
torrentfiletarget=/home/jani/Lataukset

# either --continue or empty for "no continue"
continue=

# non-empty for true
DEBUG=true

# YOU WILL ALSO NEED TO EDIT ~/.jamssirc!

# END CONFIGURATION







QUIET="> /dev/null 2>&1"
if [[ "x$DEBUG" == "x" ]]
then
	QUIET=
fi


# jamssi actual
function jamssia {
	if [ $# -lt 2 ]
	then
		exit 1
	fi

	. ~/.jamssirc

	ssh -n $USER@$SERVER "mkdir -p 'jamssia-${1}'" || { echo "ERROR: Unable to create working directory."; exit 1; }
	echo -n "INFO: Remotely downloading .zip... "
	ssh -n $USER@$SERVER "cd 'jamssia-${1}' && wget -T 0 -t 0 $limit 'http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${1}/?p2pnet=bittorrent${2}' $QUIET" || { echo "failed. Skipping."; return 1; }
	echo "done."
	ALBUM=`ssh -n $USER@$SERVER "cd jamssia-${1} && echo *.zip"`
	ALBUM="${ALBUM%.zip}"
	ssh -n $USER@$SERVER "mkdir -p 'jamssia-${1}/${ALBUM}'"
	ssh -n $USER@$SERVER "mv 'jamssia-${1}/${ALBUM}.zip' 'jamssia-${1}/${ALBUM%.zip}/${1}.zip'"
	echo -n "INFO: Unzipping..."
	ssh -n $USER@$SERVER "cd 'jamssia-${1}/${ALBUM}' && unzip -q '${1}.zip'" || { echo "failed. Skipping."; return 1; }
	echo "done."
	ssh -n $USER@$SERVER "cd 'jamssia-${1}/${ALBUM}' && rm -f '${1}.zip'"
	echo -n "INFO: Recompressing..."
	ssh -n $USER@$SERVER "cd 'jamssia-${1}' && tar cjf '${1}.tar.bz2' '${ALBUM}'" || { echo "failed. Skipping."; return 1; }
	echo "done."
	echo "INFO: Downloading .tar.bz2:"
	scp $USER@$SERVER:jamssia-${1}/${1}.tar.bz2 . || { echo "failed. Skipping."; return 1; }
	echo "done."
	ssh -n $USER@$SERVER "rm -rf 'jamssia-${1}'"
	return 0;
}

limit=
if [[ "$1" == "--limit" || "$1" == "--limit-rate" ]]
then
	shift
	limit=--limit-rate=$1
	shift
fi

printuris=
if [[ "$1" == "--printuris" ]]
then
	printuris=true
	shift
fi
idlist=`mktemp -t`
if [ -e idlist ]
then
	uniq idlist > $idlist
else
	if [ $# -lt 1 ]
	then
		echo "usage: `basename ${0}` [--limit-rate amount] album_id|album_url..."
		exit 1
	fi
	for id in $@ ; do
		echo $id >> $idlist
	done
fi

downloadformat="&are=ogg3"
torrentformat="&class=ogg3"
if [[ "`basename $0`" == "jampget" ]]
then
  downloadformat=
  torrentformat=
fi
echo "idlist=$idlist"
while read albumid ; do

	albumid=`basename "${albumid%/?p2pnet=bittorrent${downloadformat}}"`
	if [[ "${printuris}" == "true" ]]
	then
		echo "INFO: Album URI=http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${albumid}/?p2pnet=bittorrent${downloadformat}"
		echo "INFO: Torrent URI=http://api.jamendo.com/get2/bittorrent/file/redirect/?album_id=${albumid}&type=archive${torrentformat}"
		continue
	fi

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

	echo -n "INFO: Downloading .torrent... "
	wget --quiet -t 0 -nv --continue -O ${albumid}.torrent "http://api.jamendo.com/get2/bittorrent/file/redirect/?album_id=${albumid}&type=archive${torrentformat}" $QUIET || { echo "failed. Skipping."; popd $QUIET; continue; }
	echo "done."

	if [[ "`basename $0`" == "jamssi" ]]
	then
		jamssia "${albumid}" "${downloadformat}" || { popd $QUIET; continue; }
		cp "${albumid}.tar.bz2" "${downloadtarget%/}/"
		pushd "${downloadtarget}" $QUIET
		echo "INFO: Bunzipping+untarring to torrents directory and moving tar.bz2 to extracted directory, .torrent to watch directory"
		tar xf "${albumid}.tar.bz2" && { popd $QUIET && rm "${albumid}.tar.bz2" && mv ${albumid}.torrent "${torrentfiletarget%/}/" && pushd "${downloadtarget}" $QUIET; } && rm "${albumid}.tar.bz2"
		popd $QUIET
	else
		echo -n "INFO: Downloading .zip... "
		LC_ALL=C wget -t 0 $limit $continue "http://www.jamendo.com/get/album/id/album/archiverestricted/redirect/${albumid}/?p2pnet=bittorrent${downloadformat}" $QUIET || { echo "failed. Skipping."; popd $QUIET; continue; }

		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 unzipped && mv unzipped "${downloadtarget%/}/${zipfile%.zip}" && mv "${zipfile}" extracted/ && mv ${albumid}.torrent "${torrentfiletarget%/}/"
		done < ziplistfile
		rm ziplistfile

	fi

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

rm $idlist
echo "INFO: Script finished"