d4rky

w-play beta1.6

Feb 1st, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 17.16 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # w-play 2 (author: Michał Matyas, http://nerdblog.pl)
  4. # ----------------------------------------------------
  5. #
  6. # Rewritten from scratch, new version of Wrzutaplayer.sh
  7. # Now support simple database system based on text files.
  8. #
  9. # How to use, version for dummies:
  10. #
  11. # 1. In terminal: chmod +x w-play2.sh (you have to do this ONCE)
  12. # 2. In terminal: ./w-play2.sh
  13. #
  14. # You are now in interactive mode. Neat, huh?
  15. #
  16. # 3. In interactive mode: add many Your Favourite Artist
  17. # 4. In interactive mode: play
  18. #
  19. # If you had enough, you can stop playing the music by pressing ^C (Ctrl+C)
  20. # Double pressing this combination will quit w-play 2 just like 'quit' command
  21. #
  22. # Enjoy your listening!
  23. #
  24.  
  25. WP2_VERSION="beta1.6"
  26.  
  27. ################################################################################
  28.  
  29. #
  30. # Hey, it supports last.fm now!
  31. #
  32.  
  33. #
  34. # Path to your lastfmsubmit program (check in /usr/local/lib if you're on Fedora)
  35. #
  36. WP2_LASTFMSUBMIT_PATH="/usr/lib/lastfmsubmitd/lastfmsubmit"
  37.  
  38. #
  39. # Set to 1 to scrobble on default
  40. #
  41. WP2_LASTFM_ON=1
  42.  
  43.  
  44. ################################################################################
  45.  
  46. trap '[[ "${WP2_EMERGENCY_STOP}" == 1 ]] && exit 255 || WP2_EMERGENCY_STOP=1' SIGINT
  47.  
  48. #
  49. # Reads the w-play2 database and saves it into WP2_DB variable
  50. #
  51. # @param string $1 Database name
  52. #
  53. load_db()
  54. {
  55.     [[ -z "$1" ]] && return 1;
  56.    
  57.     if [ ! -r "${1}" ];
  58.     then
  59.         echo "${1} does not exist."
  60.         return 1
  61.     fi
  62.  
  63.     IFS=$(printf "\n\b")
  64.  
  65.     local i=''
  66.     [[ -z "${WP2_DB_COUNT}" ]] && local n=0 || local n=$[WP2_DB_COUNT];
  67.  
  68.     local len=$(cat "${1}" | wc -l)
  69.     local prg=0
  70.  
  71.     WP2_DB_NAME="${1}"
  72.     for i in $(cat "${1}");
  73.     do
  74.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  75.  
  76.         prg=$[prg+1]
  77.         progress_bar "Loading database... [%3d%%]" ${prg} ${len}
  78.         if [ ! -z "${i}" ]; then
  79.             WP2_DB[${n}]="${i}";
  80.             n=$[n+1]
  81.             WP2_DB_COUNT="${n}"
  82.         fi
  83.     done
  84.     progress_bar_hide
  85.  
  86.     search_clear_results
  87.  
  88.  
  89.     echo "Database loaded."
  90.  
  91. }
  92.  
  93. #
  94. # Lists database fields
  95. #
  96. # @uses get_from_db()
  97. #
  98. list_db()
  99. {
  100.     local i=0
  101.  
  102.     if [[ ${WP2_DB_COUNT} == 0 || -z ${WP2_DB_COUNT} ]];
  103.     then
  104.        
  105.         echo "Database is empty"
  106.        
  107.     fi
  108.  
  109.     for i in $( seq 0 $((${WP2_DB_COUNT} - 1)) );
  110.     do
  111.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  112.        
  113.         get_from_db "$[i+1]"
  114.         echo "$[i+1]. ${WP2_LAST_ELEMENT[1]}"
  115.  
  116.     done;
  117. }
  118.  
  119.  
  120. #
  121. # Creates empty DB (just a nice wrapper for clearing WP2_DB)
  122. #
  123. # @uses search_clear_results()
  124. #
  125. clear_db()
  126. {
  127.     WP2_DB=();
  128.     WP2_DB_COUNT=0
  129.     WP2_DB_NAME=''
  130.  
  131.     WP2_LAST_ELEMENT=()
  132.     search_clear_results
  133. }
  134.  
  135. #
  136. # Adds element to the DB
  137. #
  138. # @param string $1 Wrzuta.pl address
  139. # @param string $2 Song name
  140. # @param string $3 Song length
  141. # @uses search_clear_results()
  142. #
  143. add_to_db()
  144. {
  145.     WP2_DB[${WP2_DB_COUNT}]="${1};${2};${3}";
  146.     WP2_DB_COUNT=$[WP2_DB_COUNT + 1]
  147.  
  148.     search_clear_results
  149. }
  150.  
  151. #
  152. # Saves the w-play2 database in file
  153. # Warning! All data in the file are erased!
  154. #
  155. # @param string $1 File name
  156. # @uses progress_bar()
  157. # @uses progress_bar_hide()
  158. #
  159. save_db()
  160. {
  161.     [[ -z "$1" ]] && return 1;
  162.  
  163.     echo -ne "" > "$1"
  164.     echo "Saving ${WP2_DB_COUNT} entries in ${1}"
  165.  
  166.     local i=0
  167.     for i in $( seq 0 $((${WP2_DB_COUNT} - 1)) ); do
  168.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  169.    
  170.    
  171.         progress_bar "Saving... [%3d%%] " $i $((${WP2_DB_COUNT} - 1))
  172.         echo "${WP2_DB[${i}]}" >> "$1"
  173.        
  174.     done;
  175.     progress_bar_hide
  176. }
  177.  
  178. #
  179. # Reads the w-play2 element from database
  180. #
  181. # @param int $1 Entry ID
  182. #
  183. get_from_db()
  184. {
  185.     if [[ ${WP2_DB_COUNT} -lt ${1} ]];
  186.     then
  187.  
  188.         echo "Entry ${1} does not exist in this database."
  189.         return 1
  190.  
  191.     fi
  192.     local db_elem="${WP2_DB[ $[ $((${1} - 1)) ] ]}"
  193.     local array_names=( name link )
  194.     local i=0
  195.  
  196.     WP2_LAST_ELEMENT=()
  197.  
  198.     if [[ -z "${db_elem}" ]];
  199.     then
  200.  
  201.         echo "Entry ${1} does not exist in this database."
  202.         return 1
  203.  
  204.     fi
  205.  
  206.     for i in 1 2 3;
  207.     do
  208.  
  209.         WP2_LAST_ELEMENT[$[ ${i} - 1 ]]="$( echo "${db_elem}" | cut -d";" -f$i )";
  210.  
  211.     done;
  212. }
  213.  
  214. #
  215. # Deletes an entry from database
  216. #
  217. # @param id $1 Entry ID
  218. #
  219. delete_from_db()
  220. {
  221.     get_from_db "$1"
  222.  
  223.     echo "${WP2_LAST_ELEMENT[1]} removed from database"
  224.  
  225.     unset WP2_DB[${1}]
  226.     search_clear_results
  227. }
  228.  
  229. #
  230. # Searches for a song in database
  231. #
  232. # @param string $1 Searched entry
  233. # @uses get_from_db
  234. #
  235. search_db()
  236. {
  237.     local i=0
  238.     local n=0
  239.  
  240.     for i in $( seq 1 ${WP2_DB_COUNT} );
  241.     do
  242.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  243.  
  244.         progress_bar "Searching... [%3d%%]" $i $[${WP2_DB_COUNT}-1]
  245.         get_from_db "$i"
  246.  
  247.         # Search for keywords inside, not 1:1 match
  248.         if [[ -n $(echo "${WP2_LAST_ELEMENT[*]}" | grep -i "${1}") ]];
  249.         then
  250.             WP2_SEARCH[${n}]="${i}"
  251.             n=$[n+1]
  252.         fi
  253.         WP2_SEARCH_COUNT=${n}
  254.     done;
  255.     progress_bar_hide
  256.  
  257.     [[ -n "${WP2_SEARCH[*]}" ]] && return 0 || return 1;
  258. }
  259.  
  260. #
  261. # Clears search results
  262. #
  263. search_clear_results()
  264. {
  265.     WP2_SEARCH=()
  266.     WP2_SEARCH_COUNT=0
  267. }
  268.  
  269. #
  270. # Wrapper for search_db() in interactive mode
  271. #
  272. # @param string $1 Searched entry
  273. # @uses search_db()
  274. #
  275. find_in_db()
  276. {
  277.     search_db "${1}"
  278.     echo "Found ${WP2_SEARCH_COUNT} entries"
  279.  
  280.     if [[ -n "${WP2_SEARCH}" ]];
  281.     then
  282.         for i in ${WP2_SEARCH[*]};
  283.         do
  284.             get_from_db ${i}
  285.             echo "${i}. ${WP2_LAST_ELEMENT[1]}"
  286.         done;
  287.  
  288.         echo "To play them all, type play found"
  289.     fi
  290. }
  291.  
  292. #
  293. # Plays a song from database
  294. #
  295. # @param int $1 ID of database entry
  296. # @uses get_from_db
  297. #
  298. play_from_db()
  299. {
  300.     get_from_db $1
  301.     [[ $? != 0 ]] && return 1;
  302.    
  303.     echo -ne "Loading...\r"
  304.  
  305.     local mp3="$( wrzuta_mp3 "${WP2_LAST_ELEMENT[0]}" )"
  306.  
  307.     if [[ -z "$mp3" ]];
  308.     then
  309.    
  310.         echo "An error occured while loading an MP3. Maybe it's just a glitch."
  311.    
  312.     else
  313.  
  314.         echo "Now playing: ${WP2_LAST_ELEMENT[1]} (${WP2_LAST_ELEMENT[2]})"
  315.  
  316.         local starttime="$(date +%s)"
  317.         MPLAYER_VERBOSE=-6 mplayer -msglevel all=-1:statusline=5 "$mp3" 2>/dev/null
  318.         local errorcode=$?
  319.         local endtime="$(date +%s)"
  320.  
  321.         local mintime=$(( $( echo "${WP2_LAST_ELEMENT[2]}" | awk -F: '{if($0=="") print '0';else if($3!="") print $1*3600+$2*60+$3;else if($2!="") print $1*60+$2;else print $1}' ) / 3 ))
  322.  
  323.         if [[ "${errorcode}" == "0" && $((${endtime}-${starttime})) > ${mintime} ]];
  324.         then
  325.  
  326.             lastfm_scrobble "$1"
  327.  
  328.         fi
  329.  
  330.     fi
  331. }
  332.  
  333.  
  334. #
  335. # Tries to guess song's data based on name
  336. # Yep, it's pretty dumb
  337. #
  338. # @param int $1 Entry ID
  339. #
  340. guess_tags()
  341. {
  342.  
  343.     WP2_TAGS=()
  344.  
  345.     get_from_db $1
  346.  
  347.     if [[ -n "${WP2_LAST_ELEMENT[*]}" ]];
  348.     then
  349.  
  350.         local tested=$(echo ${WP2_LAST_ELEMENT[1]} | sed -e "s/^[0-9_-'\" ]*//" -e "s/ *\$//")
  351.  
  352.         # Title
  353.         WP2_TAGS[0]=$(echo ${tested} | cut -d '-' -f 1 | sed -e "s/(.*)//g" -e "s/\[.*\]//g" -e "s/live.*//i" -e "s/cover\$//i" -e "s/ *\$//")
  354.  
  355.         # Name
  356.         WP2_TAGS[1]=$(echo ${tested} | cut -d '-' -f 2- | sed -e "s/(.*)//g" -e "s/\[.*\]//g" -e "s/live.*//i" -e "s/cover\$//i" -e "s/^[0-9_-'\" ]*//" -e "s/ *\$//")
  357.  
  358.         # Duration
  359.         WP2_TAGS[2]=${WP2_LAST_ELEMENT[2]}
  360.  
  361.         # Link
  362.         WP2_TAGS[3]=${WP2_LAST_ELEMENT[0]}
  363.  
  364.     fi
  365.  
  366. }
  367.  
  368. #
  369. # Progress bar
  370. #
  371. # @param string $1 Text to be shown (uses %d to show percentage)
  372. # @param int $2 Number
  373. # @param int $3 Maximum value of Number
  374. #
  375. progress_bar()
  376. {
  377.     tput sc
  378.  
  379.     if [[ $3 == 0 ]];
  380.     then
  381.         return 1;
  382.     fi
  383.  
  384.     local percent=$(( ($2 * 100) / $3 ));
  385.  
  386.     bars=$((${percent}/10))
  387.     progressbar="$(for bar in $(seq ${bars} ); do echo -n '='; done)>"
  388.     [[ bars -ge 10 ]] && progressbar="==========";
  389.  
  390.     printf "\r${1} [%-10s]" "${percent}" "${progressbar}"
  391.     #printf "\r$1" $percent
  392.  
  393. }
  394.  
  395. #
  396. # Hides scraps left behind by progress bar
  397. #
  398. progress_bar_hide()
  399. {
  400.     tput el1;
  401.     tput rc;
  402.  
  403.     printf "\r"
  404. }
  405.  
  406. #
  407. # Gets one song from Wrzuta.pl's audio search
  408. #
  409. # @param string $1 Song title, or whatever should be searched for
  410. #
  411. wrzuta_get_one()
  412. {
  413.     echo "Searching for: ${1}"
  414.     local link="$(wget "http://www.wrzuta.pl/szukaj/audio/${1}" --user-agent="Mozilla 5.0" -q -O - | awk -F \" '/class="title"/{ print $4 }' | head -n 1)"
  415.  
  416.     echo -ne "Saving ${link##*/} ... "
  417.     songname=$(wrzuta_title "$link")
  418.     songlength=$(wrzuta_duration "$link")
  419.     echo -ne "done.\n"
  420.     add_to_db "$link" "$songname" "$songlength"
  421. }
  422.  
  423. #
  424. # Gets whole list of songs from Wrzuta.pl's audio search
  425. #
  426. # @param string $1 Song title, or whatever should be searched for
  427. # @param int $2 Number of pages to search
  428. #
  429. wrzuta_get_many()
  430. {
  431.     echo "Searching for: ${1}"
  432.     local links=" ";
  433.  
  434.     while [[ -n "$links" ]]; do
  435.  
  436.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  437.  
  438.         local page=$[page+1];
  439.  
  440.         if [[ -n "${2}" && "${2}" < "${page}" ]];
  441.         then
  442.             return 0;
  443.         fi
  444.        
  445.         local links=$(wget "http://www.wrzuta.pl/szukaj/audio/${1}/$page" --user-agent="Mozilla 5.0" -q -O - | awk -F \" '/class="title"/{ print $4 }')
  446.  
  447.         [[ -n "${links}" ]] && echo -e "\nPage: ${page}";
  448.  
  449.         local link
  450.         for link in $links; do
  451.             [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && return 1;
  452.            
  453.             echo -ne "Saving ${link##*/} ... "
  454.             songname=$(wrzuta_title $link)
  455.             songlength=$(wrzuta_duration $link)
  456.             echo -ne "done.\n"
  457.             add_to_db "$link" "$songname" "$songlength"
  458.         done;
  459.  
  460.         echo ""
  461.  
  462.     done;
  463. }
  464.  
  465. #
  466. # Adds song to Last.fm
  467. #
  468. # @param int $1 Entry ID
  469. #
  470. lastfm_scrobble()
  471. {
  472.     if [[ "${WP2_LASTFM_ON}" == "1" ]];
  473.     then
  474.  
  475.         guess_tags "${1}"
  476.  
  477.         if [[ -n "${WP2_TAGS[0]}" && -n "${WP2_TAGS[1]}" && -n "${WP2_TAGS[2]}" && "${WP2_TAGS[0]}" != "${WP2_TAGS[1]}" ]];
  478.         then
  479.  
  480.             ${WP2_LASTFMSUBMIT_PATH} --artist "${WP2_TAGS[0]}" --title "${WP2_TAGS[1]}" --length "${WP2_TAGS[2]}"
  481.  
  482.         fi
  483.  
  484.     fi
  485.  
  486. }
  487.  
  488. #
  489. # Gets list of songs from Wrzuta.pl's audio search based on
  490. # TasteKid simliar search engine
  491. #
  492. # @param string $1 Artist name
  493. #
  494. wrzuta_get_similar()
  495. {
  496.     IFS=$(printf "\n\b")
  497.  
  498.     for i in $(tastekid_similar ${1});
  499.     do
  500.         wrzuta_get_many ${i} 1
  501.     done
  502. }
  503.  
  504. #
  505. # Helper method, gets song's name
  506. #
  507. # @param string $1 Link to the song
  508. #
  509. wrzuta_title()
  510. {
  511.     echo "$(wget -q -O - "$1" | grep '<title>' | sed -e 's/.*WRZUTA - \([^<]*\).*/\1/' -e "s/&#039;/'/g" -e 's/&[^;]*;//g' -e 's/;//g' )"
  512. }
  513.  
  514.  
  515. #
  516. # Helper method, gets song's duration
  517. #
  518. # @param string $1 Link to the song
  519. #
  520. wrzuta_duration()
  521. {
  522.     echo $(echo $(wget -q -O - "$1" |tr -d '\n'|sed -e 's/.*<span id="file_info_data_size">\([^>]*\)<\/span>.*/\1/g'))
  523. }
  524.  
  525. #
  526. # Helper method, gets song's MP3 address
  527. #
  528. # @param string $1 Link to the song
  529. #
  530. wrzuta_mp3()
  531. {
  532.     echo $(wget -q "$(echo "$1/f/a/i/l" | sed -e 's/audio/xml\/plik/')" -O -|grep "fileId"|sed -e 's/.*\[\(.*\)\]\].*/\1/')
  533. }
  534.  
  535. #
  536. # Searches in TasteKid.com for similar artists
  537. #
  538. # @param string $1 Artist name
  539. #
  540. tastekid_similar()
  541. {
  542.     # Thanks blueyed for perl code
  543.     wget "http://www.tastekid.com/ask/ws?q=band:$( echo ${1} | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' )" -q -O -|grep 'name'|sed -e 's/.*CDATA\[\(.*\)\]\].*/\1/'
  544. }
  545.  
  546.  
  547. #
  548. # Meat!
  549. #
  550. wplay2()
  551. {
  552.     # It *WILL* come handy
  553.     local i=0;
  554.  
  555.     echo "w-play 2 (${WP2_VERSION})"
  556.     echo "For command list type: help"
  557.  
  558.     if [[ -n "${1}" ]];
  559.     then
  560.  
  561.         if [[ -r "${1}" ]];
  562.         then
  563.  
  564.             load_db "${1}"|less
  565.             play
  566.        
  567.         else
  568.    
  569.             echo "Usage: ${0} [dbname]"
  570.             echo ""
  571.             echo "Or use interactive mode, you dummy."
  572.        
  573.         fi
  574.    
  575.     fi
  576.  
  577.     while read -p '> ' arg; do
  578.  
  579.         # QUIT
  580.         [[ "${arg}" == "quit" || "${arg}" == "exit" ]] && exit 0;
  581.  
  582.         # Load Database
  583.         if   [[ "${arg:0:5}" == "load " ]];
  584.         then
  585.  
  586.             load_db "${arg:5}"
  587.  
  588.         elif [[ "${arg}" == "list" ]];
  589.         then
  590.  
  591.             list_db
  592.  
  593.         elif [[ "${arg}" == "clear" ]];
  594.         then
  595.    
  596.             clear_db
  597.    
  598.         elif [[ "${arg:0:8}" == "add one " ]];
  599.         then
  600.  
  601.             wrzuta_get_one "${arg:8}"
  602.             echo "Finished";
  603.  
  604.         elif [[ "${arg:0:9}" == "add many " ]];
  605.         then
  606.  
  607.             wrzuta_get_many "${arg:9}"
  608.             echo "Finished";
  609.  
  610.         elif [[ "${arg:0:12}" == "add similar " ]];
  611.         then
  612.  
  613.             wrzuta_get_similar "${arg:12}"
  614.             echo "Finished";
  615.  
  616.  
  617.         # Hidden from command list because it's mostly for debugging
  618.         elif [[ "${arg:0:5}" == "tags " ]];
  619.         then
  620.  
  621.             guess_tags "${arg:5}"
  622.  
  623.             if [[ -n "${WP2_TAGS[*]}" ]];
  624.             then
  625.  
  626.                 echo "Artist     : ${WP2_TAGS[0]}"
  627.                 echo "Song       : ${WP2_TAGS[1]}"
  628.                 echo "Duration   : ${WP2_TAGS[2]}"
  629.                 echo "Link       : ${WP2_TAGS[3]}"
  630.  
  631.             fi
  632.  
  633.  
  634.         elif [[ "${arg:0:5}" == "find " ]];
  635.         then
  636.  
  637.             find_in_db "${arg:5}"
  638.  
  639.         elif [[ "${arg:0:4}" == "del " ]];
  640.         then
  641.    
  642.             if [[ ${WP2_DB_COUNT} > 0 ]];
  643.             then
  644.                 if [[ -n "${arg:4}" ]];
  645.                 then
  646.                     for i in ${arg:4};
  647.                     do
  648.  
  649.                         delete_from_db ${i}
  650.                
  651.                     done
  652.                 fi
  653.             else
  654.        
  655.                 echo "Database is not loaded"
  656.        
  657.             fi
  658.    
  659.    
  660.         elif [[ "${arg:0:5}" == "save " ]];
  661.         then
  662.  
  663.             if [[ -z "${arg:5}" ]];
  664.             then
  665.            
  666.                 save_db "${WP2_DB_NAME}"
  667.  
  668.             else
  669.  
  670.                 save_db "${arg:5}"
  671.            
  672.             fi
  673.  
  674.            
  675.         elif [[ "${arg}" == "play" ]];
  676.         then
  677.  
  678.             if [[ ${WP2_DB_COUNT} > 0 ]];
  679.             then
  680.  
  681.                 for i in $(seq 1 ${WP2_DB_COUNT});
  682.                 do
  683.                     [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  684.                    
  685.                     play_from_db ${i}
  686.                 done
  687.  
  688.                 echo -e "\nFinished";
  689.             else
  690.  
  691.                 echo "Database is empty"
  692.  
  693.             fi
  694.  
  695.         elif [[ "${arg}" == "play random" ]];
  696.         then
  697.  
  698.             if [[ ${WP2_DB_COUNT} > 0 ]];
  699.             then
  700.  
  701.                 local tmp_playlist=()
  702.  
  703.                 for i in $(seq 1 ${WP2_DB_COUNT});
  704.                 do
  705.                     [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  706.  
  707.                     tmp_playlist[${RANDOM}]="${i}"
  708.                 done
  709.  
  710.                 for i in ${tmp_playlist[*]};
  711.                 do
  712.                     [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  713.                    
  714.                     play_from_db ${i}
  715.                 done
  716.  
  717.                 echo -e "\nFinished";
  718.             else
  719.  
  720.                 echo "Database is empty"
  721.  
  722.             fi
  723.  
  724.         elif [[ "${arg}" == "play found" ]];
  725.         then
  726.  
  727.             if [[ ${WP2_DB_COUNT} > 0 ]];
  728.             then
  729.  
  730.                 if [[ -n ${WP2_SEARCH} && ${WP2_SEARCH_COUNT} > 0 ]];
  731.                 then
  732.  
  733.                     for i in ${WP2_SEARCH[*]};
  734.                     do
  735.                         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  736.  
  737.                         play_from_db ${i}
  738.                     done
  739.  
  740.                 echo -e "\nFinished";
  741.  
  742.                 else
  743.  
  744.                     echo "You have to find something first."
  745.  
  746.                 fi
  747.  
  748.             else
  749.  
  750.                 echo "Database is empty"
  751.  
  752.             fi
  753.  
  754.         elif [[ "${arg:0:5}" == "play " ]];
  755.         then
  756.  
  757.             if [[ ${WP2_DB_COUNT} > 0 ]];
  758.             then
  759.                 if [[ -n "${arg:5}" ]];
  760.                 then
  761.                     for i in ${arg:5};
  762.                     do
  763.                         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  764.  
  765.                         play_from_db ${i}
  766.  
  767.                     done
  768.                 else
  769.                     for i in $(seq 1 ${WP2_DB_COUNT});
  770.                     do
  771.                         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && break;
  772.  
  773.                         play_from_db ${i}
  774.                     done
  775.                 fi
  776.                 echo -e "\nFinished";
  777.             else
  778.  
  779.                 echo "Database is empty"
  780.  
  781.             fi
  782.  
  783.         elif [[ "${arg:0:8}" == "similar " ]];
  784.         then
  785.  
  786.             echo -ne "Checking on TasteKid... \r"
  787.             echo $(tastekid_similar "${arg:8}")
  788.  
  789.  
  790.         elif [[ "${arg:0:8}" == "scrobble" ]];
  791.         then
  792.  
  793.             if [[ ! -x "${WP2_LASTFMSUBMIT_PATH}" ]];
  794.             then
  795.  
  796.                 echo "You have to install lastfmsubmitd and set a proper path in configuration"
  797.  
  798.             else
  799.  
  800.                 if [[ "${arg:9}" == "on" ]];
  801.                 then
  802.  
  803.                     WP2_LASTFM_ON=1
  804.                     echo "Scrobbling enabled."
  805.  
  806.                 else
  807.  
  808.                     WP2_LASTFM_ON=0
  809.                     echo "Scrobbling disabled."
  810.  
  811.                 fi
  812.  
  813.             fi
  814.  
  815.  
  816.  
  817.         elif [[ "${arg}" == "help" ]];
  818.         then
  819.  
  820.             echo " "
  821.             echo "  List of commands:"
  822.             echo "--------------------------------------------------------------------------------"
  823.             echo " "
  824.             echo "  load [filename]      - loads database from file"
  825.             echo "  save [filename]      - saves database to file (file is overwritten)"
  826.             echo " "
  827.             echo "  list                 - lists all entries in database"
  828.             echo "  clear                - clears database"
  829.             echo " "
  830.             echo "--------------------------------------------------------------------------------"
  831.             echo " "
  832.             echo "  add one [name]       - looks for a song in Wrzuta.pl"
  833.             echo "  add many [name]      - looks for a list of songs in Wrzuta.pl"
  834.             echo " "
  835.             echo "  add similar [artist] - looks for songs of similar artists"
  836.             echo " "
  837.             echo "--------------------------------------------------------------------------------"
  838.             echo " "
  839.             echo "  del [id]             - remove ID entry from database"
  840.             echo "  del [list]           - remove listed IDs from database"
  841.             echo " "
  842.             echo "--------------------------------------------------------------------------------"
  843.             echo " "
  844.             echo "  play                 - plays all entries from database"
  845.             echo "  play [id]            - plays ID entry from database"
  846.             echo "  play [list]          - plays listed IDs from database"
  847.             echo " "
  848.             echo "  play random          - plays random entries from database"
  849.             echo " "
  850.             echo "--------------------------------------------------------------------------------"
  851.             echo " "
  852.             echo "  find [name]          - searches database for NAME"
  853.             echo "  play found           - plays entries found using 'find' command"
  854.             echo " "
  855.             echo "--------------------------------------------------------------------------------"
  856.             echo " "
  857.             echo "  similar [name]       - looks for similar bands on TasteKid"
  858.             echo "  scrobble [on/off]    - toggles scrobbling on Last.FM"
  859.             echo " "
  860.             echo "--------------------------------------------------------------------------------"
  861.             echo " "
  862.             echo "  help                 - this list of commands"
  863.             echo "  quit                 - closes w-play2"
  864.             echo " "
  865.    
  866.         elif [[ "${WP2_EMERGENCY_STOP}" != "1" ]];
  867.         then
  868.  
  869.             echo "Unknown command: '${arg}'. Type help for command list."
  870.    
  871.         fi
  872.  
  873.         [[ "${WP2_EMERGENCY_STOP}" == "1" ]] && echo "Stopped on user request."
  874.         WP2_EMERGENCY_STOP=0; # We're safe now, bad people are gone
  875.  
  876.  
  877.     done;
  878. }
  879.  
  880. wplay2 # kaboom!
Add Comment
Please, Sign In to add comment