00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 __title__ ="GiantBomb Query";
00032 __author__="R.D. Vaughan"
00033 __version__="0.11"
00034
00035
00036
00037
00038
00039 __usage_examples__='''
00040 Request giantbomb.py verison number:
00041 > ./giantbomb.py -v
00042 <grabber>
00043 <name>GiantBomb Query</name>
00044 <author>R.D. Vaughan</author>
00045 <thumbnail>giantbomb.png</thumbnail>
00046 <command>giantbomb.py</command>
00047 <type>games</type>
00048 <description>Search and Metadata downloads for Games from the giantbomb.com API</description>
00049 <version>v0.11</version>
00050 </grabber>
00051
00052 Request a list of matching game titles:
00053 > ./giantbomb.py -M "Terminator"
00054 <?xml version='1.0' encoding='UTF-8'?>
00055 <metadata>
00056 <item>
00057 <language>en</language>
00058 <title>Terminator Salvation</title>
00059 <inetref>24514</inetref>
00060 <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>
00061 <releasedate>2009-05-19</releasedate>
00062 <homepage>http://www.giantbomb.com/terminator-salvation/61-24514/</homepage>
00063 <images>
00064 <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"/>
00065 </images>
00066 <lastupdated>Thu, 04 Mar 2010 06:23:22 GMT</lastupdated>
00067 </item>
00068 ...
00069 <item>
00070 <language>en</language>
00071 <title>Terminator 2</title>
00072 <inetref>28832</inetref>
00073 <description>Terminator 2</description>
00074 <homepage>http://www.giantbomb.com/terminator-2/61-28832/</homepage>
00075 <lastupdated>Sat, 03 Oct 2009 00:21:31 GMT</lastupdated>
00076 </item>
00077 </metadata>
00078
00079 Request game details using a GiantBomb#:
00080 > ./giantbomb.py -D 24514
00081 <?xml version='1.0' encoding='UTF-8'?>
00082 <metadata>
00083 <item>
00084 <language>en</language>
00085 <title>Terminator Salvation</title>
00086 <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>
00087 <categories>
00088 <category type="genre" name="Shooter"/>
00089 <category type="genre" name="Vehicular Combat"/>
00090 <category type="genre" name="Action"/>
00091 </categories>
00092 <systems>
00093 <system>PC</system>
00094 <system>PlayStation 3</system>
00095 <system>Xbox 360</system>
00096 </systems>
00097 <studios>
00098 <studio name="GRIN"/>
00099 <studio name="Evolved Games"/>
00100 <studio name="Warner Bros. Interactive Entertainment Inc."/>
00101 </studios>
00102 <releasedate>2009-05-19</releasedate>
00103 <lastupdated>Thu, 04 Mar 2010 06:23:22 GMT</lastupdated>
00104 <inetref>24514</inetref>
00105 <homepage>http://www.giantbomb.com/terminator-salvation/61-24514/</homepage>
00106 <trailer/>
00107 <people>
00108 <person name="Rose McGowan" job="Actor"/>
00109 </people>
00110 <images>
00111 <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"/>
00112 <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"/>
00113 <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"/>
00114 <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"/>
00115 <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"/>
00116 <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"/>
00117 <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"/>
00118 <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"/>
00119 <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"/>
00120 <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"/>
00121 <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"/>
00122 </images>
00123 </item>
00124 </metadata>
00125 '''
00126
00127 import sys, os
00128 from optparse import OptionParser
00129 import re
00130 from string import capitalize
00131
00132
00133 class OutStreamEncoder(object):
00134 """Wraps a stream with an encoder
00135 """
00136 def __init__(self, outstream, encoding=None):
00137 self.out = outstream
00138 if not encoding:
00139 self.encoding = sys.getfilesystemencoding()
00140 else:
00141 self.encoding = encoding
00142
00143 def write(self, obj):
00144 """Wraps the output stream, encoding Unicode strings with the specified encoding"""
00145 if isinstance(obj, unicode):
00146 self.out.write(obj.encode(self.encoding))
00147 else:
00148 self.out.write(obj)
00149
00150 def __getattr__(self, attr):
00151 """Delegate everything but write to the stream"""
00152 return getattr(self.out, attr)
00153
00154 sys.stdout = OutStreamEncoder(sys.stdout)
00155 sys.stderr = OutStreamEncoder(sys.stderr)
00156
00157
00158 try:
00159 from StringIO import StringIO
00160 from lxml import etree
00161 except Exception, e:
00162 sys.stderr.write(u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
00163 sys.exit(1)
00164
00165
00166
00167
00168
00169 version = ''
00170 for digit in etree.LIBXML_VERSION:
00171 version+=str(digit)+'.'
00172 version = version[:-1]
00173 if version < '2.7.2':
00174 sys.stderr.write(u'''
00175 ! Error - The installed version of the "lxml" python library "libxml" version is too old.
00176 At least "libxml" version 2.7.2 must be installed. Your version is (%s).
00177 ''' % version)
00178 sys.exit(1)
00179
00180
00181
00182
00183
00184 try:
00185 import giantbomb.giantbomb_api as giantbomb_api
00186 except Exception, e:
00187 sys.stderr.write('''
00188 The subdirectory "giantbomb" containing the modules giantbomb_api.py (v0.1.0 or greater) and
00189 giantbomb_exceptions.py must have been installed with the MythTV gaming plugin.
00190 Error:(%s)
00191 ''' % e)
00192 sys.exit(1)
00193
00194 if giantbomb_api.__version__ < '0.1.0':
00195 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__)
00196 sys.exit(1)
00197
00198
00199 def main():
00200 """Gets game details using a GiantBomb# OR using a game name
00201 """
00202
00203 apikey = "b5883a902a8ed88b15ce21d07787c94fd6ad9f33"
00204
00205 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:\nhttp://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format")
00206
00207 parser.add_option( "-d", "--debug", action="store_true", default=False, dest="debug",
00208 help=u"Show debugging info")
00209 parser.add_option( "-u", "--usage", action="store_true", default=False, dest="usage",
00210 help=u"Display examples for executing the giantbomb script")
00211 parser.add_option( "-v", "--version", action="store_true", default=False, dest="version",
00212 help=u"Display version and author")
00213 parser.add_option( "-l", "--language", metavar="LANGUAGE", default=u'en', dest="language",
00214 help=u"Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.")
00215 parser.add_option( "-M", "--gamelist", action="store_true", default=False, dest="gamelist",
00216 help=u"Get matching Movie list")
00217 parser.add_option( "-D", "--gamedata", action="store_true", default=False, dest="gamedata",
00218 help=u"Get Movie metadata including graphic URLs")
00219
00220 opts, args = parser.parse_args()
00221
00222
00223 for index in range(len(args)):
00224 args[index] = unicode(args[index], 'utf8')
00225
00226 if opts.debug:
00227 sys.stdout.write("\nopts: %s\n" % opts)
00228 sys.stdout.write("\nargs: %s\n\n" % args)
00229
00230
00231 if opts.version:
00232 version = etree.XML(u'<grabber></grabber>')
00233 etree.SubElement(version, "name").text = __title__
00234 etree.SubElement(version, "author").text = __author__
00235 etree.SubElement(version, "thumbnail").text = 'giantbomb.png'
00236 etree.SubElement(version, "command").text = 'giantbomb.py'
00237 etree.SubElement(version, "type").text = 'games'
00238 etree.SubElement(version, "description").text = 'Search and Metadata downloads for Games from the giantbomb.com API'
00239 etree.SubElement(version, "version").text = __version__
00240 sys.stdout.write(etree.tostring(version, encoding='UTF-8', pretty_print=True))
00241 sys.exit(0)
00242
00243
00244 if opts.usage:
00245 sys.stdout.write(__usage_examples__)
00246 sys.exit(0)
00247
00248 if not len(args) == 1:
00249 sys.stderr.write("! Error: There must be one value for any option. Your options are (%s)\n" % (args))
00250 sys.exit(1)
00251
00252 if args[0] == u'':
00253 sys.stderr.write("! Error: There must be a non-empty argument, yours is empty.\n")
00254 sys.exit(1)
00255
00256 Queries = giantbomb_api.gamedbQueries(apikey,
00257 debug = opts.debug,
00258 )
00259
00260
00261 if opts.gamelist:
00262 Queries.gameSearch(args[0])
00263 elif opts.gamedata:
00264 Queries.gameData(args[0])
00265
00266 sys.exit(0)
00267
00268
00269 if __name__ == '__main__':
00270 main()