31 __title__ =
"GiantBomb Query";
32 __author__=
"R.D. Vaughan"
39 __usage_examples__=
'''
40 Request giantbomb.py verison number:
43 <name>GiantBomb Query</name>
44 <author>R.D. Vaughan</author>
45 <thumbnail>giantbomb.png</thumbnail>
46 <command>giantbomb.py</command>
48 <description>Search and Metadata downloads for Games from the giantbomb.com API</description>
49 <version>v0.11</version>
52 Request a list of matching game titles:
53 > ./giantbomb.py -M "Terminator"
54 <?xml version='1.0' encoding='UTF-8'?>
57 <language>en</language>
58 <title>Terminator Salvation</title>
59 <inetref>24514</inetref>
60 <description>Based on the “Terminator Salvation” film, the game offers players the chance to assume the role of John Connor, a soldier in the resistance, battling for survival against the far superior forces of Skynet.</description>
61 <releasedate>2009-05-19</releasedate>
62 <homepage>http://www.giantbomb.com/terminator-salvation/61-24514/</homepage>
64 <image type="coverart" url="http://media.giantbomb.com/uploads/1/13154/1110143-gb_super.png" thumb="http://media.giantbomb.com/uploads/1/13154/1110143-gb_thumb.png"/>
66 <lastupdated>Thu, 04 Mar 2010 06:23:22 GMT</lastupdated>
70 <language>en</language>
71 <title>Terminator 2</title>
72 <inetref>28832</inetref>
73 <description>Terminator 2</description>
74 <homepage>http://www.giantbomb.com/terminator-2/61-28832/</homepage>
75 <lastupdated>Sat, 03 Oct 2009 00:21:31 GMT</lastupdated>
79 Request game details using a GiantBomb#:
80 > ./giantbomb.py -D 24514
81 <?xml version='1.0' encoding='UTF-8'?>
84 <language>en</language>
85 <title>Terminator Salvation</title>
86 <description>Based on the “Terminator Salvation” film, the game offers players the chance to assume the role of John Connor, a soldier in the resistance, battling for survival against the far superior forces of Skynet.</description>
88 <category type="genre" name="Shooter"/>
89 <category type="genre" name="Vehicular Combat"/>
90 <category type="genre" name="Action"/>
94 <system>PlayStation 3</system>
95 <system>Xbox 360</system>
99 <studio name="Evolved Games"/>
100 <studio name="Warner Bros. Interactive Entertainment Inc."/>
102 <releasedate>2009-05-19</releasedate>
103 <lastupdated>Thu, 04 Mar 2010 06:23:22 GMT</lastupdated>
104 <inetref>24514</inetref>
105 <homepage>http://www.giantbomb.com/terminator-salvation/61-24514/</homepage>
108 <person name="Rose McGowan" job="Actor"/>
111 <image type="coverart" url="http://media.giantbomb.com/uploads/1/13154/1110143-gb_super.png" thumb="http://media.giantbomb.com/uploads/1/13154/1110143-gb_thumb.png"/>
112 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115329-terminatorsalvation_2009_08_23_12_36_06_46_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115329-terminatorsalvation_2009_08_23_12_36_06_46_thumb.jpg"/>
113 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115327-terminatorsalvation_2009_08_23_12_35_50_70_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115327-terminatorsalvation_2009_08_23_12_35_50_70_thumb.jpg"/>
114 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115326-terminatorsalvation_2009_08_23_12_35_40_07_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115326-terminatorsalvation_2009_08_23_12_35_40_07_thumb.jpg"/>
115 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115325-terminatorsalvation_2009_08_23_12_35_24_83_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115325-terminatorsalvation_2009_08_23_12_35_24_83_thumb.jpg"/>
116 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115324-terminatorsalvation_2009_08_23_12_34_32_33_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115324-terminatorsalvation_2009_08_23_12_34_32_33_thumb.jpg"/>
117 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115323-terminatorsalvation_2009_08_23_12_33_27_96_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115323-terminatorsalvation_2009_08_23_12_33_27_96_thumb.jpg"/>
118 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115322-terminatorsalvation_2009_08_23_12_33_19_64_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115322-terminatorsalvation_2009_08_23_12_33_19_64_thumb.jpg"/>
119 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115321-terminatorsalvation_2009_08_23_12_33_15_70_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115321-terminatorsalvation_2009_08_23_12_33_15_70_thumb.jpg"/>
120 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115319-terminatorsalvation_2009_08_23_12_32_28_68_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115319-terminatorsalvation_2009_08_23_12_32_28_68_thumb.jpg"/>
121 <image type="screenshot" url="http://media.giantbomb.com/uploads/0/8484/1115320-terminatorsalvation_2009_08_23_12_32_34_27_super.jpg" thumb="http://media.giantbomb.com/uploads/0/8484/1115320-terminatorsalvation_2009_08_23_12_32_34_27_thumb.jpg"/>
128 from optparse
import OptionParser
132 IS_PY2 = sys.version_info[0] == 2
136 from StringIO
import StringIO
138 from io
import StringIO
139 from lxml
import etree
140 except Exception
as e:
141 sys.stderr.write(
u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
149 stdio_type = io.TextIOWrapper
155 """Wraps a stream with an encoder
165 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
166 if isinstance(obj, unicode):
171 self.
out.buffer.write(obj)
174 """Delegate everything but write to the stream"""
175 return getattr(self.
out, attr)
176 if isinstance(sys.stdout, stdio_type):
186 for digit
in etree.LIBXML_VERSION:
187 version+=str(digit)+
'.'
188 version = version[:-1]
189 if version <
'2.7.2':
190 sys.stderr.write(
u'''
191 ! Error - The installed version of the "lxml" python library "libxml" version is too old.
192 At least "libxml" version 2.7.2 must be installed. Your version is (%s).
202 except Exception
as e:
204 The subdirectory "giantbomb" containing the modules giantbomb_api.py (v0.1.0 or greater) and
205 giantbomb_exceptions.py must have been installed with the MythTV gaming plugin.
210 if giantbomb_api.__version__ <
'0.1.0':
211 sys.stderr.write(
"\n! Error: Your current installed giantbomb_api.py version is (%s)\nYou must at least have version (0.1.0) or higher.\n" % giantbomb_api.__version__)
216 """Gets game details using a GiantBomb# OR using a game name
219 apikey =
"b5883a902a8ed88b15ce21d07787c94fd6ad9f33"
221 parser = OptionParser(usage=
u"%prog usage: giantbomb -hdluvMD [parameters]\n <game name or gameid number>\n\nFor details on using giantbomb from the command execute './giantbomb.py -u'. For details on the meaning of the XML element tags see the wiki page at:\nhttps://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format")
223 parser.add_option(
"-d",
"--debug", action=
"store_true", default=
False, dest=
"debug",
224 help=
u"Show debugging info")
225 parser.add_option(
"-u",
"--usage", action=
"store_true", default=
False, dest=
"usage",
226 help=
u"Display examples for executing the giantbomb script")
227 parser.add_option(
"-v",
"--version", action=
"store_true", default=
False, dest=
"version",
228 help=
u"Display version and author")
229 parser.add_option(
"-l",
"--language", metavar=
"LANGUAGE", default=
u'en', dest=
"language",
230 help=
u"Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.")
231 parser.add_option(
"-a",
"--area", metavar=
"AREA", default=
u"gb", dest=
"area",
232 help=
u"Select data that matches the specified country. This option is currently not used.")
233 parser.add_option(
"-M",
"--gamelist", action=
"store_true", default=
False, dest=
"gamelist",
234 help=
u"Get matching Movie list")
235 parser.add_option(
"-D",
"--gamedata", action=
"store_true", default=
False, dest=
"gamedata",
236 help=
u"Get Movie metadata including graphic URLs")
238 opts, args = parser.parse_args()
241 for index
in range(len(args)):
243 args[index] =
unicode(args[index],
'utf8')
245 args[index] = str(args[index])
247 sys.stdout.write(
"\nopts: %s\n" % opts)
248 sys.stdout.write(
"\nargs: %s\n\n" % args)
252 version = etree.XML(
u'<grabber></grabber>')
253 etree.SubElement(version,
"name").text = __title__
254 etree.SubElement(version,
"author").text = __author__
255 etree.SubElement(version,
"thumbnail").text =
'giantbomb.png'
256 etree.SubElement(version,
"command").text =
'giantbomb.py'
257 etree.SubElement(version,
"type").text =
'games'
258 etree.SubElement(version,
"description").text =
'Search and Metadata downloads for Games from the giantbomb.com API'
259 etree.SubElement(version,
"version").text = __version__
260 sys.stdout.write(etree.tostring(version, encoding=
'UTF-8', pretty_print=
True))
265 sys.stdout.write(__usage_examples__)
268 if not len(args) == 1:
269 sys.stderr.write(
"! Error: There must be one value for any option. Your options are (%s)\n" % (args))
273 sys.stderr.write(
"! Error: There must be a non-empty argument, yours is empty.\n")
282 Queries.gameSearch(args[0])
284 Queries.gameData(args[0])
289 if __name__ ==
'__main__':