From 4b6c0e31385f5f27a151088c0a2b614495c4e589 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 14 Oct 2021 12:47:50 -0400 Subject: initial commit, including theme --- content/posts/2004-03-22-xmms-ruby-and-m3u.html | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 content/posts/2004-03-22-xmms-ruby-and-m3u.html (limited to 'content/posts/2004-03-22-xmms-ruby-and-m3u.html') diff --git a/content/posts/2004-03-22-xmms-ruby-and-m3u.html b/content/posts/2004-03-22-xmms-ruby-and-m3u.html new file mode 100644 index 0000000..69f5aac --- /dev/null +++ b/content/posts/2004-03-22-xmms-ruby-and-m3u.html @@ -0,0 +1,59 @@ +--- +date: "2004-03-22T12:40:09Z" +title: XMMS-Ruby and M3U +--- + +

+I wrote this little snippet of code in response to an email, and I thought it might be useful for other people. +

+ +
+

+Basically, I'm trying to write some code that will connect to a running +XMMS session, grab the playlist and write out a .pls or a .m3u file. +Unfortunately, while XMMS can do this in a single operation, their API +doesn't seem to have a simple hook to do this. +

+ +

+Unfortunately, there's nothing in the remote API that lets you do that +in a single call. But it should be pretty easy to write; just iterate +over the list and print out the necessary lines for each entry. +Something like this: +

+ +
+  module Xmms                                                                   
+    class Remote                                                                
+      #                                                                         
+      # get playlist contents as m3u-encoded string                             
+      #                                                                         
+      def to_m3u                                                                
+        "#EXTM3U\n" + playlist.map { |title, file, time|                        
+          "#EXTINF:#{time / 1000},#{title}\n#{file}"                            
+        }.join("\n")                                                            
+      end                                                                       
+    end                                                                         
+  end
+
+ +

+Then, to save a playlist, you can just do the following: +

+ +
+  xmms = Xmms::Remote.new                                                       
+  File::open('path/to/output.m3u', 'w') { |out| out.puts xmms.to_m3u }          
+                                                                                
+ +

+Hope this helps... +

+
+ +

+Update: I tossed this code in a downloadable file, and I added an +Xmms::Remote#save_m3u method for free. Download xmms-m3u.rb. +

+ -- cgit v1.2.3