PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin.video.vodie/resources/lib/TVSeriesUtil.py

http://xbmc-vodie.googlecode.com/
Python | 223 lines | 177 code | 34 blank | 12 comment | 26 complexity | 3985737b068a22308cf9a3488f8acc6c MD5 | raw file
Possible License(s): AGPL-1.0
  1. #!/usr/bin/python
  2. """
  3. VODie
  4. kitesurfing@kitesurfing.ie
  5. """
  6. import re
  7. import sys
  8. from BeautifulSoup import SoupStrainer, MinimalSoup as BeautifulSoup, BeautifulStoneSoup
  9. import urllib, urllib2, cookielib
  10. import time
  11. KNOWN_TV3_SHOWS_URL = 'http://xbmc-vodie.googlecode.com/svn/trunk/plugin.video.vodie/xml/tv3shows.json'
  12. GET_SERIES_URL = 'http://www.thetvdb.com/api/GetSeries.php?seriesname=%s'
  13. SERIE_DETAILS_URL = 'http://cache.thetvdb.com/api/1D62F2F90030C444/series/%s/banners'
  14. BANNER_URL = 'http://cache.thetvdb.com/banners/%s'
  15. KNOWN_SHOWS = {
  16. "Castle" : {"TVDBName":"Castle (2009)",},
  17. }
  18. IGNORE_SHOWS = ["The Daily Show",
  19. "Dermot's Secret Garden",
  20. "Champions League Magazine",
  21. "Cheltenham Festival",
  22. "About the House",
  23. "Against The Head",
  24. "Airtricity League Live: St Patrick's Athletic V Bohemians",
  25. "The All Ireland Talent Show",
  26. "The All Ireland Talent Show - Backstage",
  27. "The All Ireland Talent Show - Results",
  28. "Animal Clinic",
  29. "Anonymous",
  30. "Eco Eye",
  31. "Election 2011",
  32. "Elev8",
  33. "The Frontline",
  34. "Families in the Wild",
  35. "Four Live",
  36. "From Here to Maternity",
  37. "Give Up Yer Aul Sins",
  38. "Grubz Up!",
  39. "Hill Walks",
  40. "How to Create a Garden",
  41. "hubble",
  42. "International Soccer Friendly Highlights: Republic of Ireland v Uruguay",
  43. "iWitness",
  44. "Katherine Lynch's Wagons' Den",
  45. "Last Lioness",
  46. "Leaders' Questions",
  47. "League Sunday",
  48. "Living The Wildlife",
  49. "Lotto",
  50. "The Late Late Show",
  51. "Magners League: Munster v Leinster",
  52. "Magners League: Munster v Newport-Gwent Dragons",
  53. "Magners League: Newport v Leinster",
  54. "Mass for St Patrick's Day",
  55. "Mass on Sunday",
  56. "MasterChef: The Professionals",
  57. "Mattie",
  58. "MNS",
  59. "The Meaning of Life with Gay Byrne",
  60. "The Mountain",
  61. "Nationwide",
  62. "Nine News",
  63. "News on Two and World Forecast",
  64. "News2Day",
  65. "Nuacht and News with Signing",
  66. "National Lottery Skyfest",
  67. "Neven Maguire: Home Chef",
  68. "Now That's What You Called News 2010",
  69. "Oireachtas Report",
  70. "One News",
  71. "Octonauts",
  72. "Off the Rails - On Tour",
  73. "Prime Time",
  74. "Pro Box Live",
  75. "Red",
  76. "Republic of Telly",
  77. "The Restaurant",
  78. "The Rumour Room",
  79. "RED Radar",
  80. "Roomers",
  81. "Scannal",
  82. "Services of the Word",
  83. "Six Nations Championship: France v Wales",
  84. "Six Nations Championship: Ireland v England",
  85. "Six Nations Championship: Rugby Extra",
  86. "Six Nations Championship: Scotland v Italy",
  87. "Six One News",
  88. "St Patrick's Day Festival Parade",
  89. "St Patrick's Day Highlights",
  90. "StoryLand: Free House",
  91. "StoryLand: Lucky Run",
  92. "StoryLand: Rent A Friend Promo",
  93. "StoryLand: Street Cobra",
  94. "StoryLand: The Last Security Man",
  95. "StoryLand: The Last Security Man promo",
  96. "StoryLand: The Masterplan",
  97. "StoryLand: The Outlaw Concy Ryan",
  98. "StoryLand: WartGirl",
  99. "StoryLand: Rent A Friend",
  100. "Six Nations U20's Internationals: Ireland v England",
  101. "Stuck for Words",
  102. "The Saturday Night Show",
  103. "The Week in Politics",
  104. "Val Falvey T.D.",
  105. "Wagons' Den",
  106. "Winning Streak"
  107. ]
  108. class Util:
  109. def saveSerieDetail(self, serieName, serie):
  110. if not serieName in KNOWN_SHOWS.keys():
  111. KNOWN_SHOWS[serieName] = {"TVDBName":serieName}
  112. KNOWN_SHOWS[serieName]['id'] = str(serie.id.string)
  113. KNOWN_SHOWS[serieName]['banner'] = str(BANNER_URL % (serie.banner.string))
  114. print 'IMDB'
  115. print str(serie.imdb_id.string)
  116. KNOWN_SHOWS[serieName]['IMDB_ID'] = str(serie.imdb_id.string)
  117. #self.getDetailsForSerieByID(serieName, KNOWN_SHOWS[serieName]['id'])
  118. def getSeriesDetailsByName(self, serieName):
  119. if serieName in IGNORE_SHOWS:
  120. return None
  121. print 'checking: ' + serieName
  122. if serieName in KNOWN_SHOWS.keys():
  123. url = GET_SERIES_URL % (urllib.quote(KNOWN_SHOWS[serieName]['TVDBName']))
  124. else:
  125. url = GET_SERIES_URL % (urllib.quote(serieName))
  126. try:
  127. # Change the User Agent
  128. USER_AGENT = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10'
  129. cj = cookielib.CookieJar()
  130. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  131. req = urllib2.Request(url)
  132. req.add_header('User-Agent', USER_AGENT)
  133. resp = opener.open(req)
  134. soup = BeautifulStoneSoup(resp.read())
  135. resp.close()
  136. if len(soup.findAll('series')) == 1:
  137. self.saveSerieDetail(serieName, soup.series)
  138. else:
  139. for serie in soup.findAll('series'):
  140. if serie.seriesname.string == serieName:
  141. self.saveSerieDetail(serieName, serie)
  142. if serieName in KNOWN_SHOWS.keys():
  143. return KNOWN_SHOWS[serieName]
  144. return None
  145. except:
  146. print 'Error: ' + url
  147. return None
  148. def getDetailsForSerieByID(self, serieName, serieID):
  149. url = SERIE_DETAILS_URL % (urllib.quote(serieID))
  150. try:
  151. # Change the User Agent
  152. USER_AGENT = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10'
  153. cj = cookielib.CookieJar()
  154. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  155. req = urllib2.Request(url)
  156. req.add_header('User-Agent', USER_AGENT)
  157. resp = opener.open(req)
  158. soup = BeautifulStoneSoup(resp.read())
  159. resp.close()
  160. for banner in soup.banners.findAll('banner'):
  161. if banner.language.string == 'en':
  162. if not 'Fanart' in KNOWN_SHOWS[serieName].keys() and banner.bannertype.string == 'fanart':
  163. KNOWN_SHOWS[serieName]['Fanart'] = str(BANNER_URL % (banner.bannerpath.string))
  164. if banner.thumbnailpath:
  165. KNOWN_SHOWS[serieName]['FanartThumb'] = str(BANNER_URL % (banner.thumbnailpath.string))
  166. elif not 'Poster' in KNOWN_SHOWS[serieName].keys() and banner.bannertype.string == 'poster':
  167. KNOWN_SHOWS[serieName]['Poster'] = str(BANNER_URL % (banner.bannerpath.string))
  168. if banner.thumbnailpath:
  169. KNOWN_SHOWS[serieName]['PosterThumb'] = str(BANNER_URL % (banner.thumbnailpath.string))
  170. elif not 'Season' in KNOWN_SHOWS[serieName].keys() and banner.bannertype.string == 'season':
  171. KNOWN_SHOWS[serieName]['Season'] = str(BANNER_URL % (banner.bannerpath.string))
  172. if banner.thumbnailpath:
  173. KNOWN_SHOWS[serieName]['SeasonThumb'] = str(BANNER_URL % (banner.thumbnailpath.string))
  174. elif not 'Series' in KNOWN_SHOWS[serieName].keys() and banner.bannertype.string == 'series':
  175. KNOWN_SHOWS[serieName]['Series'] = str(BANNER_URL % (banner.bannerpath.string))
  176. if banner.thumbnailpath:
  177. KNOWN_SHOWS[serieName]['SeriesThumb'] = str(BANNER_URL % (banner.thumbnailpath.string))
  178. return KNOWN_SHOWS[serieName]
  179. except:
  180. print 'Error: ' + url
  181. return None
  182. if __name__ == '__main__':
  183. #print KNOWN_SHOWS
  184. print Util().getSeriesDetailsByName('Home and Away')
  185. time.sleep(5)
  186. #print Util().getSeriesDetailsByName('Castle')
  187. #print Util().getSeriesDetailsByName('Casualty')
  188. print Util().getSeriesDetailsByName('Desperate Housewives')
  189. #print KNOWN_SHOWS