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.

121 lines
4.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. compat_urllib_parse,
  8. determine_ext,
  9. unified_strdate,
  10. )
  11. class NHLBaseInfoExtractor(InfoExtractor):
  12. @staticmethod
  13. def _fix_json(json_string):
  14. return json_string.replace('\\\'', '\'')
  15. def _extract_video(self, info):
  16. video_id = info['id']
  17. self.report_extraction(video_id)
  18. initial_video_url = info['publishPoint']
  19. data = compat_urllib_parse.urlencode({
  20. 'type': 'fvod',
  21. 'path': initial_video_url.replace('.mp4', '_sd.mp4'),
  22. })
  23. path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
  24. path_doc = self._download_xml(
  25. path_url, video_id, 'Downloading final video url')
  26. video_url = path_doc.find('path').text
  27. join = compat_urlparse.urljoin
  28. return {
  29. 'id': video_id,
  30. 'title': info['name'],
  31. 'url': video_url,
  32. 'ext': determine_ext(video_url),
  33. 'description': info['description'],
  34. 'duration': int(info['duration']),
  35. 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
  36. 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
  37. }
  38. class NHLIE(NHLBaseInfoExtractor):
  39. IE_NAME = 'nhl.com'
  40. _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console\?.*?(?:[?&])id=(?P<id>[0-9]+)'
  41. _TEST = {
  42. 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
  43. 'info_dict': {
  44. 'id': '453614',
  45. 'ext': 'mp4',
  46. 'title': 'Quick clip: Weise 4-3 goal vs Flames',
  47. 'description': 'Dale Weise scores his first of the season to put the Canucks up 4-3.',
  48. 'duration': 18,
  49. 'upload_date': '20131006',
  50. },
  51. }
  52. def _real_extract(self, url):
  53. mobj = re.match(self._VALID_URL, url)
  54. video_id = mobj.group('id')
  55. json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
  56. data = self._download_json(
  57. json_url, video_id, transform_source=self._fix_json)
  58. return self._extract_video(data[0])
  59. class NHLVideocenterIE(NHLBaseInfoExtractor):
  60. IE_NAME = 'nhl.com:videocenter'
  61. IE_DESC = 'NHL videocenter category'
  62. _VALID_URL = r'https?://video\.(?P<team>[^.]*)\.nhl\.com/videocenter/(console\?.*?catid=(?P<catid>[0-9]+)(?![&?]id=).*?)?$'
  63. _TEST = {
  64. 'url': 'http://video.canucks.nhl.com/videocenter/console?catid=999',
  65. 'info_dict': {
  66. 'id': '999',
  67. 'title': 'Highlights',
  68. },
  69. 'playlist_count': 12,
  70. }
  71. def _real_extract(self, url):
  72. mobj = re.match(self._VALID_URL, url)
  73. team = mobj.group('team')
  74. webpage = self._download_webpage(url, team)
  75. cat_id = self._search_regex(
  76. [r'var defaultCatId = "(.+?)";',
  77. r'{statusIndex:0,index:0,.*?id:(.*?),'],
  78. webpage, 'category id')
  79. playlist_title = self._html_search_regex(
  80. r'tab0"[^>]*?>(.*?)</td>',
  81. webpage, 'playlist title', flags=re.DOTALL).lower().capitalize()
  82. data = compat_urllib_parse.urlencode({
  83. 'cid': cat_id,
  84. # This is the default value
  85. 'count': 12,
  86. 'ptrs': 3,
  87. 'format': 'json',
  88. })
  89. path = '/videocenter/servlets/browse?' + data
  90. request_url = compat_urlparse.urljoin(url, path)
  91. response = self._download_webpage(request_url, playlist_title)
  92. response = self._fix_json(response)
  93. if not response.strip():
  94. self._downloader.report_warning(u'Got an empty reponse, trying '
  95. 'adding the "newvideos" parameter')
  96. response = self._download_webpage(request_url + '&newvideos=true',
  97. playlist_title)
  98. response = self._fix_json(response)
  99. videos = json.loads(response)
  100. return {
  101. '_type': 'playlist',
  102. 'title': playlist_title,
  103. 'id': cat_id,
  104. 'entries': [self._extract_video(v) for v in videos],
  105. }