You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class MlbIE(InfoExtractor):
  5. _VALID_URL = r'http?://m\.mlb\.com/video/topic/[0-9]+/v(?P<id>n?\d+)/.*$'
  6. _TEST = {
  7. 'url': 'http://m.mlb.com/video/topic/81536970/v34496663/mianym-stanton-practices-for-the-home-run-derby',
  8. 'md5': u'd9c022c10d21f849f49c05ae12a8a7e9',
  9. 'info_dict': {
  10. 'id': '34496663',
  11. 'ext': 'mp4',
  12. 'format': 'mp4',
  13. 'description': "7/11/14: Giancarlo Stanton practices for the Home Run Derby prior to the game against the Mets",
  14. 'title': "Stanton prepares for Derby",
  15. },
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. video_id = mobj.group('id')
  20. webpage = self._download_webpage(url, video_id)
  21. title = self._og_search_title(webpage, default=video_id)
  22. description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)"/>', webpage, 'description', fatal=False)
  23. thumbnail = self._html_search_regex(r'<meta itemprop="image" (?:content|value)="(.*?)" />', webpage, 'image', fatal=False)
  24. # use the video_id to find the Media detail XML
  25. id_len = len(video_id)
  26. _mediadetail_url = 'http://m.mlb.com/gen/multimedia/detail/'+video_id[id_len-3]+'/'+video_id[id_len-2]+'/'+video_id[id_len-1]+'/'+video_id+'.xml'
  27. mediadetails = self._download_xml(_mediadetail_url, video_id, "Downloading media detail...")
  28. has1500K = 0
  29. has1200K = 0
  30. has600K = 0
  31. # loop through the list of url's and only get the highest quality MP4 content
  32. for element in mediadetails.findall('url'):
  33. scenario = element.attrib['playback_scenario']
  34. if scenario.startswith(u'FLASH'):
  35. if scenario.startswith(u'FLASH_1800K'):
  36. video_url = element.text
  37. # 1800K is the current highest quality video on MLB.com
  38. break
  39. else:
  40. if scenario.startswith(u'FLASH_1500K'):
  41. video_url = element.text
  42. has1500K = 1
  43. else:
  44. if (scenario.startswith(u'FLASH_1200K') and not has1500K):
  45. video_url = element.text
  46. has1200K = 1
  47. else:
  48. if (scenario.startswith(u'FLASH_600K') and not has1200K):
  49. video_url = element.text
  50. has600K = 1
  51. else:
  52. if (scenario.startswith(u'FLASH_300K') and not has600K):
  53. video_url = element.text
  54. return {
  55. 'id': video_id,
  56. 'url': video_url,
  57. 'extractor': 'mlb',
  58. 'webpage_url': url,
  59. 'title': title,
  60. 'ext': 'mp4',
  61. 'format': 'mp4',
  62. 'description': description,
  63. 'thumbnail': thumbnail,
  64. }