Skip to content

Instantly share code, notes, and snippets.

@i-sync
Created August 10, 2017 04:20
Show Gist options
  • Save i-sync/f699b09dad2c1ba6732df79aefbd8ad1 to your computer and use it in GitHub Desktop.
Save i-sync/f699b09dad2c1ba6732df79aefbd8ad1 to your computer and use it in GitHub Desktop.
use mpc random play douban ten songs
#!/usr/bin/env bash
type='n'
pt='3.1'
channel=1
pb='320'
from='mainsite'
kbps='320'
app_name='radio_website'
client='s:mainsite|y:3.0'
version='100'
sid="0"
#cookie='bid=N2eIL8ZvMyc; flag="ok"; ac="1502330993"; _ga=GA1.2.1127229252.1494605945; _gid=GA1.2.126872079.1502331592'
cookie="bid=`curl --silent --output /dev/null --cookie-jar - 'https://douban.fm' | grep bid | awk '{ print $7 }'`"
#echo $cookie
new_url="https://douban.fm/j/v2/playlist?channel=$channel&kbps=$kbps&client=$client&app_name=$app_name&version=$version&type=n&pt=&pb=$pb&apikey="
next_url="https://douban.fm/j/v2/playlist?channel=$channel&kbps=$kbps&client=$client&app_name=$app_name&version=$version&type=s&pt=&pb=$pb&apikey=&sid="
log=/tmp/douban.log
datetime=`date "+%F %T"`
echo $datetime >> $log
song_urls=[]
for i in {0..9}
do
if [ $sid == "0" ]
then
json_data=`curl "$new_url" -H "Cookie: $cookie"`
else
json_data=`curl "$next_url$sid" -H "Cookie: $cookie"`
fi
#echo $json_data
song_url=`echo $json_data | python -c "import sys, json; print(json.load(sys.stdin)['song'][0]['url'])"`
song_name=`echo $json_data | python -c "import sys, json; print(json.load(sys.stdin)['song'][0]['title'])"`
sid=`echo $json_data | python -c "import sys, json; print(json.load(sys.stdin)['song'][0]['sid'])"`
#echo "$song_name:$song_url"
song_urls[$i]=$song_url
echo "$song_name: $song_url" >> $log
sleep 2
done;
mpc clear
for i in {0..9}
do
mpc add ${song_urls[i]}
done;
mpc play
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment