plait 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. #! /bin/sh
  2. # Plait -- Search music library or Shoutcast radio streams and make
  3. # one of the supported music players play the results.
  4. #
  5. # Copyright (C) 2005-200* Stephen Jungels
  6. #
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # General Public License for more details.
  17. #
  18. # See COPYING for the full text of the license.
  19. #
  20. # See README for supported platforms and installation instructions.
  21. #
  22. # To contact the author: sjungels@gmail.com
  23. usage ()
  24. {
  25. echo "Usage is:"
  26. echo " \"plait <hint about artist or album or song> [[not] <hint>]...[as <mix>]\", or"
  27. echo " \"plait --stream <hint> [[not] <hint>]...\""
  28. echo "Options:"
  29. echo " --list,-l -- show matching tracks but don't play"
  30. echo " --mix,-m -- play tracks matching any hint (make a mix)"
  31. echo " --queue,-q -- add tracks to queue"
  32. echo " --random,-r -- play in random order"
  33. echo " --sort -- play in sorted order"
  34. echo " --stripe -- play in alternating order"
  35. echo " --stripe2 -- play in random alternating order"
  36. echo " --fade -- play in gaussian fade order"
  37. echo " --group -- play randomly in groups"
  38. echo " --tracks,-t -- play n tracks, if possible"
  39. echo " --stream,-s -- play Shoutcast radio streams"
  40. echo " --mixfile,-f -- read hints from mixfile"
  41. echo " --device,-d -- choose target device"
  42. echo " --platform -- choose platform"
  43. echo " --coverart -- cover art mode (0 or 1)"
  44. echo " --guest,-g -- use guest configuration"
  45. echo " --interactive,-i -- interactive mode"
  46. echo " --cache,-c -- rebuild cache"
  47. echo " --install -- install Plait"
  48. echo " --uninstall -- uninstall Plait"
  49. echo " --play "
  50. echo " --pause "
  51. echo " --stop "
  52. echo " --next "
  53. echo " --prev "
  54. echo " --help -- show help"
  55. echo " --version -- show version"
  56. }
  57. version ()
  58. {
  59. echo "Plait v 1.6.3"
  60. echo "Written by Stephen Jungels"
  61. echo ""
  62. echo "Copyright (c) 2005-2009 by Stephen Jungels. Released under the GPL."
  63. echo "Latest version and more info at http://plait.sourceforge.net/"
  64. }
  65. create_winamp_scripts ()
  66. {
  67. if ! test -f "$HOME/.plait/commands/cmd-play.vbs"
  68. then
  69. echo 1>&2 Installing Winamp scripts
  70. mkdir -p "$HOME/.plait/commands"
  71. PLAYLIST="`cygpath -aw \"$HOME/.plait/playlist2.m3u\"`"
  72. cat > "$HOME/.plait/commands/play.vbs" <<EOF
  73. Dim oWinCom
  74. set oWinCom = CreateObject("WinampCOM.Application")
  75. oWinCom.Stop
  76. oWinCom.ClearPlaylist
  77. oWinCom.AddFile("$PLAYLIST")
  78. oWinCom.Play
  79. EOF
  80. cat > "$HOME/.plait/commands/queue.vbs" <<EOF
  81. Dim oWinCom
  82. set oWinCom = CreateObject("WinampCOM.Application")
  83. oWinCom.AddFile("$PLAYLIST")
  84. EOF
  85. cat > "$HOME/.plait/commands/cmd-play.vbs" <<EOF
  86. Dim oWinCom
  87. set oWinCom = CreateObject("WinampCOM.Application")
  88. oWinCom.Play
  89. EOF
  90. cat > "$HOME/.plait/commands/cmd-pause.vbs" <<EOF
  91. Dim oWinCom
  92. set oWinCom = CreateObject("WinampCOM.Application")
  93. oWinCom.Pause
  94. EOF
  95. cat > "$HOME/.plait/commands/cmd-stop.vbs" <<EOF
  96. Dim oWinCom
  97. set oWinCom = CreateObject("WinampCOM.Application")
  98. oWinCom.Stop
  99. EOF
  100. cat > "$HOME/.plait/commands/cmd-next.vbs" <<EOF
  101. Dim oWinCom
  102. set oWinCom = CreateObject("WinampCOM.Application")
  103. oWinCom.FastForward
  104. EOF
  105. cat > "$HOME/.plait/commands/cmd-prev.vbs" <<EOF
  106. Dim oWinCom
  107. set oWinCom = CreateObject("WinampCOM.Application")
  108. oWinCom.Rewind
  109. EOF
  110. fi
  111. }
  112. create_itunes_scripts ()
  113. {
  114. if ! test -e "$HOME/.plait/commands/itunes-cmd-play.js"
  115. then
  116. echo 1>&2 Installing iTunes scripts
  117. mkdir -p "$HOME/.plait/commands"
  118. PLAYLIST="`cygpath -am \"$HOME/.plait/playlist2.m3u\"`"
  119. cat > "$HOME/.plait/commands/itunes-play.js" <<EOF
  120. var iTunesApp = WScript.CreateObject("iTunes.Application");
  121. var lists = iTunesApp.LibrarySource.Playlists;
  122. var list;
  123. list = lists.ItemByName("%PL%");
  124. while (list != null)
  125. {
  126. list.Delete();
  127. list = lists.ItemByName("%PL%");
  128. }
  129. list = iTunesApp.CreatePlaylist("%PL%");
  130. list.AddFile("$PLAYLIST");
  131. try
  132. {
  133. list.PlayFirstTrack();
  134. }
  135. catch (err) {}
  136. EOF
  137. cat > "$HOME/.plait/commands/itunes-queue.js" <<EOF
  138. var iTunesApp = WScript.CreateObject("iTunes.Application");
  139. var lists = iTunesApp.LibrarySource.Playlists;
  140. var list;
  141. list = lists.ItemByName("%PL%");
  142. if (list == null)
  143. {
  144. list = iTunesApp.CreatePlaylist("%PL%");
  145. }
  146. list.AddFile("$PLAYLIST");
  147. EOF
  148. cat > "$HOME/.plait/commands/itunes-cmd-play.js" <<EOF
  149. var iTunesApp = WScript.CreateObject("iTunes.Application");
  150. iTunesApp.Play();
  151. EOF
  152. cat > "$HOME/.plait/commands/itunes-cmd-pause.js" <<EOF
  153. var iTunesApp = WScript.CreateObject("iTunes.Application");
  154. iTunesApp.Pause();
  155. EOF
  156. cat > "$HOME/.plait/commands/itunes-cmd-stop.js" <<EOF
  157. var iTunesApp = WScript.CreateObject("iTunes.Application");
  158. iTunesApp.Stop();
  159. EOF
  160. cat > "$HOME/.plait/commands/itunes-cmd-next.js" <<EOF
  161. var iTunesApp = WScript.CreateObject("iTunes.Application");
  162. iTunesApp.NextTrack()
  163. EOF
  164. cat > "$HOME/.plait/commands/itunes-cmd-prev.js" <<EOF
  165. var iTunesApp = WScript.CreateObject("iTunes.Application");
  166. iTunesApp.PreviousTrack()
  167. EOF
  168. fi
  169. }
  170. install ()
  171. {
  172. if ! test "-$1-" = "--"
  173. then
  174. INSTALLDIR="$1"
  175. else
  176. if test $CYGWIN -ge 1
  177. then
  178. touch 2>/dev/null /etc/motd
  179. if test $? = 0
  180. then
  181. INSTALLDIR=/usr/local
  182. else
  183. INSTALLDIR="$HOME"
  184. fi
  185. else
  186. if test $(id -u) = 0
  187. then
  188. INSTALLDIR=/usr/local
  189. else
  190. INSTALLDIR="$HOME"
  191. fi
  192. fi
  193. fi
  194. echo Installing in $INSTALLDIR
  195. mkdir -p $INSTALLDIR/bin
  196. mkdir -p $INSTALLDIR/share/man/man1
  197. mkdir -p $INSTALLDIR/share/plait
  198. mkdir -p $INSTALLDIR/share/doc/plait
  199. if test -f plait
  200. then
  201. sed "s:%INSTALLDIR%:$INSTALLDIR:g" plait > $INSTALLDIR/bin/plait
  202. chmod +x $INSTALLDIR/bin/plait
  203. fi
  204. if test -f plait.1
  205. then
  206. cp plait.1 $INSTALLDIR/share/man/man1
  207. fi
  208. if test -f plait-s3
  209. then
  210. cp plait-s3 $INSTALLDIR/bin
  211. fi
  212. if test -f plaiter
  213. then
  214. cp plaiter $INSTALLDIR/bin
  215. fi
  216. if test -f plaiter.1
  217. then
  218. cp plaiter.1 $INSTALLDIR/share/man/man1
  219. fi
  220. if test -f querystream.awk
  221. then
  222. cp querystream.awk $INSTALLDIR/share/plait
  223. fi
  224. if test -f postprocess.awk
  225. then
  226. cp postprocess.awk $INSTALLDIR/share/plait
  227. fi
  228. if test -f device.awk
  229. then
  230. cp device.awk $INSTALLDIR/share/plait
  231. fi
  232. if test -f interactive.awk
  233. then
  234. cp interactive.awk $INSTALLDIR/share/plait
  235. fi
  236. if test -f interactivestream.awk
  237. then
  238. cp interactivestream.awk $INSTALLDIR/share/plait
  239. fi
  240. if test -f robots.awk
  241. then
  242. cp robots.awk $INSTALLDIR/share/plait
  243. fi
  244. if test -f xspf.awk
  245. then
  246. cp xspf.awk $INSTALLDIR/share/plait
  247. fi
  248. if test -f treecopy.awk
  249. then
  250. cp treecopy.awk $INSTALLDIR/share/plait
  251. fi
  252. if test -f coverart.awk
  253. then
  254. cp coverart.awk $INSTALLDIR/share/plait
  255. fi
  256. if test -f playlist.html
  257. then
  258. cp playlist.html $INSTALLDIR/share/plait
  259. fi
  260. if test -f README
  261. then
  262. cp README $INSTALLDIR/share/doc/plait
  263. fi
  264. if test -f README.plaiter
  265. then
  266. cp README.plaiter $INSTALLDIR/share/doc/plait
  267. fi
  268. if test -f COPYING
  269. then
  270. cp COPYING $INSTALLDIR/share/doc/plait
  271. fi
  272. if test -f INSTALL
  273. then
  274. cp INSTALL $INSTALLDIR/share/doc/plait
  275. fi
  276. # always force rewrite of scripts
  277. rm -f "$HOME/.plait/commands/itunes-cmd-play.js"
  278. rm -f "$HOME/.plait/commands/cmd-play.vbs"
  279. # clean up junk from old versions of plait
  280. rm -fr /etc/plait
  281. echo "1.6.2" > $INSTALLDIR/share/plait/version
  282. }
  283. uninstall ()
  284. {
  285. echo Uninstall "plait"\? Type "yes" to continue, "no" to cancel.
  286. read yes
  287. if test "-$yes-" = "-yes-"
  288. then
  289. rm -fr $INSTALLDIR/share/plait
  290. if test $? != 0
  291. then
  292. echo You need root privileges to uninstall, try su or sudo
  293. exit 1
  294. fi
  295. rm -fr $INSTALLDIR/share/doc/plait
  296. rm -f $INSTALLDIR/share/man/man1/plait.1
  297. rm -f $INSTALLDIR/share/man/man1/plaiter.1
  298. rm -f $INSTALLDIR/bin/plait
  299. rm -f $INSTALLDIR/bin/plait-s3
  300. rm -f $INSTALLDIR/bin/plaiter
  301. echo Uninstall complete.
  302. else
  303. echo Uninstall cancelled
  304. fi
  305. }
  306. docache ()
  307. {
  308. echo 1>&2 Caching music directory $MUSICDIR/$SUBDIR
  309. if test "-$SUBDIR-" = "--"
  310. then
  311. rm -f "$HOME/.plait/$CACHE"
  312. dir="$MUSICDIR"
  313. else
  314. touch "$HOME/.plait/$CACHE"
  315. dir="$MUSICDIR/$SUBDIR"
  316. cat "$HOME/.plait/$CACHE" | grep -v "$dir" > "$HOME/.plait/cache2"
  317. mv "$HOME/.plait/cache2" "$HOME/.plait/$CACHE"
  318. fi
  319. if test -d "$dir"
  320. then
  321. eval "find \"$dir\" -follow -type f" >> "$HOME/.plait/$CACHE"
  322. sort "$HOME/.plait/$CACHE" | uniq > "$HOME/.plait/$CACHE-tmp"
  323. mv "$HOME/.plait/$CACHE-tmp" "$HOME/.plait/$CACHE"
  324. else
  325. echo 1>&2 The directory $dir was not found
  326. fi
  327. touch "$HOME/.plait/$CACHE"
  328. }
  329. querylibrary ()
  330. {
  331. rm -f "$HOME/.plait/mixfile"
  332. OUTMIXFILE=mix0
  333. QUERY=""
  334. NOTQUERY=""
  335. bar=""
  336. awkhints=""
  337. colons=""
  338. while test $# -gt 0
  339. do
  340. if test "-$1-" = "-as-" && ! test "-$2-" = "--" && test "-$bar-" = "-|-"
  341. then
  342. OUTMIXFILE=`echo "$2" | sed "s/ /-/g"`
  343. shift; shift
  344. elif test "-$1-" = "-not-" && ! test "-$2-" = "--" && test "-$bar-" = "-|-"
  345. then
  346. NOTQUERY="$NOTQUERY | grep -Eiv \"$2\""
  347. echo "not \"$2\"" >> "$HOME/.plait/mixfile"
  348. shift; shift
  349. else
  350. if test $MIX = 1 || test "-$colons-" = "--"
  351. then
  352. awkhints="${awkhints}${colons}$1"
  353. colons="::"
  354. fi
  355. if test $MIX = 0
  356. then
  357. QUERY="$QUERY | grep -Ei \"$1\""
  358. else
  359. QUERY="${QUERY}${bar}$1"
  360. fi
  361. echo "\"$1\"" >> "$HOME/.plait/mixfile"
  362. shift
  363. fi
  364. bar="|"
  365. done
  366. if test $MIX = 1
  367. then
  368. QUERY="| grep -Ei \"$QUERY\""
  369. fi
  370. STRIPDIR="| sed \"s:$MUSICDIR::\""
  371. ADDDIR="| sed \"s:^:$MUSICDIR:\""
  372. eval cat "$HOME/.plait/$CACHE" $STRIPDIR $QUERY $NOTQUERY $ADDDIR > "$HOME/.plait/playlist.m3u"
  373. if test -e "$HOME/.plait/mixfile"
  374. then
  375. sort "$HOME/.plait/mixfile" | uniq > "$HOME/.plait/mixfiles/$OUTMIXFILE"
  376. fi
  377. # select device-appropriate tracks
  378. awk -f $INSTALLDIR/share/plait/device.awk types="$DEVICE" \
  379. "$HOME/.plait/playlist.m3u" > "$HOME/.plait/playlist0.m3u"
  380. # optionally process the list interactively
  381. if test $INTERACTIVE = 1
  382. then
  383. awk -f $INSTALLDIR/share/plait/interactive.awk prefix="$MUSICDIR/" levelsep="$LEVELSEP" \
  384. "$HOME/.plait/playlist0.m3u" > "$HOME/.plait/playlist.m3u"
  385. mv "$HOME/.plait/playlist.m3u" "$HOME/.plait/playlist0.m3u"
  386. fi
  387. # balance and sort
  388. if test $ORDER = "sort"
  389. then
  390. awk -f $INSTALLDIR/share/plait/postprocess.awk hints="$awkhints" order=$ORDER tracks=$TRACKS \
  391. "$HOME/.plait/playlist0.m3u" state=2 "$HOME/.plait/playlist0.m3u" \
  392. > "$HOME/.plait/playlist.m3u"
  393. else
  394. awk -f $INSTALLDIR/share/plait/postprocess.awk hints="$awkhints" order=$ORDER tracks=$TRACKS \
  395. "$HOME/.plait/playlist0.m3u" state=2 "$HOME/.plait/playlist0.m3u" \
  396. | sort -n | cut -f "2-" > "$HOME/.plait/playlist.m3u"
  397. fi
  398. }
  399. querystream ()
  400. {
  401. wget >/dev/null 2>&1 -O "$HOME/.plait/robots.txt" -r \
  402. -U "Plait \(http://plait.sourceforge.net/bot.html\)" \
  403. "http://classic.shoutcast.com/robots.txt"
  404. if test -f "$HOME/.plait/robots.txt"
  405. then
  406. ok=`cat "$HOME/.plait/robots.txt" | awk -f $INSTALLDIR/share/plait/robots.awk`
  407. if test $ok = "NOT OK"
  408. then
  409. echo 1>&2 "The Plait bot was excluded by Shoutcast's robots.txt file, exiting"
  410. exit 1
  411. fi
  412. fi
  413. if test $MIX = 0
  414. then
  415. wget >/dev/null 2>&1 -O "$HOME/.plait/shoutcast.html" \
  416. -U "Plait (http://plait.sourceforge.net/bot.html)" \
  417. "http://classic.shoutcast.com/directory/?s=$HINT1&numresult=100&orderby=listeners"
  418. else
  419. rm -f "$HOME/.plait/shoutcast.html"
  420. fi
  421. awkhints=""
  422. space=""
  423. while test $# -gt 0
  424. do
  425. awkhints="${awkhints}${space}`echo "$1" | sed "s/ /_/g"`"
  426. space=" "
  427. if test $MIX = 1
  428. then
  429. if test "-$1-" = "-not-" && ! test "-$2-" = "--"
  430. then
  431. shift
  432. awkhints="${awkhints}${space}`echo "$1" | sed "s/ /_/g"`"
  433. else
  434. wget >/dev/null 2>&1 -O "$HOME/.plait/shoutcast2.html" \
  435. -U "Plait (http://plait.sourceforge.net/bot.html)" \
  436. "http://classic.shoutcast.com/directory/?s=$1&numresult=100&orderby=listeners"
  437. cat "$HOME/.plait/shoutcast2.html" >> "$HOME/.plait/shoutcast.html"
  438. fi
  439. fi
  440. shift
  441. done
  442. awk -f $INSTALLDIR/share/plait/querystream.awk hints="$awkhints" mix=$MIX interactive=$INTERACTIVE \
  443. "$HOME/.plait/shoutcast.html" > "$HOME/.plait/playlist.m3u"
  444. # optionally process the list interactively
  445. if test $INTERACTIVE = 1
  446. then
  447. awk -f $INSTALLDIR/share/plait/interactivestream.awk \
  448. "$HOME/.plait/playlist.m3u" > "$HOME/.plait/playlist0.m3u"
  449. mv "$HOME/.plait/playlist0.m3u" "$HOME/.plait/playlist.m3u"
  450. fi
  451. if test $ORDER = "random"
  452. then
  453. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  454. cat "$HOME/.plait/playlist.m3u" | awk 'BEGIN{srand()} {print rand() "\t" $0}' | \
  455. sort -n | cut -f "2-" > $tmpfile
  456. mv $tmpfile "$HOME/.plait/playlist.m3u"
  457. fi
  458. # trim the playlist if it has not been edited interactively
  459. if test $INTERACTIVE = 0
  460. then
  461. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  462. head -n $TRACKS > $tmpfile "$HOME/.plait/playlist.m3u"
  463. mv $tmpfile "$HOME/.plait/playlist.m3u"
  464. fi
  465. }
  466. listmixfiles ()
  467. {
  468. echo Mixfiles available:
  469. mkdir -p "$HOME/.plait/mixfiles"
  470. rm -f "$HOME/.plait/mixfiles/*~"
  471. ls "$HOME/.plait/mixfiles"
  472. }
  473. prefetch_stream_urls ()
  474. {
  475. rm -f "$HOME/.plait/playlists.pls"
  476. cat "$HOME/.plait/playlist.m3u" | grep -i "^http" | awk \
  477. '{ print "wget >/dev/null 2>&1 -O \"$HOME/.plait/playlist.pls\" \"" \
  478. $0 "\"; cat \"$HOME/.plait/playlist.pls\" >> \"$HOME/.plait/playlists.pls\""}' \
  479. > "$HOME/.plait/xme"
  480. . "$HOME/.plait/xme"
  481. # make sure there is a trailing slash, for mpg321:
  482. cat "$HOME/.plait/playlists.pls" | awk 'BEGIN {FS="="} \
  483. /File1/ {if ($2 ~ /\/$/) print $2; else print $2 "/"}' \
  484. > "$HOME/.plait/playlist2.m3u"
  485. }
  486. translate_to_windows_file_paths_old ()
  487. {
  488. # translate to windows file paths. cygpath is very slow, so
  489. # run it just once for the top two directories (enough to
  490. # cover /cygdrive/c), then do a simple replace for the rest of
  491. # each file path
  492. root="`head -n 1 \"$HOME/.plait/playlist.m3u\" | awk \
  493. '{match($0, "/*[^/]*/[^/]*/"); print substr($0, RSTART, RLENGTH)}'`"
  494. root="`cygpath -am $root`"
  495. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  496. cat "$HOME/.plait/playlist.m3u" | awk > $tmpfile -v r="$root" \
  497. 'BEGIN { if (r !~ /\/$/) r = r "/"; gsub (/\//, "\\", r) } \
  498. { s = $0; sub ("^/*[^/]*/[^/]*/", "", s); gsub (/\//, "\\", s); print r s}'
  499. mv $tmpfile "$HOME/.plait/playlist2.m3u"
  500. }
  501. translate_to_windows_file_paths ()
  502. {
  503. if test $SLOW_PATH_TRANSLATION = 1
  504. then
  505. cat "$HOME/.plait/playlist.m3u" | xargs > "$HOME/.plait/playlist2.m3u" -i cygpath -am "{}"
  506. else
  507. root="`cygpath -am \"$MUSICDIR\"`"
  508. tmpfile="$(mktemp /tmp/plait.XXXXXX)"
  509. cat "$HOME/.plait/playlist.m3u" | awk > $tmpfile -v r="$root" -v d="$MUSICDIR" \
  510. 'BEGIN {if (r !~ /\/$/) r = r "/"; gsub (/\//, "\\", r)} \
  511. {s = $0; sub (d "/", "", s); gsub (/\//, "\\", s); print r s}'
  512. mv $tmpfile "$HOME/.plait/playlist2.m3u"
  513. fi
  514. }
  515. prefetch_or_copy ()
  516. {
  517. hasurl=`grep -ci http "$HOME/.plait/playlist.m3u"`
  518. if test $hasurl -gt 0
  519. then
  520. prefetch_stream_urls
  521. else
  522. cp "$HOME/.plait/playlist.m3u" "$HOME/.plait/playlist2.m3u"
  523. fi
  524. }
  525. prefetch_or_translate ()
  526. {
  527. hasurl=`grep -ci http "$HOME/.plait/playlist.m3u"`
  528. if test $hasurl = 0
  529. then
  530. translate_to_windows_file_paths
  531. else
  532. prefetch_stream_urls
  533. fi
  534. }
  535. translate_or_copy ()
  536. {
  537. hasurl=`grep -ci http "$HOME/.plait/playlist.m3u"`
  538. if test $hasurl = 0
  539. then
  540. translate_to_windows_file_paths
  541. else
  542. cp "$HOME/.plait/playlist.m3u" "$HOME/.plait/playlist2.m3u"
  543. fi
  544. }
  545. CYGWIN=`uname -s | grep -ic CYGWIN`
  546. DARWIN=`uname -s | grep -ic Darwin`
  547. LINUX=`uname -s | grep -ic Linux`
  548. INSTALLDIR="%INSTALLDIR%"
  549. # file types and devices
  550. TYPES=".mp3 .wav .flac .aif .aiff .ogg"
  551. compact="mp3 MP3"
  552. medium="mp3 MP3 ogg OGG wav WAV flac FLAC aif AIF aiff AIFF"
  553. hifi="wav WAV flac FLAC aif AIF aiff AIFF mp3 MP3 ogg OGG"
  554. DEVICE="$hifi"
  555. SETDEVICE=""
  556. # option flags
  557. SHOW=0
  558. QUEUE=0
  559. ORDER="sort"
  560. SETORDER=""
  561. STREAM=0
  562. CONFIG=config
  563. CACHE=cache
  564. DOCACHE=0
  565. MIX=0
  566. TRACKS=-4
  567. SETTRACKS=-5
  568. MIXFILES=""
  569. DOMIXFILE=0
  570. DOLISTMIXFILES=0
  571. HINTS=""
  572. HINT1=""
  573. SUBDIR=""
  574. COMMAND=""
  575. SLOW_PATH_TRANSLATION=0
  576. INTERACTIVE=0
  577. LEVELSEP="/"
  578. SETPLATFORM=""
  579. ARTISTIDX=1
  580. ALBUMIDX=2
  581. SONGIDX=3
  582. BASEURL=""
  583. COVERART=0
  584. SETCOVERART=-1
  585. while test $# -gt 0
  586. do
  587. case "$1" in
  588. --install)
  589. install "$2"
  590. exit 0
  591. ;;
  592. --uninstall)
  593. uninstall
  594. exit 0
  595. ;;
  596. --list|-l)
  597. SHOW=1
  598. shift
  599. ;;
  600. --queue|-q)
  601. QUEUE=1
  602. shift
  603. ;;
  604. --random|-r)
  605. SETORDER="random"
  606. shift
  607. ;;
  608. --stripe)
  609. SETORDER="stripe"
  610. shift
  611. ;;
  612. --stripe2)
  613. SETORDER="stripe2"
  614. shift
  615. ;;
  616. --sort)
  617. SETORDER="sort"
  618. shift
  619. ;;
  620. --fade)
  621. SETORDER="fade"
  622. shift
  623. ;;
  624. --group)
  625. SETORDER="group"
  626. shift
  627. ;;
  628. --cache|-c)
  629. DOCACHE=1
  630. if ! test "-$2-" = "--"
  631. then
  632. SUBDIR="$2"
  633. shift
  634. fi
  635. shift
  636. ;;
  637. --coverart)
  638. if ! test "-$2-" = "--"
  639. then
  640. test 2> /dev/null $2 -gt -1
  641. if test $? -ne 0
  642. then
  643. echo 1>&2 Bad value for --coverart, ignoring $1
  644. else
  645. SETCOVERART=$2
  646. shift
  647. fi
  648. else
  649. echo 1>&2 No value for --coverart, ignoring
  650. fi
  651. shift
  652. ;;
  653. --stream|-s)
  654. STREAM=1
  655. TRACKS=10
  656. shift
  657. ;;
  658. --guest|-g)
  659. if ! test "-$2-" = "--"
  660. then
  661. prefix=`echo "$2" | sed "s/ /-/g"`
  662. CONFIG="$prefix-$CONFIG"
  663. CACHE="$prefix-$CACHE"
  664. shift
  665. else
  666. echo 1>&2 No guest name provided, ignoring $1
  667. fi
  668. shift
  669. ;;
  670. --device|-d)
  671. if ! test "-$2-" = "--"
  672. then
  673. SETDEVICE="$2"
  674. shift
  675. else
  676. echo 1>&2 No device name provided, ignoring $1
  677. fi
  678. shift
  679. ;;
  680. --platform)
  681. if ! test "-$2-" = "--"
  682. then
  683. SETPLATFORM="$2"
  684. shift
  685. else
  686. echo 1>&2 No platform provided, ignoring $1
  687. fi
  688. shift
  689. ;;
  690. --mix|-m)
  691. MIX=1
  692. shift
  693. ;;
  694. --tracks|-t)
  695. if ! test "-$2-" = "--"
  696. then
  697. if test $2 = "avg"
  698. then
  699. SETTRACKS=-1
  700. elif test $2 = "min"
  701. then
  702. SETTRACKS=-2
  703. elif test $2 = "max"
  704. then
  705. SETTRACKS=-3
  706. elif test $2 = "all"
  707. then
  708. SETTRACKS=-4
  709. else
  710. test 2> /dev/null $2 -gt -1
  711. if test $? -ne 0
  712. then
  713. echo 1>&2 Bad track count, ignoring $1
  714. else
  715. SETTRACKS=$2
  716. fi
  717. fi
  718. shift
  719. else
  720. echo 1>&2 No track count provided, ignoring $1
  721. fi
  722. shift
  723. ;;
  724. --mixfile|-f)
  725. if ! test "-$2-" = "--"
  726. then
  727. MIXFILES="$MIXFILES `echo "$2" | sed "s/ /-/g"`"
  728. DOMIXFILE=1
  729. MIX=1
  730. shift
  731. else
  732. echo 1>&2 No mix file name provided, ignoring $1
  733. fi
  734. shift
  735. ;;
  736. --play)
  737. COMMAND=play
  738. shift
  739. ;;
  740. --pause)
  741. COMMAND=pause
  742. shift
  743. ;;
  744. --stop)
  745. COMMAND=stop
  746. shift
  747. ;;
  748. --next)
  749. COMMAND=next
  750. shift
  751. ;;
  752. --prev)
  753. COMMAND=prev
  754. shift
  755. ;;
  756. --interactive|-i)
  757. INTERACTIVE=1
  758. shift
  759. ;;
  760. --dump)
  761. DOLISTMIXFILES=1
  762. shift
  763. ;;
  764. --help)
  765. usage
  766. exit 0
  767. ;;
  768. --version)
  769. version
  770. exit 0
  771. ;;
  772. -*)
  773. echo 1>&2 Ignoring unknown option $1
  774. shift
  775. ;;
  776. *)
  777. if test "-$HINT1-" = "--"
  778. then
  779. HINT1="$1"
  780. fi
  781. HINTS="$HINTS \"$1\""
  782. shift
  783. ;;
  784. esac
  785. done
  786. mkdir -p "$HOME/.plait/xspf"
  787. if test -f "$HOME/.plait/$CONFIG"
  788. then
  789. . "$HOME/.plait/$CONFIG"
  790. else
  791. echo "INSTALLDIR=$INSTALLDIR" > "$HOME/.plait/$CONFIG"
  792. fi
  793. if test "-$MUSICDIR-" = "--"
  794. then
  795. echo 1>&2 Please enter the directory where your music is stored.
  796. while test 1 -gt 0
  797. do
  798. read a
  799. if test -d "$a"
  800. then
  801. MUSICDIR="$a"
  802. echo >> "$HOME/.plait/$CONFIG" "MUSICDIR=\"$a\""
  803. echo 1>&2 Configuration complete
  804. break
  805. else
  806. echo 1>&2 Directory $a not found, try again
  807. fi
  808. done
  809. fi
  810. if ! test "-$SETPLATFORM-" = "--"
  811. then
  812. PLATFORM=$SETPLATFORM
  813. fi
  814. if test "-$PLATFORM-" = "--"
  815. then
  816. if test $CYGWIN -ge 1
  817. then
  818. PLATFORM=cygwin-winamp
  819. elif test $DARWIN -ge 1
  820. then
  821. PLATFORM=osx-itunes
  822. else
  823. xmms=`which xmms 2>/dev/null`
  824. if ! test "-$xmms-" = "--"
  825. then
  826. PLATFORM=unix-xmms
  827. else
  828. bmp=`which beep-media-player 2>/dev/null`
  829. if ! test "-$bmp-" = "--"
  830. then
  831. PLATFORM=unix-beep-media-player
  832. else
  833. audacious=`which audacious 2>/dev/null`
  834. if ! test "-$audacious-" = "--"
  835. then
  836. PLATFORM=unix-audacious
  837. else
  838. amarok=`which amarok 2>/dev/null`
  839. if ! test "-$amarok-" = "--"
  840. then
  841. PLATFORM=unix-amarok
  842. else
  843. mpc=`which mpc 2>/dev/null`
  844. if ! test "-${mpc}-" = "--"
  845. then
  846. PLATFORM=unix-mpc
  847. else
  848. mpg=`which mpg123 2>/dev/null`
  849. ogg=`which ogg123 2>/dev/null`
  850. mpg3=`which mpg321 2>/dev/null`
  851. if ! test "-${mpg}${ogg}${mpg3}-" = "--"
  852. then
  853. PLATFORM=unix-plaiter
  854. else
  855. PLATFORM=any-listonly
  856. echo 1>&2 No player is selected. Edit $HOME/.plait/config to select one.
  857. fi
  858. fi
  859. fi
  860. fi
  861. fi
  862. fi
  863. fi
  864. echo 1>&2 Platform $PLATFORM selected.
  865. echo >> "$HOME/.plait/$CONFIG" "PLATFORM=$PLATFORM"
  866. fi
  867. export ESPEAKER
  868. MUSICDIR=`echo "$MUSICDIR" | sed "s:/$::"`
  869. mkdir -p "$HOME/.plait/mixfiles"
  870. if test $SETTRACKS -ge -4
  871. then
  872. TRACKS=$SETTRACKS
  873. fi
  874. if ! test "-$SETDEVICE-" = "--"
  875. then
  876. eval DEVICE="\$$SETDEVICE"
  877. fi
  878. if ! test "-$SETORDER-" = "--"
  879. then
  880. ORDER=$SETORDER
  881. fi
  882. if test $SETCOVERART -ge 0
  883. then
  884. COVERART=$SETCOVERART
  885. fi
  886. if test $STREAM = 1 && test $DOMIXFILE = 1
  887. then
  888. STREAM=0
  889. echo 1>&2 Mix file selected, ignoring --stream
  890. fi
  891. if test $STREAM = 1 && test $TRACKS -lt 0
  892. then
  893. TRACKS=10
  894. echo 1>&2 "Stream query selected, ignoring symbolic track count"
  895. fi
  896. #if test $STREAM = 1 && test $INTERACTIVE = 1
  897. #then
  898. # INTERACTIVE=0
  899. # echo 1>&2 "Stream query selected, disabling interactive mode"
  900. #fi
  901. if test $DOCACHE -eq 1
  902. then
  903. docache
  904. exit 0
  905. fi
  906. if test $DOLISTMIXFILES -eq 1
  907. then
  908. listmixfiles
  909. exit 0
  910. fi
  911. if test "$PLATFORM" = "cygwin-winamp"
  912. then
  913. create_winamp_scripts
  914. fi
  915. if test "$PLATFORM" = "cygwin-itunes"
  916. then
  917. create_itunes_scripts
  918. fi
  919. # if there is a command, forward it to the player and quit
  920. if ! test "-$COMMAND-" = "--"
  921. then
  922. case $PLATFORM in
  923. cygwin-winamp)
  924. cygstart "$HOME/.plait/commands/cmd-$COMMAND.vbs"
  925. ;;
  926. cygwin-itunes)
  927. cygstart "$HOME/.plait/commands/itunes-cmd-$COMMAND.js"
  928. ;;
  929. unix-mpc)
  930. mpc $COMMAND > /dev/null
  931. ;;
  932. linux-plaiter|unix-plaiter)
  933. plaiter --$COMMAND
  934. ;;
  935. osx-itunes)
  936. case $COMMAND in
  937. play)
  938. osascript -e 'tell application "iTunes" to play' > /dev/null 2>&1
  939. ;;
  940. pause)
  941. osascript -e 'tell application "iTunes" to pause' > /dev/null 2>&1
  942. ;;
  943. stop)
  944. osascript -e 'tell application "iTunes" to stop' > /dev/null 2>&1
  945. ;;
  946. next)
  947. osascript -e 'tell application "iTunes" to next track' > /dev/null 2>&1
  948. ;;
  949. prev)
  950. osascript -e 'tell application "iTunes" to previous track' > /dev/null 2>&1
  951. ;;
  952. esac
  953. ;;
  954. linux-xmms|unix-xmms|unix_xmms)
  955. case $COMMAND in
  956. play)
  957. xmms-shell -e play > /dev/null 2>&1
  958. ;;
  959. pause)
  960. xmms-shell -e pause > /dev/null 2>&1
  961. ;;
  962. stop)
  963. xmms-shell -e stop > /dev/null 2>&1
  964. ;;
  965. next)
  966. xmms-shell -e next > /dev/null 2>&1
  967. ;;
  968. prev)
  969. xmms-shell -e previous > /dev/null 2>&1
  970. ;;
  971. esac
  972. if ! test $? = 0
  973. then
  974. echo 1>&2 Platform $PLATFORM requires the package xmms-shell to send command $COMMAND
  975. fi
  976. ;;
  977. linux-beep-media-player|unix-beep-media-player)
  978. case $COMMAND in
  979. play)
  980. beep-media-player --play > /dev/null 2>&1
  981. ;;
  982. pause)
  983. beep-media-player --play-pause > /dev/null 2>&1
  984. ;;
  985. stop)
  986. beep-media-player --stop > /dev/null 2>&1
  987. ;;
  988. next)
  989. beep-media-player --fwd > /dev/null 2>&1
  990. ;;
  991. prev)
  992. beep-media-player --rew > /dev/null 2>&1
  993. ;;
  994. esac
  995. ;;
  996. linux-audacious|unix-audacious)
  997. case $COMMAND in
  998. play)
  999. audacious --play > /dev/null 2>&1
  1000. ;;
  1001. pause)
  1002. audacious --play-pause > /dev/null 2>&1
  1003. ;;
  1004. stop)
  1005. audacious --stop > /dev/null 2>&1
  1006. ;;
  1007. next)
  1008. audacious --fwd > /dev/null 2>&1
  1009. ;;
  1010. prev)
  1011. audacious --rew > /dev/null 2>&1
  1012. ;;
  1013. esac
  1014. ;;
  1015. linux-amarok|unix-amarok)
  1016. case $COMMAND in
  1017. play)
  1018. amarok --play > /dev/null 2>&1
  1019. ;;
  1020. pause)
  1021. amarok --pause > /dev/null 2>&1
  1022. ;;
  1023. stop)
  1024. amarok --stop > /dev/null 2>&1
  1025. ;;
  1026. next)
  1027. amarok --next > /dev/null 2>&1
  1028. ;;
  1029. prev)
  1030. amarok --previous > /dev/null 2>&1
  1031. ;;
  1032. esac
  1033. ;;
  1034. linux-mplayer|unix-mplayer)
  1035. case $COMMAND in
  1036. stop)
  1037. killall mplayer > /dev/null 2>&1
  1038. ;;
  1039. esac
  1040. ;;
  1041. *)
  1042. echo 1>&2 Platform $PLATFORM does not support command $COMMAND
  1043. ;;
  1044. esac
  1045. exit 0
  1046. fi
  1047. if ! test "-$HINTS-" = "--" || test $DOMIXFILE = 1
  1048. then
  1049. if test $STREAM = 0
  1050. then
  1051. if ! test -f "$HOME/.plait/$CACHE"
  1052. then
  1053. docache
  1054. fi
  1055. if test $DOMIXFILE = 1
  1056. then
  1057. LISTNAME="`echo \"$MIXFILES\" | sed \"s/^ //\"` tracks"
  1058. else
  1059. LISTNAME="$HINT1 tracks"
  1060. fi
  1061. echo "LISTNAME=\"$LISTNAME\"" > "$HOME/.plait/listname"
  1062. if test $DOMIXFILE -eq 0
  1063. then
  1064. eval querylibrary $HINTS
  1065. else
  1066. filehints=""
  1067. for MIXFILE in $MIXFILES
  1068. do
  1069. if test -e "$HOME/.plait/mixfiles/$MIXFILE"
  1070. then
  1071. filehints="$filehints `cat "$HOME/.plait/mixfiles/$MIXFILE" | awk '{printf "%s ", $0}'`"
  1072. else
  1073. echo 1>&2 Mixfile $MIXFILE not found
  1074. fi
  1075. done
  1076. if test "-$HINTS-" = "--" && test "-$filehints-" = "--"
  1077. then
  1078. echo 1>&2 No hints, exiting
  1079. exit 0
  1080. else
  1081. eval querylibrary $filehints $HINTS
  1082. fi
  1083. fi
  1084. else
  1085. LISTNAME="$HINT1 streams"
  1086. echo "LISTNAME=\"$LISTNAME\"" > "$HOME/.plait/listname"
  1087. eval querystream $HINTS
  1088. fi
  1089. else
  1090. # make sure there's at least an empty playlist
  1091. touch "$HOME/.plait/playlist.m3u"
  1092. fi
  1093. if test "-$LISTNAME-" = "--"
  1094. then
  1095. if test -f "$HOME/.plait/listname"
  1096. then
  1097. . "$HOME/.plait/listname"
  1098. fi
  1099. if test "-$LISTNAME-" = "--"
  1100. then
  1101. if test $STREAM = 0
  1102. then
  1103. LISTNAME="plait tracks"
  1104. else
  1105. LISTNAME="plait streams"
  1106. fi
  1107. echo "LISTNAME=\"$LISTNAME\"" > "$HOME/.plait/listname"
  1108. fi
  1109. fi
  1110. if test $SHOW = 1
  1111. then
  1112. cat "$HOME/.plait/playlist.m3u"
  1113. else
  1114. cuts=`cat "$HOME/.plait/playlist.m3u" | wc -l`
  1115. if test $cuts = 0
  1116. then
  1117. echo 1>&2 Playlist empty, try --list or --help
  1118. else
  1119. if ! test -d "$MUSICDIR" && test $STREAM = 0
  1120. then
  1121. echo 1>&2 The music directory is unavailable, exiting
  1122. exit 1
  1123. fi
  1124. case $PLATFORM in
  1125. cygwin-winamp)
  1126. translate_or_copy
  1127. if test $QUEUE = 0
  1128. then
  1129. cygstart "$HOME/.plait/commands/play.vbs"
  1130. else
  1131. cygstart "$HOME/.plait/commands/queue.vbs"
  1132. fi
  1133. ;;
  1134. cygwin-itunes)
  1135. prefetch_or_translate
  1136. ln2=`echo "$LISTNAME" | sed "s:/:-:g"`
  1137. if test $QUEUE = 0
  1138. then
  1139. sed "s/%PL%/$ln2/g" "$HOME/.plait/commands/itunes-play.js" > "$HOME/.plait/commands/itunes-play-2.js"
  1140. cygstart "$HOME/.plait/commands/itunes-play-2.js"
  1141. else
  1142. sed "s/%PL%/$ln2/g" "$HOME/.plait/commands/itunes-queue.js" > "$HOME/.plait/commands/itunes-queue-2.js"
  1143. cygstart "$HOME/.plait/commands/itunes-queue-2.js"
  1144. fi
  1145. ;;
  1146. osx-itunes)
  1147. if test $QUEUE -eq 1
  1148. then
  1149. echo > "$HOME/.plait/play.osa" "tell application \"iTunes\""
  1150. echo >> "$HOME/.plait/play.osa" "if not (exists user playlist \"$LISTNAME\") then"
  1151. echo >> "$HOME/.plait/play.osa" "make user playlist with properties {name:\"$LISTNAME\"}"
  1152. echo >> "$HOME/.plait/play.osa" "end if"
  1153. else
  1154. echo > "$HOME/.plait/play.osa" "tell application \"iTunes\""
  1155. echo >> "$HOME/.plait/play.osa" "if (exists user playlist \"$LISTNAME\") then"
  1156. echo >> "$HOME/.plait/play.osa" "delete user playlist \"$LISTNAME\""
  1157. echo >> "$HOME/.plait/play.osa" "end if"
  1158. echo >> "$HOME/.plait/play.osa" "make user playlist with properties {name:\"$LISTNAME\"}"
  1159. fi
  1160. hasurl=`grep -ci http "$HOME/.plait/playlist.m3u"`
  1161. if test $hasurl = 0
  1162. then
  1163. cat "$HOME/.plait/playlist.m3u" | awk >> "$HOME/.plait/play.osa" -v pl="$LISTNAME" \
  1164. '{print "set f to \"" $0 "\""; \
  1165. print "try"; \
  1166. print "set f2 to (POSIX file f) as string"; \
  1167. print "add f2 to playlist \"" pl "\"";
  1168. print "end try"}'
  1169. else
  1170. prefetch_stream_urls
  1171. pl="$HOME/.plait/playlist2.m3u"
  1172. echo >> "$HOME/.plait/play.osa" "set f to \"$pl\""
  1173. echo >> "$HOME/.plait/play.osa" "set f2 to (POSIX file f) as string"
  1174. echo >> "$HOME/.plait/play.osa" "add f2 to playlist \"$LISTNAME\""
  1175. fi
  1176. if test $QUEUE = 0
  1177. then
  1178. echo >> "$HOME/.plait/play.osa" "play track 1 of playlist \"$LISTNAME\""
  1179. fi
  1180. echo >> "$HOME/.plait/play.osa" "end tell"
  1181. osascript > /dev/null 2>&1 "$HOME/.plait/play.osa"
  1182. ;;
  1183. linux-xmms|unix-xmms|unix_xmms)
  1184. prefetch_or_copy
  1185. if test $QUEUE -eq 0
  1186. then
  1187. xmms "$HOME/.plait/playlist2.m3u" &
  1188. else
  1189. xmms --enqueue "$HOME/.plait/playlist2.m3u" &
  1190. fi
  1191. ;;
  1192. linux-mpg321|unix-mpg321)
  1193. prefetch_or_copy
  1194. killall > /dev/null 2>&1 mpg321
  1195. mpg321 -q --list "$HOME/.plait/playlist2.m3u" &
  1196. ;;
  1197. linux-mpg321-esd|unix-mpg321-esd)
  1198. prefetch_or_copy
  1199. killall > /dev/null 2>&1 mpg321
  1200. if ! test "-$ESPEAKER-" = "--"
  1201. then
  1202. SERVEROPT="-a $ESPEAKER"
  1203. fi
  1204. mpg321 -q -o esd $SERVEROPT --list "$HOME/.plait/playlist2.m3u" &
  1205. ;;
  1206. linux-mpg123|unix-mpg123)
  1207. prefetch_or_copy
  1208. killall > /dev/null 2>&1 mpg123
  1209. mpg123 -q --list "$HOME/.plait/playlist2.m3u" &
  1210. ;;
  1211. linux-ogg123|unix-ogg123)
  1212. prefetch_or_copy
  1213. killall > /dev/null 2>&1 ogg123
  1214. ogg123 -q --list "$HOME/.plait/playlist2.m3u" &
  1215. ;;
  1216. linux-ogg123-esd|unix-ogg123-esd)
  1217. prefetch_or_copy
  1218. killall > /dev/null 2>&1 ogg123
  1219. ogg123 -d esd -q --list "$HOME/.plait/playlist2.m3u" &
  1220. ;;
  1221. linux-mpg123-esd|unix-mpg123-esd)
  1222. prefetch_or_copy
  1223. killall > /dev/null 2>&1 mpg123-esd
  1224. mpg123-esd -q --list "$HOME/.plait/playlist2.m3u" &
  1225. ;;
  1226. unix-mpc)
  1227. prefetch_or_copy
  1228. if test $QUEUE = 0
  1229. then
  1230. mpc clear > /dev/null
  1231. fi
  1232. MPDLIBRARY="$MUSICDIR"
  1233. while read file
  1234. do
  1235. # chop off absolute path
  1236. file=`echo $file | sed -e "s#$MPDLIBRARY/\(.*\)#\1#"`
  1237. mpc add "${file}" > /dev/null
  1238. done < "$HOME/.plait/playlist2.m3u"
  1239. if test $QUEUE = 0
  1240. then
  1241. mpc play
  1242. fi
  1243. ;;
  1244. linux-plaiter|unix-plaiter)
  1245. prefetch_or_copy
  1246. if test $QUEUE = 0
  1247. then
  1248. plaiter "$HOME/.plait/playlist2.m3u" &
  1249. else
  1250. plaiter --queue "$HOME/.plait/playlist2.m3u" &
  1251. fi
  1252. ;;
  1253. linux-beep-media-player|unix-beep-media-player)
  1254. prefetch_or_copy
  1255. if test $QUEUE = 0
  1256. then
  1257. beep-media-player "$HOME/.plait/playlist2.m3u" &
  1258. else
  1259. beep-media-player --enqueue "$HOME/.plait/playlist2.m3u" &
  1260. fi
  1261. ;;
  1262. linux-audacious|unix-audacious)
  1263. prefetch_or_copy
  1264. if test $QUEUE = 0
  1265. then
  1266. # audacious will print stuff to the console
  1267. audacious "$HOME/.plait/playlist2.m3u" >/dev/null 2>&1 &
  1268. else
  1269. audacious --enqueue "$HOME/.plait/playlist2.m3u" >/dev/null 2>&1 &
  1270. fi
  1271. ;;
  1272. linux-amarok|unix-amarok)
  1273. prefetch_or_copy
  1274. if test $QUEUE = 0
  1275. then
  1276. amarok "$HOME/.plait/playlist2.m3u" &
  1277. else
  1278. amarok --enqueue "$HOME/.plait/playlist2.m3u" &
  1279. fi
  1280. ;;
  1281. any-listonly)
  1282. cat "$HOME/.plait/playlist.m3u"
  1283. ;;
  1284. cygwin-listonly)
  1285. prefetch_or_translate
  1286. cat "$HOME/.plait/playlist2.m3u"
  1287. ;;
  1288. any-xspf)
  1289. prefetch_or_copy
  1290. awk -f $INSTALLDIR/share/plait/xspf.awk -v title="$LISTNAME" art=$COVERART \
  1291. plait="$HOME/.plait" coverprog="$INSTALLDIR/share/plait/coverart.awk" \
  1292. sep="$LEVELSEP" d="$MUSICDIR" ar=$ARTISTIDX al=$ALBUMIDX so=$SONGIDX url="$BASEURL" \
  1293. "$HOME/.plait/playlist2.m3u" > "$HOME/.plait/xspf/playlist.xspf"
  1294. sed -e "s:%TITLE%:$LISTNAME:" $INSTALLDIR/share/plait/playlist.html \
  1295. > "$HOME/.plait/xspf/index.html"
  1296. echo 1>&2 "Playlist directory $HOME/.plait/xspf ready for upload"
  1297. ;;
  1298. any-xspf-copy)
  1299. prefetch_or_copy
  1300. awk -f $INSTALLDIR/share/plait/xspf.awk -v title="$LISTNAME" art=$COVERART \
  1301. plait="$HOME/.plait" coverprog="$INSTALLDIR/share/plait/coverart.awk" \
  1302. sep="$LEVELSEP" d="$MUSICDIR" ar=$ARTISTIDX al=$ALBUMIDX so=$SONGIDX url="$BASEURL" \
  1303. "$HOME/.plait/playlist2.m3u" > "$HOME/.plait/xspf/playlist.xspf"
  1304. sed -e "s:%TITLE%:$LISTNAME:" $INSTALLDIR/share/plait/playlist.html \
  1305. > "$HOME/.plait/xspf/playlist.html"
  1306. if ! test $hasurl -gt 0
  1307. then
  1308. echo 1>&2 "Copying mp3 files to $HOME/.plait/xspf"
  1309. awk -f $INSTALLDIR/share/plait/treecopy.awk d="$MUSICDIR/" to="$HOME/.plait/xspf/" \
  1310. "$HOME/.plait/playlist2.m3u" | sh
  1311. fi
  1312. echo 1>&2 "Playlist directory $HOME/.plait/xspf ready for upload"
  1313. ;;
  1314. linux-mplayer|unix-mplayer)
  1315. prefetch_or_copy
  1316. killall > /dev/null 2>&1 mplayer
  1317. mplayer -really-quiet -playlist "$HOME/.plait/playlist2.m3u" &
  1318. ;;
  1319. any-s3)
  1320. ln2=`echo "$LISTNAME" | sed "s:/:-:g" | sed "s: :-:g"`
  1321. STRIPDIR=" | sed \"s:$MUSICDIR::\""
  1322. ADDURL=" | sed \"s~^~$BASEURL~\""
  1323. eval cat "$HOME/.plait/playlist.m3u" $STRIPDIR $ADDURL > "$HOME/.plait/playlist2.m3u"
  1324. cp "$HOME/.plait/playlist2.m3u" $MUSICDIR/$ln2.m3u
  1325. echo Playlist URL: $BASEURL/$ln2.m3u
  1326. ;;
  1327. esac
  1328. fi
  1329. fi