=begin # TODO encode query in jamendo_query AUTHOR: Kesiev WHAT IT DOES: A really basic Jamendo support plugin. It isn't really complete, since is not using the Jamendo databases snapshots for getting informations but uses REST calls. REST calls aren't too much complete so not all searches are available. When REST calls will be completed, probably it will be updated. Database is here: http://developer.jamendo.com/en/wiki/DatabaseDumps So you can update or rewrite this plugin, if you like. It has interesting album browsing features, overloading the play sub =end # Misc jamendo queries. Not all are available from the gui JAMENDO_QUERIES={ :tag=>{ # the query label for menus :label=>"Tag", # The query url, with %s as the queried words :url=>"http://api.jamendo.com/get2/album_id+image+name+url+artist_name/album/plain/?tag_idstr=%s&n=100&order=rating_desc", # tab separated list => playlist converter :fieldmap=>[:custommeta,:cover,:title,:url,:artist], # Additional prefix in custommeta :additionallabel=>"jamendo-album", # Attributes to be added in custommeta :additionalitems=>[:custommeta,:artist], # Static fields assignment :set=>{:album=>"(Album)"} }, :artist=>{ :label=>"Artist", :url=>"http://api.jamendo.com/get2/album_id+image+name+url+artist_name/album/plain/?artist_name=%s&n=100&order=rating_desc", :fieldmap=>[:custommeta,:cover,:title,:url,:artist], :additionallabel=>"jamendo-album", :additionalitems=>[:custommeta,:artist], :set=>{:album=>"(Album)"} }, :album_id=>{ :label=>"Album ID", :url=>"http://api.jamendo.com/get2/album_id+image+name+url+artist_name/album/plain/?album_id=%s&n=100&order=rating_desc", :fieldmap=>[:custommeta,:cover,:title,:url,:artist], :additionallabel=>"jamendo-album", :additionalitems=>[:custommeta,:artist], :set=>{:album=>"(Album)"} }, :bestalbums=>{ :label=>"Best albums", :url=>"http://api.jamendo.com/get2/album_id+image+name+url+artist_name/album/plain/?n=100&order=rating_desc", :fieldmap=>[:custommeta,:cover,:title,:url,:artist], :additionallabel=>"jamendo-album", :additionalitems=>[:custommeta,:artist], :set=>{:album=>"(Album)"}, :noask=>true }, :latestalbums=>{ :label=>"Latest albums", :url=>"http://api.jamendo.com/get2/album_id+image+name+url+artist_name/album/plain/?n=100&order=releasedate_desc", :fieldmap=>[:custommeta,:cover,:title,:url,:artist], :additionallabel=>"jamendo-album", :additionalitems=>[:custommeta,:artist], :set=>{:album=>"(Album)"}, :noask=>true }, :albumid=>{ :label=>"Album ID", :url=>"http://api.jamendo.com/get2/track_id+name+stream+numalbum+url+album_name+album_image/track/plain/?album_id=%s&n=all&order=numalbum", :fieldmap=>[:custommeta,:title,:file,:trackno,:url,:album,:cover], :additionallabel=>"jamendo-song", :additionalitems=>[:custommeta] } } # Playlist entry $lists << { :label=> "Jamendo", :icon=> "file:#{$opt[:root]}/jamendoicon", :file=>"#{$opt[:root]}/jamendo", :protected=>true, :jamendo=>true } # Background download of the Jamendo favicon as the entry icon if !File.exist?("#{$opt[:root]}/jamendoicon") then Thread.new { open("http://www.jamendo.com/favicon.ico","r") { |fin| open("#{$opt[:root]}/jamendoicon", "w") { |fout| while (buf = fin.read(8192)) do fout.write buf end } } updatemodes } end # Get the first Jamendo list item def jamendo_get $lists.each { |item| if (item[:jamendo]) then return item end } return nil end # Adding the Jamendo menu before the Help menu $menulist.insert($menulist.length-1, { :label => "Jamendo", :id=>:jamendo, :showif=>Proc.new {|s| s[:jamendo]} } ) # Adding menu items for searching Jamendo [:tag,:artist,:album_id,:bestalbums,:latestalbums].each { |tag| $menus <<{ :menu=>:jamendo, :label=>"Search by #{JAMENDO_QUERIES[tag][:label]}", :action=>Proc.new{ if JAMENDO_QUERIES[tag][:noask] then jamendo_query("",tag) setmode(jamendo_get) else jamendo_form(tag,JAMENDO_QUERIES[tag][:label]) end } } } # Go to the Jamendo Home Page $menus<<{ :menu=>:jamendo, :label=>"Jamendo homepage", :action=>Proc.new{ surf("http://www.jamendo.com/") } } # Adding contextual actions for Jamendo searches $contextactions << { :label => "Search Jamendo for artist", :verifyer => Proc.new{ |s| s[COLMAP[:custommeta]].to_s[0..7]=="jamendo-"}, :action => Proc.new{ |s| jamendo_query(s[COLMAP[:artist]],:artist); setmode(jamendo_get)} } << { :label => "Search Jamendo for album", :verifyer => Proc.new{ |s| s[COLMAP[:custommeta]].to_s[0..7]=="jamendo-"}, :action => Proc.new{ |s| jamendo_query(nil,:albumid,s[COLMAP[:custommeta]]) setmode(jamendo_get) } } # Open albums if an album is selected, else go to normal playback. # This is useful if you want to implement something like a raw folder # browser. alias jamendo_play play def play(iter) if iter[COLMAP[:custommeta]].to_s[0..12]=="jamendo-album" then jamendo_query(nil,:albumid,iter[COLMAP[:custommeta]]) setmode(jamendo_get) else jamendo_play(iter) end end # The Jamendo search box def jamendo_form(id,label) searchbox = Gtk::Window.new searchbox.modal=true searchbox.title="Search Jamendo" searchbox.border_width = 5 searchbox.set_default_size(400,30) searchbox.add(mbox=Gtk::HBox.new) mbox.spacing=5 mbox.pack_start(Gtk::Label.new(label),false,false) mbox.pack_start(editbox=Gtk::Entry.new,true,true) mbox.pack_start(confirm=Gtk::Button.new("Search"),false,true) mbox.pack_start(cancel=Gtk::Button.new("Cancel"),false,true) confirm.signal_connect("clicked") { jamendo_query(editbox.text,id) setmode(jamendo_get) searchbox.destroy } editbox.signal_connect("activate") { jamendo_query(editbox.text,id) setmode(jamendo_get) searchbox.destroy } cancel.signal_connect("clicked") { searchbox.destroy } searchbox.show_all end def jamendo_query(query,field=:track_name,additional="") section=jamendo_get add={} additional.split("\t").each { |item| add[item[0..item.index("=")-1].intern]=item[item.index("=")+1..-1] if item.index("=") } field=JAMENDO_QUERIES[field] query=add[:custommeta] if query==nil open(section[:file],"w") { |w| open(field[:url] % [URI.escape(query)],"r") { |f| f.each { |line| line.strip! line.each {|album| newitem={} album=album.split("\t") field[:fieldmap].each_with_index { |f,i| newitem[f]=album[i] } add.each { |k,v| newitem[k]=v } if field[:additionallabel] tmp=field[:additionallabel]+"\t" field[:additionalitems].each { |i| tmp+="#{i}=#{newitem[i]}\t" } newitem[:custommeta]=tmp end field[:set].each { |k,v| newitem[k]=v } if field[:set] w.puts(formatrecord(newitem)) } } } } end