z-music.org
z-music.org
. On this site you can find a song, listen and download it.bash
script to search for music using the “gentleman's set” of sed
, awk
and grep
. Well, plus a little curl or wget to taste.z-music.org
, it becomes clear that:z-music.org/search/
. As a GET parameter, you can pass the query text q
, the type of the query (AJAX) action
and the page number of the search result page
z-music.org/bitrate/
with the data "id=<SONG_ID>"
m1.z-music.org/t/<SONG_ID>_<HASH>
. <HASH>
found in the script at z-music.org/theme/new/js/lang.js
curl
, but nothing prevents you from using wget
. Instead of curl -s
will be wget -q -O -
, and instead of curl -F
will be wget --post-data
<HASH>
in the hsh
variable: hsh=$(curl -s http://z-music.org/theme/new/js/lang.js | sed -n 's/^var hsh="\([^"]*\)";$/\1/p')
$query
and $page
will contain the query text and the page number of the result. Send a request to the server: curl -s "http://z-music.org/search/?page=$page&action=ajax&q=$query"
<a class="info" data-aid="SONG_ID"...>SONG_NAME</a>
. Get <SONG_ID>
and <SONG_NAME>
separated by tabs: sed -n 's/^\s*<a class="info" data-aid="\([^"]*\)"[^>]*>\([^<]*\)<\/a>\s*$/\1\t\2/p'
<SONG_ID>
you can send a request to bitrate. JSON will be returned. In order to pull out the very value of bitrate, use the cut
utility. For a change. curl -sF "id=$songid" http://z-music.org/bitrate/ | cut -d'"' -f8
m1.z-music.org/t/${songid}_${hsh}/
#!/bin/bash case $# in 1) query=$1 bitrate=320 ;; 2) query=$1 bitrate=$2 ;; *) echo -e 'Usage:\n\tzmusic "song name"\nor:\n\tzmusic "song name" 256\nwhere 256 is bitrate' exit ;; esac hsh=$(curl -s http://z-music.org/theme/new/js/lang.js | sed -n 's/^var hsh="\([^"]*\)";$/\1/p') # infinite loop incrementing search page for (( page=1; page>0; page++ )) do result=$( \ curl -s "http://z-music.org/search/?page=$page&action=ajax&q=$query" | \ sed -n 's/^\s*<a class="info" data-aid="\([^"]*\)"[^>]*>\([^<]*\)<\/a>\s*$/\1\t\2/p' | \ awk -v hsh=$hsh -F"\t" ' \ { \ system("curl -sF \"id=" $1 "\" http://z-music.org/bitrate/ | cut -d\"\\\"\" -f8"); \ print "http://m1.z-music.org/t/" $1 "_" hsh "/"; \ print $2 "\n"; \ }') # stop the script if nothing found on this page if [ -z "$result" ]; then exit; fi # output songs with $bitrate only while read -r res; do echo -e $res; done <<< "$result" | grep -A2 "$bitrate" echo -e "-- end of page $page --\n" done
$ zmusic "Habr" "256 \ | 320" 320 http://m1.z-music.org/t/-3ev4fnuc23h_2b49895762/ Habr - Addict song - 320 http://m1.z-music.org/t/-3ev4fnubytf_2b49895762/ HaBr - Nedomassaraksh - 320 http://m1.z-music.org/t/-3ev4fnuc1d3_2b49895762/ HaBr - Travel [Hedgehogs and Petruccio cover] - 320 http://m1.z-music.org/t/-3ev4fntmcfl_2b49895762/ Habr - Do not take the elevator (new single) - end of page 1 -
Source: https://habr.com/ru/post/141924/
All Articles