]> git.sesse.net Git - vlc/blob - share/lua/meta/fetcher/tvrage.lua
Lua: fix the remaining scripts.
[vlc] / share / lua / meta / fetcher / tvrage.lua
1 --[[
2  Gets metas for tv episode using tvrage.
3
4  $Id$
5  Copyright © 2010 the VideoLAN team
6
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 --]]
21
22 -- Replace non alphanumeric char by +
23 function get_query( title )
24     -- If we have a .EXT remove the extension.
25     str = string.gsub( title, "(.*)%....$", "%1" )
26     return string.gsub( str, "([^%w ])",
27          function (c) return string.format ("%%%02X", string.byte(c)) end)
28 end
29
30 function fetch_meta()
31     local metas = vlc.input.item:metas()
32
33     local showName = metas["showName"]
34     if not showName then
35         return false
36     end
37
38     local seasonNumber = metas["seasonNumber"];
39     if not seasonNumber then
40         return false
41     end
42
43     local episodeNumber = metas["episodeNumber"];
44     if not episodeNumber then
45         return false
46     end
47
48     local fd = vlc.stream("http://services.tvrage.com/feeds/search.php?show=" .. get_query(showName))
49     if not fd then return nil end
50     local page = fd:read( 65653 )
51     fd = nil
52     _, _, showid = string.find( page, "<showid>(.-)</showid>" )
53     if not showid then
54         return false
55     end
56
57     fd = vlc.stream("http://services.tvrage.com/feeds/full_show_info.php?sid=" .. showid)
58     if not fd then return nil end
59     page = fd:read( 65653 )
60     fd = nil
61     _, _, season = string.find(page, "<Season no=\""..seasonNumber.."\">(.-)</Season>")
62     if not season then
63         return false
64     end
65
66     _, _, episode = string.find(season, "<episode>(.-<seasonnum>"..episodeNumber.."</seasonnum>.-)</episode>")
67     if not episode then
68         return false
69     end
70
71     _, _, title, artwork = string.find(episode, "<title>(.-)</title><screencap>(.-)</screencap>")
72     if not title then
73         return false
74     end
75
76     vlc.input.item:set_meta("title", showName.. " S"..seasonNumber.."E"..episodeNumber.." - ".. title)
77     vlc.input.item:set_meta("artwork_url", artwork)
78     vlc.input.item:set_meta("episodeName", title)
79
80     return true
81 end