Merge pull request #4735 from cg110/fix_web_server_mem_leak
[vuplus_xbmc] / tools / Fake Episode Maker / main.py
1 # -*- coding: utf-8 -*-
2
3 #       Copyright (C) 2008-2013 Team XBMC
4 #       http://xbmc.org
5 #
6 #   This Program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2, or (at your option)
9 #   any later version.
10 #
11 #   This Program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with XBMC; see the file COPYING.  If not, see
18 #   <http://www.gnu.org/licenses/>.
19 #
20
21 import urllib
22 import os
23 import openAnything
24 from xml.dom import minidom
25
26 def parseShow(seriesID, show_name):
27     safe_show_name = show_name.replace(":", "")
28     details_url = "http://thetvdb.com/api/EB49E8B9E78EBEE1/series/"+seriesID+"/all/en.xml"
29     details = openAnything.fetch(details_url)
30     details_xml = minidom.parseString(details['data'])
31     seasons = details_xml.getElementsByTagName("SeasonNumber")
32     episodes = details_xml.getElementsByTagName("EpisodeNumber")
33     # check to see if parent show path needs to be made
34     if not os.access(safe_show_name, os.F_OK):
35         os.makedirs(safe_show_name)
36     i = 0
37     for item in episodes:
38         season = seasons[i].firstChild.data
39         episode = item.firstChild.data
40         filename = safe_show_name+" S"+season+"E"+episode+".avi"
41         # seeif season path exists or not, and make it if not
42         if os.access(safe_show_name + "\\Season " + season, os.F_OK):
43             # just go ahead and create the file
44             file = open(safe_show_name + "\\Season " + season + "\\" + filename, "w")
45             file.close()
46         else:
47             os.makedirs(safe_show_name + "\\Season " + season)
48             file = open(safe_show_name + "\\Season " + season + "\\" + filename, "w")
49             file.close()
50         print "Creating %s" % filename
51         i = i + 1
52         
53 show_file = open("shows.txt")
54 shows = show_file.read().split("\n")
55 show_file.close()
56 for item in shows:
57     show_url = "http://thetvdb.com/api/GetSeries.php?"+urllib.urlencode({"seriesname":item})
58     print "Building "+item+"..."
59     show_xml = openAnything.fetch(show_url)
60     xmldoc = minidom.parseString(show_xml['data'])
61     node = xmldoc.getElementsByTagName("seriesid")
62     if ("node" in dir()):
63         seriesID = node[0].firstChild.data
64         parseShow(seriesID, item)
65     else:
66         print "Could not find any data for "+show_name+" on TVDB.\nURL: "+show_url