File indexing completed on 2024-05-19 04:50:25
0001 0002 # Simple script for testing the scriptable service browser 0003 # by creating a simple dynamic shoutcast directory browser. 0004 # when called with no arguments it creates the service, and 0005 # when called with a parent node id and a genre, it populates that 0006 # parent node with all stations in that genre 0007 # 0008 # (c) 2007 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> 0009 # 0010 # License: GNU General Public License V2 0011 0012 0013 require 'net/http' 0014 require 'uri' 0015 0016 0017 0018 0019 def parse_genre(nodeId, genre) 0020 0021 puts "genre: " + genre 0022 stations_xml = Net::HTTP.get(URI.parse('http://www.shoutcast.com/sbin/newxml.phtml?genre=' + genre) ) 0023 station_elements = stations_xml.split("\n") 0024 station_elements.each do |station| 0025 station =~ /(<station name=")(.*?)(")/ 0026 station_name = $2.to_s 0027 station =~ /(id=")(.*?)(")/ 0028 station_id = $2.to_s 0029 station_url = 'http://www.shoutcast.com/sbin/shoutcast-playlist.pls?rn=' + station_id + '&file=filename.pls' 0030 if station_name != "" 0031 system("qdbus", "org.kde.amarok", "/ScriptableServiceManager", "insertElement", station_name, station_url, "...", nodeId, "Shoutcast Streams") 0032 end 0033 end 0034 `qdbus org.kde.amarok /ScriptableServiceManager updateComplete "Shoutcast Streams"` 0035 0036 end 0037 0038 def setup_service() 0039 0040 `qdbus org.kde.amarok /ScriptableServiceManager createService "Shoutcast Streams" "Streams" "The largest collection of radio streams on the net, gathered in one place"` 0041 0042 genre_xml = Net::HTTP.get(URI.parse('http://www.shoutcast.com/sbin/newxml.phtml') ) 0043 genre_elements = genre_xml.split("\n") 0044 genre_elements.shift 0045 genre_elements.shift 0046 genre_elements.pop 0047 0048 script_command = "ruby ~/multimedia/amarok/src/servicebrowser/scriptableservice/shoutcast_service.rb" 0049 0050 genre_elements.each do |genre| 0051 genre =~ /(<genre name=")(.*)("><\/genre>)/# 0052 0053 system("qdbus", "org.kde.amarok", "/ScriptableServiceManager", "insertDynamicElement", $2, script_command, $2, "A collection of streams in the " + genre + " genre", 0.to_s, "Shoutcast Streams") 0054 0055 end 0056 0057 `qdbus org.kde.amarok /ScriptableServiceManager updateComplete "Shoutcast Streams"` 0058 0059 end 0060 0061 if ARGV.size == 0 then 0062 setup_service() 0063 else 0064 parse_genre(ARGV[0], ARGV[1]) 0065 end 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075