Last.fm RadioをMPDプレイリストに追加します

こんにちはHabramens、



IchBin's。 すべては、 last.fmラジオのサポートがMPDで非常に不器用に実装されていたため、この関数のコンパイルを停止したという事実から始まりました。 その不器用さは、サーバーがリクエストごとに5つのトラックを提供するため、チャンネルにチューニングした後、プレイリストにトラックを手動で追加する必要があるという事実にあります。 したがって、すべてのトラックが失われた後、リクエストを繰り返して次の5つのトラックを取得する必要があります! 次に、このプロセスを自動化するスクリプトについて説明します。



Bash.fm-ベアリングの作業



ここでオリジナルのアイデアが見つかりまし 。 リンク上のスクリプトは長い間古く、機能しませんでした。 さらに、スクリプトの作成者は非常に独特なスタイルを持ち、たとえばlynxに不要な依存関係を追加することができました。 したがって、作業のロジックは同じままですが、ほとんど変更する必要がありました。





fmstartから始めましょう。

root@Buffalo:~# cat /mnt/sd/bin/fmstart #!/bin/sh username=$(sed -nr 's/^username=(.*)/\1/p' ~/.bashfm) password=$(sed -nr 's/^password=([^[:space:]]*).*/\1/p' ~/.bashfm) mediaplayer=$(sed -nr 's/^mediaplayer=(.*)/\1/p' ~/.bashfm) if [ ! -z "$password" ]; then passwordmd5=$(echo -n $password | md5sum | sed -nr 's/([^[:space:]]*).*/\1/p') else passwordmd5=$(sed -nr 's/^passwordmd5=([^[:space:]]*).*/\1/p' ~/.bashfm) fi echo 'username='$username > ~/.bashfm echo 'password=' >> ~/.bashfm echo 'mediaplayer='"$mediaplayer" >> ~/.bashfm echo 'passwordmd5='$passwordmd5 >> ~/.bashfm login_url='http://ws.audioscrobbler.com/radio/handshake.php?' login_url="$login_url"'version=1.1.1&platform=linux&username=' login_url="$login_url"$username'&passwordmd5='$passwordmd5 login_url="$login_url"'&debug=0&partner=' echo "login_url=$login_url" >> ~/.bashfm wget -q -O - "$login_url" >> ~/.bashfm echo >> ~/.bashfm
      
      





スクリプトが正しく機能するためには、最初に〜/ .bashfmファイルを次の内容で作成する必要があります。

 root@Buffalo:~# cat ~/.bashfm username=ichbins password=123456 mediaplayer=/mnt/sd/bin/mpc add
      
      





ここで、ユーザー名とパスワードはlast.fmのユーザー名とパスワードであり、mediaplayerはトラックをプレイリストに追加するコマンドです。

fmstartを初めて起動すると、パスワードが削除され、md5の量に置き換えられます。



小さな余談:

MPCは、コマンドラインの標準MPDクライアントです。 しかし、私はそれをコンパイルしませんが、1行でスクリプトを使用します。

 root@Buffalo:~# cat /mnt/sd/bin/mpc #!/bin/sh echo "$*" | nc localhost 6600
      
      





このスクリプトはMPCの完全な類似物ではありませんが、私のニーズには常に十分でした。



次に、チャネルを選択するためのスクリプトについて説明します。 実際、それらはすべて同じであり、内部のチャネルURLのみが異なります。 私は個人のラジオまたは特定のアーティストのラジオを聴きます。したがって、以下ではこれら2つのスクリプトのみを紹介します。



パーソナルラジオチャネルアクティベーションスクリプト:

 root@Buffalo:~# cat /mnt/sd/bin/fmpersonal #!/bin/sh # # "fmpersonal" plays user's personal radio station # session=$(sed -nr 's/^session=(.*)/\1/p' ~/.bashfm) username=$(sed -nr 's/^username=(.*)/\1/p' ~/.bashfm) tuning_url='http://ws.audioscrobbler.com/radio/adjust.php?' tuning_url="${tuning_url}session=${session}&url=lastfm://user/" tuning_url="${tuning_url}${username}/personal" #echo "$tuning_url" wget -q -O - "$tuning_url" echo
      
      





成功すると、スクリプトは以下を生成します。

 root@Buffalo:~# /mnt/sd/bin/fmpersonal response=OK url=http://www.last.fm/listen/user/IchBins/personal stationname=IchBins's Library Radio
      
      





アーティストのアクティベーションスクリプトは次のようになります。

 root@Buffalo:~# cat /mnt/sd/bin/fmart #!/bin/sh # "fmart" plays the radio station corresponding to a # certain artist. It takes the artist's name as command # line argument. Use quotes when the artist's name # contains spaces. # # Example: # fmart 'jahcoozi' artist=$(echo $1 | sed 's/ /%20/g') session=$(sed -nr 's/^session=(.*)/\1/p' ~/.bashfm) tuning_url='http://ws.audioscrobbler.com/radio/adjust.php?' tuning_url="${tuning_url}session=${session}&url=lastfm://artist/" tuning_url="${tuning_url}${artist}/similarartists&debug=0" #echo "$tuning_url" wget -q -O - "$tuning_url" echo
      
      





実行結果:

 root@Buffalo:~# /mnt/sd/bin/fmart response=FAILED error=4 root@Buffalo:~# /mnt/sd/bin/fmart "Knorkator" response=OK url=http://www.last.fm/listen/artist/Knorkator/similarartists stationname=Knorkator Radio
      
      





チャンネルにチューニングすることにより、fmgetを使用して、チャンネルからプレイリストにトラックを追加できます。

 root@Buffalo:~# cat /mnt/sd/bin/fmget #!/bin/sh # "fmget" gets list of mp3's from a radiostation and # adds it into the current playlist # # Example: # fmart 'Depeche Mode'; fmget session=$(sed -nr 's/^session=(.*)/\1/p' ~/.bashfm) mplayer=$(sed -nr 's/^mediaplayer=(.*)/\1/p' ~/.bashfm) tuning_url='http://ws.audioscrobbler.com/radio/xspf.php?' tuning_url="${tuning_url}sk=${session}" tuning_url="${tuning_url}&discovery=0&desktop=1.5.1" #echo "$tuning_url" mp3list=$(wget -q -O - "$tuning_url" | sed -nr "s/.*<location>(.*)<\/location>/\1/p") for i in $mp3list; do #echo $i $mplayer "$i" done
      
      





仕事の結果:

 root@Buffalo:~# /mnt/sd/bin/fmget OK MPD 0.16.0 OK OK MPD 0.16.0 OK OK MPD 0.16.0 OK OK MPD 0.16.0 OK OK MPD 0.16.0 OK
      
      





結果のトラックへのリンクはmp3ファイルへのリンクであるため、MPDだけでなく任意のプレーヤーにフィードできます。 〜/ .bashfmファイルのmediaplayerパラメーターを置き換えるだけで十分です。



私が伝えたかったのはそれだけです。 プレイリストにトラックを追加するプロセスの自動化については、このスクリプトを宿題としてお任せします。 ここでは、fmgetを+100500回呼び出すか、ループ呼び出し「mpc status」で応答を解析し、nextsong == playlistlengthの場合、fmgetを呼び出します。



おまけに、ここまで習得したら、好奇心c盛な友人に、この記事のすべてのスクリプトを1本のボトルに入れます



All Articles