Bookmark file playing in xmms


/ Published in: PHP
Save to your folder(s)

Gets currently playing song path and saves it to one of 3 playlists. Comes very handy when it's made a shortcut in the wm's panel.
Requires infopipe.
Reentrant.
Usage: /bm [0|1|2].
Creates files /bm.lock, /bm0.m3u, /bm1.m3u, /bm2.m3u.
Playlists must end with newline. Does not correctly handle diactritic letters.


Copy this code and paste it in your HTML
  1. //Removes the path $t from the nth playlist.
  2. function _remove($n,$t)
  3. {
  4. $nazw="/bm".$n.".m3u";
  5.  
  6. $b=strpos($a,$t);
  7.  
  8. if ($b === false) {;} else
  9. {
  10. $c=strpos($a,"\n",$b);
  11. $ha=fopen($nazw,"w+");
  12. if ($b>0)
  13. fwrite($ha,substr($a,0,$b));
  14. fwrite($ha, substr($a,$c+1));
  15. fclose($ha);
  16. }
  17. }
  18.  
  19. if ($argc!=2) die ("usage: ".$argv[0]." [0,1,2]\n");
  20. if (!in_array($argv[1], array('0','1','2') ))
  21. die ("usage: ".$argv[0]." [0,1,2]\n");
  22. $n=(integer)$argv[1];
  23.  
  24.  
  25.  
  26.  
  27. $blokada=fopen("/.bm.lock",'w');
  28. if ($blokada == false)
  29. die("error fopen\n");
  30. if (!flock($blokada,LOCK_EX))
  31. die ("error flock\n");
  32.  
  33. //get path to currently played track
  34. $a=file_get_contents('/tmp/xmms-info');
  35. $b=substr($a, 6+strpos($a,"File: "));
  36. $b=substr($b,0,strlen($b)-1);
  37.  
  38. _remove(0,$b);
  39. _remove(1,$b);
  40. _remove(2,$b);
  41.  
  42. //add path to a file
  43.  
  44. $nazw="/bm".$n.".m3u";
  45.  
  46. $plik=fopen($nazw,'a');
  47. fwrite($plik, $b."\n");
  48. fclose($plik);
  49. fclose($blokada);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.