]> git.sesse.net Git - vlc/blob - share/lua/meta/fetcher/tvrage.lua
af71f0e4ea9f1a6def12c21dd406f4d08f8c9824
[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.item.metas(vlc.item)
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     local page = fd:read( 65653 )
50     fd = nil
51     _, _, showid = string.find( page, "<showid>(.-)</showid>" )
52     if not showid then
53         return false
54     end
55
56     fd = vlc.stream("http://services.tvrage.com/feeds/full_show_info.php?sid=" .. showid)
57     page = fd:read( 65653 )
58     fd = nil
59     _, _, season = string.find(page, "<Season no=\""..seasonNumber.."\">(.-)</Season>")
60     if not season then
61         return false
62     end
63
64     _, _, episode = string.find(season, "<episode>(.-<seasonnum>"..episodeNumber.."</seasonnum>.-)</episode>")
65     if not episode then
66         return false
67     end
68
69     _, _, title, artwork = string.find(episode, "<title>(.-)</title><screencap>(.-)</screencap>")
70     if not title then
71         return false
72     end
73
74     vlc.item.set_meta(vlc.item, "title", showName.. " S"..seasonNumber.."E"..episodeNumber.." - ".. title)
75     vlc.item.set_meta(vlc.item, "artwork_url", artwork)
76     vlc.item.set_meta(vlc.item, "episodeName", title)
77
78     return true
79 end