Hack:di.fm-playlists
Talk0this wiki
Contents |
DI.FM playlists
Edit
This tiny script downloads all playlists from www.di.fm, converts them from .pls to .m3u and places them in you MPD-playlists directory. it is free to be modified/extended. but if you do so, please update the version is this wiki, too.
PREMIUM PLAYLIST DOWNLOAD
Edit
If you decide to get the premium account on the di.fm or sky.fm, the list generation requires you to enter your credentials. I have modified one of the scripts i've found online, as following (AAC 128)
#/bin/sh USER="sdfr" PASS="545sdfsdfsdf13" dir=$1; url=$2 prefix=$3 if [ "$dir" == "" ]; then echo "Usage: di.sh PLAYLIST_DIR [URL] [FILENAME_PREFIX]" echo "URL defaults to http://listen.di.fm/public3" echo "public1: AAC 64, public2: AAC 32, public3: MP3 96, public5: WMA 40" echo echo "EXAMPLE" echo "di.sh /var/lib/mpd/playlists" echo "di.sh /var/lib/mpd/playlists listen.sky.fm/public3" exit fi if [ "$url" == "" ]; then url="http://listen.di.fm/public3"; fi if [ "$prefix" == "" ]; then prefix="`echo "$url" | sed 's/.*\b\([^.]\+\.[^.]\+\)\/.*/\1/'`"; fi for name in `wget -nv -O - $url | grep -o '"key":"[^"]*"' | sed 's/"key":"\([^"]*\)"/\1/g'`; do echo $name file="$dir/$prefix-$name.m3u" # wget -nv -O $file "$url/$name.pls" wget -nv -O $file "http://www.di.fm/listen/$name/128k.pls?user=$USER&pass=$PASS" sed -n -i 's/^File[0-9]*=//p' $file done
JSON API
Edit
There's a new JSON API available at listen.di.fm & listen.sky.fm
You can access the 96kbps MP3 streams at listen.di.fm/public3
Other formats: public1: AAC 64, public2: AAC 32, public3: MP3 96, public5: WMA 40
di.sh
Edit
#/bin/sh
# http://mpd.wikia.com/index.php?title=Hack:di.fm-playlists
mpd_conf="/etc/mpd.conf"
default_url="http://listen.di.fm/public3"
usage()
{
cat <<EOF
Usage: di.sh [PLAYLIST_DIR] [URL] [FILENAME_PREFIX]
PLAYLIST_DIR will be taken from ${mpd_conf} by default
URL defaults to http://listen.di.fm/public3
public1: AAC 64, public2: AAC 32, public3: MP3 96, public5: WMA 40
EXAMPLE
di.sh /var/lib/mpd/playlists
di.sh /var/lib/mpd/playlists listen.sky.fm/public3
EOF
exit ${1:-1}
}
# Be nice to user with standard help options
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
usage 0
fi
# Process user arguments and default values
dir=$1
: ${url:=${2:-${default_url}}}
: ${prefix:=${3:-`echo "$url" | sed 's/.*\b\([^.]\+\.[^.]\+\)\/.*/\1/'`}}
# Handle default playlist dir
if [ -z "$dir" ] ; then
if [ -e "${mpd_conf}" ] ; then
eval dir=`awk '$1=="playlist_directory"{print $NF}' "${mpd_conf}"`
fi
if [ -z "$dir" ] || [ ! -d "$dir" ] ; then
echo "sorry, unable to find mpd playlist dir: $dir"
exit 1
fi
fi
# Extract a value from json data given the keyword index
json_val()
{
local key=$1; shift
echo "$@" | sed -r -e 's|.*"'"${key}"'":"([^"]*)".*|\1|' -e 's:\\::g'
}
# Grab the json data and format it into newlines
wget -q -O - "$url" | sed -e 's:},{:\n:g' -e 's:^\[{::' -e 's:}\]$::' | \
while read line ; do
# Extract the human friendly name of the stream
name=$(json_val name "${line}")
# Extract the full URL to the .pls file
pls=$(json_val playlist "${line}")
# Grab the pls file and convert it to a m3u
file="${dir}/${prefix} ${name}.m3u"
wget -q -O - "${pls}" | sed -n 's/^File[0-9]*=//p' > "${file}"
done
Old versions which do not work anymore
Edit
original script
Edit
Usage:
- execute this script
- execute `mpd lsplaylists` to see what you've got :)
have fun with it, DocFX <docfx at softeys dot de>
#!/bin/bash
TMP_HTML="/tmp/html.txt"
TMP_PLSNAMES="/tmp/plsnames.txt"
TMP_PLSDIR="/tmp/pls/"
MPC_PLSDIR="/var/lib/mpd/playlists/"
wget www.di.fm -O ${TMP_HTML}
grep -ioe "[0-9a-z/\.:]*\\.pls" ${TMP_HTML} |\
grep -v aacplus| \
sed s/^\\//http:\\/\\/di.fm\\// > ${TMP_PLSNAMES}
mkdir ${TMP_PLSDIR}
wget -i ${TMP_PLSNAMES} -P ${TMP_PLSDIR}
for pls in `ls ${TMP_PLSDIR}`; do
out="${MPC_PLSDIR}di.fm-${pls/pls/m3u}"
cat ${TMP_PLSDIR}${pls}| \
grep File[0-9]*| \
sed s/^File[0-9]=// > ${out}
chown mpd:audio ${out}
done
rm -r ${TMP_PLSDIR}
rm ${TMP_PLSNAMES}
rm ${TMP_HTML}
a simpler version
Edit
A simpler version that does about the same thing, without temporary files and needless use of cat and grep. Copy the results to your playlists directory, or wherever else you like. --Paul Kishimoto
#/bin/sh wget -qO - di.fm | sed -n -e 's/^.*href="\(.*mp3.*\.pls\)".*$/\1/p' \ -e 's@^/@http://www.di.fm/@p' | sort | uniq | wget -qi - -P di.fm sed -n -i 's/^File[0-9]*=//p' di.fm/*.pls rename 's@(.*)/(.*)\.pls@$1/di.fm-$2.m3u@' di.fm/*.pls
another simpler version
Edit
#!/bin/sh
#copylefted by Harvie 2o12
get_playlist() {
wget "$1" -O - | grep -o 'http://[^"]*' | while read line; do
echo $(wget "$line" -O - | grep -o 'http://.*$' | grep '[a-zA-Z0-9]$' | head -n 1)?${line##*/}
done
}
get_playlist http://listen.di.fm/public3 > /root/playlists/di.fm.m3u
get_playlist http://listen.sky.fm/public3 > /root/playlists/sky.fm.m3u