From f065600a9415cbba628dc3e6e871fb88a207a4ba Mon Sep 17 00:00:00 2001
From: Fabio Ritrovato <exsephiroth87@gmail.com>
Date: Sat, 25 Jul 2009 13:31:20 +0200
Subject: [PATCH] [GSoC] luasd: first 3 scripts: youtube, dailymotion, jamendo

---
 share/lua/sd/dailymotion.lua |  168 +++++++++++++++++
 share/lua/sd/jamendo.lua     |  415 ++++++++++++++++++++++++++++++++++++++++++
 share/lua/sd/youtube.lua     |  302 ++++++++++++++++++++++++++++++
 3 files changed, 885 insertions(+), 0 deletions(-)
 create mode 100644 share/lua/sd/dailymotion.lua
 create mode 100644 share/lua/sd/jamendo.lua
 create mode 100644 share/lua/sd/youtube.lua

diff --git a/share/lua/sd/dailymotion.lua b/share/lua/sd/dailymotion.lua
new file mode 100644
index 0000000..f291195
--- /dev/null
+++ b/share/lua/sd/dailymotion.lua
@@ -0,0 +1,168 @@
+--SD_Description=Dailymotion
+--[[
+ $Id$
+
+ Copyright © 2007 the VideoLAN team
+ 
+ Authors: Fabio Ritrovato <exsephiroth87@gmail.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+--]]
+function main()
+    vlc.sd.add_parameter_value( {parameter="Channels",name="News & Politics",value="channel=\"news\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Film & TV",value="channel=\"shortfilms\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Auto-Moto",value="channel=\"auto\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Arts",value="channel=\"creation\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Webcam & Vlogs",value="channel=\"webcam\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Animals",value="channel=\"animals\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Tech & Science",value="channel=\"tech\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Life & Style",value="channel=\"lifestyle\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Funny",value="channel=\"fun\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Music",value="channel=\"music\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Travel",value="channel=\"travel\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Gaming",value="channel=\"videogames\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Sports & Extreme",value="channel=\"sport\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="People & Family",value="channel=\"people\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="College",value="channel=\"school\""} )
+    vlc.sd.add_parameter_value( {parameter="Channels",name="Sexy",value="channel=\"sexy\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Argentina",value="country=\"ar\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Beligique (FR)",value="country=\"be-fr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="België (NL)",value="country=\"be-nl\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Brasil",value="country=\"br\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Canada (EN)",value="country=\"ca-en\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Canada (FR)",value="country=\"ca-fr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Deutschland",value="country=\"de\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="España",value="country=\"es\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Ελλάδα",value="country=\"gr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="France",value="country=\"fr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="India",value="country=\"in\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Ireland",value="country=\"ie\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Italia",value="country=\"it\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="México",value="country=\"mx\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Nederland",value="country=\"nl\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Österreich",value="country=\"at\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Polska",value="country=\"pl\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Portugal",value="country=\"pt\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Россия",value="country=\"ru\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="România",value="country=\"ro\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Suisse (FR)",value="country=\"ch-fr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Schweiz (DE)",value="country=\"ch-de\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Svizzera (IT)",value="country=\"ch-it\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Türkiye",value="country=\"tr\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="United Kingdom",value="country=\"gb\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="United States",value="country=\"us\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="日本",value="country=\"jp\""} )
+    vlc.sd.add_parameter_value( {parameter="Order",name="Most Recent",value="order=\"recent\""} )
+    vlc.sd.add_parameter_value( {parameter="Order",name="Most Commented",value="order=\"commented\""} )
+    vlc.sd.add_parameter_value( {parameter="Order",name="Most Viewed",value="order=\"visited\""} )
+    vlc.sd.add_parameter_value( {parameter="Order",name="Best Rated",value="order=\"rated\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="All Time",value="time=\"all\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="Month",value="time=\"month\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="Week",value="time=\"week\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="Today",value="time=\"today\""} )
+    vlc.sd.add_parameter_value( {parameter="Videos",name="All Videos",value="videos=\"all\""} )
+    vlc.sd.add_parameter_value( {parameter="Videos",name="Featured Videos",value="videos=\"featured\""} )
+    vlc.sd.add_parameter_value( {parameter="Videos",name="HD Content",value="videos=\"hd\""} )
+    vlc.sd.add_parameter_value( {parameter="Videos",name="Official Content",value="videos=\"official\""} )
+    vlc.sd.add_parameter_value( {parameter="Videos",name="Creative Content",value="videos=\"creative\""} )
+end
+
+function item_put( string )
+    local _, _, channel = string.find( string, "channel=\"([^\"]+)\"" )
+    local _, _, order = string.find( string, "order=\"([^\"]+)\"" )
+    local _, _, videos = string.find( string, "videos=\"([^\"]+)\"" )
+    if videos == nil then videos = "featured" end
+    if channel ~= nil or order ~= nil or videos ~= nil then
+        local _, _, time = string.find( string, "time=\"([^\"]+)\"" )
+        local _, _, country = string.find( string, "country=\"([^\"]+)\"" )
+        get_page( channel, order, time, videos, country )
+        return
+    end
+end
+
+function get_page( channel, order, time, videos, country )
+    local url = "http://www.dailymotion.com/"
+    if country ~= nil then
+        url = url .. country .. "/"
+    end
+    if order ~= nil and order ~= "recent" then
+        if time == "all" then time = nil
+        elseif time == nil then time = "week" end
+        url = url .. order
+        if time ~= nil then
+            url = url .. "-" .. time
+        end
+        url = url .. "/"
+    end
+    if channel ~= nil then
+        url = url .. "channel/" .. channel .. "/"
+    end
+    if videos ~= "all" then
+        url = url .. videos
+    end
+    url = url .. "/1"
+    vlc.msg.info( url )
+    local fd = vlc.stream( url )
+    local page = ""
+    local newpage = fd:read( 65653 )
+    while newpage ~= nil and newpage ~= "" do
+        page = page .. newpage
+        newpage = fd:read( 65653 )
+    end
+    fd = nil
+    if page == "" then
+        return nil
+    end
+    local oldidxEnd = 0, i, j
+    _, _, title = string.find ( page, "<title>([^\"]+)</title>" )
+    node = vlc.sd.add_node( {title=title } )
+    for i=1,15 do
+        local idxEnd, url, arturl, title, duration, author
+        _, idxEnd, url = string.find ( page, "href=\"([^\"]+/video/[^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and url then
+            oldidxEnd = idxEnd
+        else
+            break
+        end
+        _, idxEnd, arturl = string.find ( page, "src=\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and arturl then
+            oldidxEnd = idxEnd
+        else
+            break
+        end
+        _, idxEnd, title = string.find ( page, "title=\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and title then
+            title = vlc.strings.resolve_xml_special_chars( title )
+            oldidxEnd = idxEnd
+        else
+            break
+        end
+        _, idxEnd, duration = string.find ( page, "dmco_text duration\">([^\"]+)</div>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and duration then
+            oldidxEnd = idxEnd
+        else
+            break
+        end
+        local s = string.find( duration, ":" )
+        duration = ( string.sub( duration, 0, s-1 )*60 )+string.sub( duration, s+1 )
+        _, idxEnd, author = string.find ( page, "login name\" href=\"/([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and author then
+            oldidxEnd = idxEnd
+        else
+            break
+        end
+        vlc.sd.add_item( {title=title,url="http://www.dailymotion.com" .. url,artist=author,arturl=arturl,duration=duration,parent=node} )
+    end
+end
diff --git a/share/lua/sd/jamendo.lua b/share/lua/sd/jamendo.lua
new file mode 100644
index 0000000..370b499
--- /dev/null
+++ b/share/lua/sd/jamendo.lua
@@ -0,0 +1,415 @@
+--SD_Description=Jamendo
+--[[
+ $Id$
+
+ Copyright © 2007 the VideoLAN team
+ 
+ Authors: Fabio Ritrovato <exsephiroth87@gmail.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+--]]
+function main()
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most populars",value="album=\"rating_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most populars this month",value="album=\"ratingmonth_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most populars this week",value="album=\"ratingweek_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Latest releases",value="album=\"releasedate_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most downloaded",value="album=\"downloaded_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most listened to",value="album=\"listened_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most starred",value="album=\"starred_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Most playlisted",value="album=\"playlisted_desc\""} )
+    vlc.sd.add_parameter_value( {parameter="Albums",name="Requires reviews",value="album=\"needreviews_desc\""} )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/idstr + name/artist/plain?n=all&hasalbums=1&order=name_asc" )
+    local page = fd:read( 65653 )
+    local skipId = false, name, id
+    while( page ~= nil and page ~= "\n" ) do
+        local oldidxEnd = 0
+        while true do
+            local idxEnd
+            if skipId == false then
+                local _, idxEnd = string.find( page, "	", oldidxEnd )
+                if idxEnd ~= nil and idxEnd < 65653 then
+                    id = string.sub( page, oldidxEnd, idxEnd-1 )
+                    oldidxEnd = idxEnd+1
+                    skipId = true 
+                else
+                    break
+                end
+            end
+            _, idxEnd = string.find( page, "\n", oldidxEnd )
+            if idxEnd ~= nil and idxEnd < 65653 then
+                name = string.sub( page, oldidxEnd, idxEnd-1 )
+                oldidxEnd = idxEnd+1
+                skipId = false
+                vlc.sd.add_parameter_value( {parameter="Artist",name=name,value="artist_idstr=\"" .. id .. "\""} )
+            else
+                break
+            end
+        end
+        local newPage = fd:read( 65653 )
+        if newPage == nil or newPage == "" then
+            newPage = "\n"
+        end
+        page = string.sub( page, oldidxEnd, 65653 ) .. newPage
+    end
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Rock",value="radio=\"9\""} )
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Pop / Songwriting",value="radio=\"8\""} )
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Jazz",value="radio=\"6\""} )
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Hip-Hop",value="radio=\"5\""} )
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Lounge",value="radio=\"7\""} )
+    vlc.sd.add_parameter_value( {parameter="Radio",name="Dance / Electro",value="radio=\"4\""} )
+    fd = nil
+    fd = vlc.stream( "http://www.jamendo.com/en/tags" )
+    page = fd:read( 131270 )
+    fd = nil
+    if page ~= nil then
+        local _, oldidxEnd = string.find( page, "tagscloud" )
+        if oldidxEnd ~= nil then
+            while true do
+                local idxEnd, tag_name
+                _, idxEnd, tag_name = string.find( page, "http://www.jamendo.com/en/tag/([^\"]+)\"", oldidxEnd )
+                if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+                    oldidxEnd = idxEnd+1
+                else
+                    break
+                end
+                vlc.sd.add_parameter_value( {parameter="Tags",name=tag_name,value="tag=\"" .. tag_name .. "\""} )
+            end
+        end
+    end
+    vlc.sd.add_parameter_value( {parameter="Album search"} )
+    vlc.sd.add_parameter_value( {parameter="Artist search"} )
+    vlc.sd.add_parameter_value( {parameter="Max results"} )
+end
+
+function item_put( string )
+    local _, _, artist = string.find( string, "artist_idstr=\"([^\"]+)\"" )
+    if artist ~= nil then
+        get_artist_from_idstr( artist, nil )
+        return
+    end
+    local _, _, album_order = string.find( string, "album=\"([^\"]+)\"" )
+    local _, _, tag = string.find( string, "tag=\"([^\"]+)\"" )
+    if album_order ~= nil or tag ~= nil then
+        if album_order == nil then
+            album_order = "ratingmonth_desc"
+        end
+        local _, _, max_results = string.find( string, "max_results=\"([^\"]+)\"" )
+        if max_results == nil then
+            max_results = "20"
+        end
+        get_top_albums( album_order, tag, max_results )
+        return
+    end
+    local _, _, radio = string.find( string, "radio=\"([^\"]+)\"" )
+    if radio ~= nil then
+        local _, _, max_results = string.find( string, "max_results=\"([^\"]+)\"" )
+        if max_results == nil then
+            max_results = "20"
+        end
+        get_radio_from_id( radio, max_results )
+        return
+    end
+    local _, _, search = string.find( string, "album_search=\"([^\"]+)\"" )
+    if search ~= nil then
+        local _, _, max_results = string.find( string, "max_results=\"([^\"]+)\"" )
+        if max_results == nil then
+            max_results = "20"
+        end
+        album_search( search, max_results )
+        return
+    end
+    local _, _, search = string.find( string, "artist_search=\"([^\"]+)\"" )
+    if search ~= nil then
+        local _, _, max_results = string.find( string, "max_results=\"([^\"]+)\"" )
+        if max_results == nil then
+            max_results = "20"
+        end
+        artist_search( search, max_results )
+        return
+    end
+end
+
+function get_artist_from_idstr( artist, parent )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/name/artist/plain/?idstr=" .. artist )
+    local artist_name = fd:read( 65653 )
+    fd = nil
+    if artist_name == nil then
+        return false
+    end
+    local node = vlc.sd.add_node( {title=artist_name,arturl="http://img.jamendo.com/artists/" .. string.sub( artist, 1, 1 ) .. "/" .. artist .. ".jpg ",parent=parent} )
+    local albums = get_albums_from_artist( artist )
+    local i = 0
+    while albums[i] ~= nil do
+        local album_node = vlc.sd.add_node( {title=albums[i].title,arturl="http://imgjam.com/albums/".. albums[i].id .. "/covers/1.200.jpg",parent=node} )
+        local tracks = get_tracks_from_album( albums[i].id )
+        local j = 0
+        while tracks[j] ~= nil do
+            vlc.sd.add_item( {url="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. tracks[j].id,title=tracks[j].title,artist=artist_name,album=albums[i].title,genre=tracks[j].genre,tracknum=j+1,date=tracks[j].date,arturl="http://imgjam.com/albums/".. albums[i].id .. "/covers/1.200.jpg",duration=tracks[j].duration,parent=album_node} )
+            j = j+1
+        end
+        i = i+1
+    end
+end
+
+function get_top_albums( album_order, tag, max_results )
+    local url = "http://api.jamendo.com/get2/id+name+artist_name/album/json/?order=" .. album_order .. "&n=" .. max_results
+    if tag ~= nil then
+        url = url .. "&tag_idstr=" .. tag
+    end
+    local fd = vlc.stream( url )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local node_name
+    if album_order == "rating_desc" then node_name = "Most populars"
+    elseif album_order == "ratingmonth_desc" then node_name = "Most populars this month"
+    elseif album_order == "ratingweek_desc" then node_name = "Most populars this week"
+    elseif album_order == "releasedate_desc" then node_name = "Latest releases"
+    elseif album_order == "downloaded_desc" then node_name = "Most downloaded"
+    elseif album_order == "listened_desc" then node_name = "Most listened to"
+    elseif album_order == "starred_desc" then node_name = "Most starred"
+    elseif album_order == "playlisted_desc" then node_name = "Most playlisted"
+    elseif album_order == "needreviews_desc" then node_name = "Requires reviews"
+    end
+    if tag ~= nil then
+        node_name = tag .. " - " .. node_name
+    end
+    local node = vlc.sd.add_node( {title=node_name} )
+    local oldidxEnd = 0
+    while true do
+        local idxEnd, id, name, artist_name
+        _, idxEnd, id = string.find( page, "\"id\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, name = string.find( page, "\"name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and name then
+            name = vlc.strings.resolve_xml_special_chars( name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, artist_name = string.find( page, "\"artist_name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and artist_name then
+            artist_name = vlc.strings.resolve_xml_special_chars( artist_name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        local album_node = vlc.sd.add_node( {title=artist_name .. " - " .. name,arturl="http://imgjam.com/albums/".. id .. "/covers/1.200.jpg",parent=node} )
+        local tracks = get_tracks_from_album( id )
+        local i = 0
+        while tracks[i] ~= nil do
+            vlc.sd.add_item( {url="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. tracks[i].id,title=tracks[i].title,artist=artist_name,album=name,genre=tracks[i].genre,tracknum=i+1,date=tracks[i].date,arturl="http://imgjam.com/albums/".. id .. "/covers/1.200.jpg",duration=tracks[i].duration,parent=album_node} )
+            i = i+1
+        end
+    end
+end
+
+function get_albums_from_artist( artist )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/id+name/album/json/?artist_idstr=" .. artist .. "&n=all&order=name_asc" )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local oldidxEnd = 0
+    local i = 0
+    local albums = {}
+    while true do
+        local idxEnd, id, name
+        _, idxEnd, id = string.find( page, "\"id\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, name = string.find( page, "\"name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and name then
+            oldidxEnd = idxEnd+1
+            name = vlc.strings.resolve_xml_special_chars( name )
+            albums[i] = {title=name,id=id}
+            i = i+1
+        else
+            break
+        end
+    end
+    return albums
+end
+
+function get_tracks_from_album( album )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/id+name+duration+album_genre+album_dates/track/json/?album_id=" .. album )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local oldidxEnd = 0
+    local i = 0
+    local tracks = {}
+    while true do
+        local idxEnd, id, name, album_genre, year, duration
+        _, idxEnd, id = string.find( page, "\"id\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, name = string.find( page, "\"name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and name then
+            name = vlc.strings.resolve_xml_special_chars( name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, duration = string.find( page, "\"duration\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and duration then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, album_genre = string.find( page, "\"album_genre\":\"([^\"]+)\"", oldidxEnd )
+        _, idxEnd, year = string.find( page, "\"year\":\"([^\"]+)\"", oldidxEnd )
+        tracks[i] = {title=name,id=id,genre=album_genre,date=year,duration=duration}
+        i = i+1
+    end
+    return tracks
+end
+
+function get_radio_from_id( id, max_results )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/id+name+artist_name+album_name+duration+album_genre+album_dates/track/json/radio_track_inradioplaylist+track_album+album_artist/?order=numradio_asc&radio_id=" .. id .. "&n=" .. max_results )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local radio_name
+    if id == "9" then radio_name="Rock"
+    elseif id == "8" then radio_name="Pop / Songwriting"
+    elseif id == "6" then radio_name="Jazz"
+    elseif id == "5" then radio_name="Hip-Hop"
+    elseif id == "7" then radio_name="Lounge"
+    elseif id == "4" then radio_name="Dance / Electro"
+    end
+    local radio_node = vlc.sd.add_node( {title="Radio " .. radio_name} )
+    local oldidxEnd = 0
+    local i = 0
+    while true do
+        local idxEnd, id, name, artist_name, album_name, album_genre, year, duration
+        _, idxEnd, id = string.find( page, "\"id\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, name = string.find( page, "\"name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and name then
+            name = vlc.strings.resolve_xml_special_chars( name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, artist_name = string.find( page, "\"artist_name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and artist_name then
+            artist_name = vlc.strings.resolve_xml_special_chars( artist_name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, album_name = string.find( page, "\"album_name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and album_name then
+            album_name = vlc.strings.resolve_xml_special_chars( album_name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, duration = string.find( page, "\"duration\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and duration then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, album_genre = string.find( page, "\"album_genre\":\"([^\"]+)\"", oldidxEnd )
+        _, idxEnd, year = string.find( page, "\"year\":\"([^\"]+)\"", oldidxEnd )
+        vlc.sd.add_item( {url="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. id,title=artist_name .. " - " .. name,artist=artist_name,album=album_name,genre=album_genre,date=year,arturl="http://imgjam.com/albums/".. id .. "/covers/1.200.jpg",duration=duration,parent=radio_node} )
+    end
+    return tracks
+end
+
+function album_search( search, max_results )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/id+name+artist_name/album/json/?searchquery=\"" .. search .. "\"&order=searchweight_desc&n=" .. max_results )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local node = vlc.sd.add_node( {title="Album search: " .. search} )
+    local oldidxEnd = 0
+    while true do
+        local idxEnd, id, name, artist_name
+        _, idxEnd, id = string.find( page, "\"id\":([^\"]+),", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and id then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, name = string.find( page, "\"name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and name then
+            name = vlc.strings.resolve_xml_special_chars( name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        _, idxEnd, artist_name = string.find( page, "\"artist_name\":\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and artist_name then
+            artist_name = vlc.strings.resolve_xml_special_chars( artist_name )
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        local album_node = vlc.sd.add_node( {title=artist_name .. " - " .. name,arturl="http://imgjam.com/albums/".. id .. "/covers/1.200.jpg",parent=node} )
+        local tracks = get_tracks_from_album( id )
+        local i = 0
+        while tracks[i] ~= nil do
+            vlc.sd.add_item( {url="http://api.jamendo.com/get2/stream/track/redirect/?id=" .. tracks[i].id,title=tracks[i].title,artist=artist_name,album=name,genre=tracks[i].genre,tracknum=i+1,date=tracks[i].date,arturl="http://imgjam.com/albums/".. id .. "/covers/1.200.jpg",duration=tracks[i].duration,parent=album_node} )
+            i = i+1
+        end
+    end
+end
+
+function artist_search( search, max_results )
+    local fd = vlc.stream( "http://api.jamendo.com/get2/idstr/artist/json/?searchquery=\"" .. search .. "\"&order=searchweight_desc&n=" .. max_results )
+    local page = fd:read( 65653 )
+    fd = nil
+    if page == nil then
+        return nil
+    end
+    local node = vlc.sd.add_node( {title="Artist search: " .. search} )
+    local oldidxEnd = 0
+    while true do
+        local idxEnd, idstr
+        _, idxEnd, idstr = string.find( page, "\"([^\"]+)\"", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd and idstr then
+            oldidxEnd = idxEnd+1
+        else
+            break
+        end
+        get_artist_from_idstr( idstr, node )
+    end
+end
diff --git a/share/lua/sd/youtube.lua b/share/lua/sd/youtube.lua
new file mode 100644
index 0000000..98c5999
--- /dev/null
+++ b/share/lua/sd/youtube.lua
@@ -0,0 +1,302 @@
+--SD_Description=Youtube
+--[[
+ $Id$
+
+ Copyright © 2007 the VideoLAN team
+ 
+ Authors: Fabio Ritrovato <exsephiroth87@gmail.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+--]]
+function main()
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Film & Animation",value="category=\"Film\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Autos & Vehicles",value="category=\"Autos\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Music",value="category=\"Music\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Pets & Animals",value="category=\"Animals\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Sports",value="category=\"Sports\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Travel & Events",value="category=\"Travel\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Short Movies",value="category=\"Shortmov\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Videoblogging",value="category=\"Videoblog\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Gaming",value="category=\"Games\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Comedy",value="category=\"Comedy\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="People & Blogs",value="category=\"People\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="News & Politics",value="category=\"News\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Entertainment",value="category=\"Entertainment\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Education",value="category=\"Education\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Howto & Style",value="category=\"Howto\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Nonprofits & Activism",value="category=\"Nonprofit\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Science & Technology",value="category=\"Tech\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies",value="category=\"Movies\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Anime/Animation",value="category=\"Movies_Anime_animation\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Comedy",value="category=\"Movies_Comedy\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Action/Adventure",value="category=\"Movies_Action_adventure\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Classics",value="category=\"Movies_Classics\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Foreign",value="category=\"Movies_Foreign\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Horror",value="category=\"Movies_Horror\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Drama",value="category=\"Movies_Drama\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Family",value="category=\"Movies_Family\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Shorts",value="category=\"Movies_Shorts\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Sci-Fi/Fantasy",value="category=\"Movies_Sci_fi_fantasy\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Movies - Thriller",value="category=\"Movies_Thriller\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Shows",value="category=\"Shows\""} )
+    vlc.sd.add_parameter_value( {parameter="Categories",name="Trailers",value="category=\"Trailers\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Top rated",value="category_order=\"top_rated\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Top favorites",value="category_order=\"top_favorites\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most viewed",value="category_order=\"most_viewed\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most popular",value="category_order=\"most_popular\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most recent",value="category_order=\"most_recent\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most discussed",value="category_order=\"most_discussed\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most linked",value="category_order=\"most_linked\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Most responded",value="category_order=\"most_responded\""} )
+    vlc.sd.add_parameter_value( {parameter="Category order",name="Recently featured",value="category_order=\"recently_featured\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Australia",value="country=\"AU\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Brazil",value="country=\"BR\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Canada",value="country=\"CA\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Czech Republic",value="country=\"CZ\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="France",value="country=\"FR\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Germany",value="country=\"DE\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Great Britain",value="country=\"GB\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Holland",value="country=\"NL\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Hong Kong",value="country=\"HK\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="India",value="country=\"IN\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Ireland",value="country=\"IE\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Israel",value="country=\"IL\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Italy",value="country=\"IT\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Japan",value="country=\"JP\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Mexico",value="country=\"MX\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="New Zeland",value="country=\"NZ\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Poland",value="country=\"PL\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Russia",value="country=\"RU\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="South Korea",value="country=\"KR\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Spain",value="country=\"ES\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Sweden",value="country=\"SE\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="Taiwan",value="country=\"TW\""} )
+    vlc.sd.add_parameter_value( {parameter="Country",name="United States",value="country=\"US\""} )
+    vlc.sd.add_parameter_value( {parameter="Max results"} )
+    vlc.sd.add_parameter_value( {parameter="Search"} )
+    vlc.sd.add_parameter_value( {parameter="Search order",name="Relevance",value="search_order=\"relevance\""} )
+    vlc.sd.add_parameter_value( {parameter="Search order",name="Most recent",value="search_order=\"published\""} )
+    vlc.sd.add_parameter_value( {parameter="Search order",name="View count",value="search_order=\"viewCount\""} )
+    vlc.sd.add_parameter_value( {parameter="Search order",name="Rating",value="search_order=\"rating\""} )
+    vlc.sd.add_parameter_value( {parameter="Start index"} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="Today",value="time=\"today\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="This week",value="time=\"this_week\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="This month",value="time=\"this_month\""} )
+    vlc.sd.add_parameter_value( {parameter="Time",name="All time",value="time=\"all_time\""} )
+end
+
+function item_put( string )
+    local _, _, category = string.find( string, "category=\"([^\"]+)\"" )
+    local _, _, search = string.find( string, "search=\"([^\"]+)\"" )
+    if category ~= nil or search ~= nil then
+        local _, _, category_order = string.find( string, "category_order=\"([^\"]+)\"" )
+        if category_order == nil then
+            category_order = "most_popular"
+        end
+        local time
+        if category_order ~= "most_recent" and category_order ~= "recently_featured" then
+            _, _, time = string.find( string, "time=\"([^\"]+)\"" )
+            if time == nil then
+                time = "today"
+            end
+        end
+        local search_order
+        if search ~= nil then
+            _, _, search_order = string.find( string, "search_order=\"([^\"]+)\"" )
+            if search_order == nil then
+                search_order = "relevance"
+            end
+        end
+        local _, _, country = string.find( string, "country=\"([^\"]+)\"" )
+        local _, _, max_results = string.find( string, "max_results=\"([^\"]+)\"" )
+        if max_results == nil then
+            max_results = "25"
+        end
+        local _, _, start_index = string.find( string, "start_index=\"([^\"]+)\"" )
+        if start_index == nil then
+            start_index = "1"
+        end
+        get_feed( search, category, category_order, search_order, time, country, max_results, start_index )
+        return
+    end
+end
+
+function get_feed( search, category, category_order, search_order, time, country, max_results, start_index )
+    local url
+    if search == nil then
+        url = "http://gdata.youtube.com/feeds/api/standardfeeds/"
+        if country ~= nil then
+            url = url .. country .. "/"
+        end
+    else
+        url = "http://gdata.youtube.com/feeds/api/videos?q=" .. search .. "&orderby=" .. search_order .. "&"
+    end
+    if search == nil then
+        url = url .. category_order .. "_" .. category .. "?"
+    end
+    url = url .. "v=2&max-results=" .. max_results .. "&start-index=" .. start_index
+    if search ~= nil and category ~= nil then
+        url = url .. "&category=" .. category
+    end
+    if time ~= nil then
+        url = url .. "&time=" .. time
+    end
+    local fd = vlc.stream( url )
+    local page = ""
+    local newpage = fd:read( 65653 )
+    while newpage ~= nil and newpage ~= "" do
+        page = page .. newpage
+        newpage = fd:read( 65653 )
+    end
+    fd = nil
+    if page == "" then
+        return nil
+    end
+    local oldidxEnd = 0, i, j
+    _, i = string.find ( page, "<title>", oldidxEnd )
+    j, oldidxEnd = string.find ( page, "</title>", oldidxEnd )
+    node = vlc.sd.add_node( {title=string.sub( page, i+1, j-1) } )
+    while true do
+        local idxEnd, published, title, url, author, category, description, keywords, arturl, duration
+        _, i = string.find ( page, "<published>", oldidxEnd )
+        j, idxEnd = string.find ( page, "</published>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            published = string.sub( page, i+1, j-1) 
+            if published then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "<title>", oldidxEnd )
+        j, idxEnd = string.find ( page, "</title>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            title = string.sub( page, i+1, j-1) 
+            if title then
+                title = vlc.strings.resolve_xml_special_chars( title )
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "href='", oldidxEnd )
+        if i ~= nil then
+            j, idxEnd = string.find ( page, "'", i+1 )
+        else
+            break
+        end
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            url = string.sub( page, i+1, j-1) 
+            if url then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "<name>", oldidxEnd )
+        j, idxEnd = string.find ( page, "</name>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            author = string.sub( page, i+1, j-1) 
+            if author then
+                author = vlc.strings.resolve_xml_special_chars( author )
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "media:category label='", oldidxEnd )
+        if i ~= nil then
+            j, idxEnd = string.find ( page, "'", i+1 )
+        else
+            break
+        end
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            category = string.sub( page, i+1, j-1) 
+            if category then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "duration='", oldidxEnd )
+        if i ~= nil then
+            j, idxEnd = string.find ( page, "'", i+1 )
+        else
+            break
+        end
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            duration = string.sub( page, i+1, j-1) 
+            if duration then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "<media:description type='plain'>", oldidxEnd )
+        j, idxEnd = string.find ( page, "</media:description>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            description = string.sub( page, i+1, j-1) 
+            if description then
+                description = vlc.strings.resolve_xml_special_chars( description )
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "<media:keywords>", oldidxEnd )
+        j, idxEnd = string.find ( page, "</media:keywords>", oldidxEnd )
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            keywords = string.sub( page, i+1, j-1) 
+            if keywords then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        _, i = string.find ( page, "media:thumbnail url='", oldidxEnd )
+        if i ~= nil then
+            j, idxEnd = string.find ( page, "'", i+1 )
+        else
+            break
+        end
+        if idxEnd ~= nil and oldidxEnd ~= nil and idxEnd > oldidxEnd then
+            arturl = string.sub( page, i+1, j-1) 
+            if arturl then
+                oldidxEnd = idxEnd
+            else
+                break
+            end
+        else
+            break
+        end
+        vlc.sd.add_item( {title=title,url=url,artist=author,date=published,album=category,description=description,genre=keywords,arturl=arturl,duration=duration,parent=node} )
+    end
+end
-- 
1.6.0.4

