nhl.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import re
  2. import json
  3. import xml.etree.ElementTree
  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 NHLIE(InfoExtractor):
  12. IE_NAME = u'nhl.com'
  13. _VALID_URL = r'https?://video(?P<team>\.[^.]*)?\.nhl\.com/videocenter/console\?.*?(?<=[?&])id=(?P<id>\d+)'
  14. _TEST = {
  15. u'url': u'http://video.canucks.nhl.com/videocenter/console?catid=6?id=453614',
  16. u'file': u'453614.mp4',
  17. u'info_dict': {
  18. u'title': u'Quick clip: Weise 4-3 goal vs Flames',
  19. u'description': u'Dale Weise scores his first of the season to put the Canucks up 4-3.',
  20. u'duration': 18,
  21. u'upload_date': u'20131006',
  22. },
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. json_url = 'http://video.nhl.com/videocenter/servlets/playlist?ids=%s&format=json' % video_id
  28. info_json = self._download_webpage(json_url, video_id,
  29. u'Downloading info json')
  30. info_json = info_json.replace('\\\'', '\'')
  31. info = json.loads(info_json)[0]
  32. initial_video_url = info['publishPoint']
  33. data = compat_urllib_parse.urlencode({
  34. 'type': 'fvod',
  35. 'path': initial_video_url.replace('.mp4', '_sd.mp4'),
  36. })
  37. path_url = 'http://video.nhl.com/videocenter/servlets/encryptvideopath?' + data
  38. path_response = self._download_webpage(path_url, video_id,
  39. u'Downloading final video url')
  40. path_doc = xml.etree.ElementTree.fromstring(path_response)
  41. video_url = path_doc.find('path').text
  42. join = compat_urlparse.urljoin
  43. return {
  44. 'id': video_id,
  45. 'title': info['name'],
  46. 'url': video_url,
  47. 'ext': determine_ext(video_url),
  48. 'description': info['description'],
  49. 'duration': int(info['duration']),
  50. 'thumbnail': join(join(video_url, '/u/'), info['bigImage']),
  51. 'upload_date': unified_strdate(info['releaseDate'].split('.')[0]),
  52. }