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.

101 lines
3.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urlparse,
  8. xpath_with_ns,
  9. compat_str,
  10. )
  11. class LivestreamIE(InfoExtractor):
  12. IE_NAME = 'livestream'
  13. _VALID_URL = r'http://new\.livestream\.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
  14. _TEST = {
  15. 'url': 'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
  16. 'md5': '53274c76ba7754fb0e8d072716f2292b',
  17. 'info_dict': {
  18. 'id': '4719370',
  19. 'ext': 'mp4',
  20. 'title': 'Live from Webster Hall NYC',
  21. 'upload_date': '20121012',
  22. }
  23. }
  24. def _extract_video_info(self, video_data):
  25. video_url = video_data.get('progressive_url_hd') or video_data.get('progressive_url')
  26. return {
  27. 'id': compat_str(video_data['id']),
  28. 'url': video_url,
  29. 'ext': 'mp4',
  30. 'title': video_data['caption'],
  31. 'thumbnail': video_data['thumbnail_url'],
  32. 'upload_date': video_data['updated_at'].replace('-', '')[:8],
  33. }
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('id')
  37. event_name = mobj.group('event_name')
  38. webpage = self._download_webpage(url, video_id or event_name)
  39. if video_id is None:
  40. # This is an event page:
  41. config_json = self._search_regex(
  42. r'window.config = ({.*?});', webpage, 'window config')
  43. info = json.loads(config_json)['event']
  44. videos = [self._extract_video_info(video_data['data'])
  45. for video_data in info['feed']['data'] if video_data['type'] == 'video']
  46. return self.playlist_result(videos, info['id'], info['full_name'])
  47. else:
  48. og_video = self._og_search_video_url(webpage, 'player url')
  49. query_str = compat_urllib_parse_urlparse(og_video).query
  50. query = compat_urlparse.parse_qs(query_str)
  51. api_url = query['play_url'][0].replace('.smil', '')
  52. info = json.loads(self._download_webpage(
  53. api_url, video_id, 'Downloading video info'))
  54. return self._extract_video_info(info)
  55. # The original version of Livestream uses a different system
  56. class LivestreamOriginalIE(InfoExtractor):
  57. IE_NAME = 'livestream:original'
  58. _VALID_URL = r'https?://www\.livestream\.com/(?P<user>[^/]+)/video\?.*?clipId=(?P<id>.*?)(&|$)'
  59. _TEST = {
  60. 'url': 'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
  61. 'info_dict': {
  62. 'id': 'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
  63. 'ext': 'flv',
  64. 'title': 'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
  65. },
  66. 'params': {
  67. # rtmp
  68. 'skip_download': True,
  69. },
  70. }
  71. def _real_extract(self, url):
  72. mobj = re.match(self._VALID_URL, url)
  73. video_id = mobj.group('id')
  74. user = mobj.group('user')
  75. api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
  76. info = self._download_xml(api_url, video_id)
  77. item = info.find('channel').find('item')
  78. ns = {'media': 'http://search.yahoo.com/mrss'}
  79. thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
  80. # Remove the extension and number from the path (like 1.jpg)
  81. path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, 'path')
  82. return {
  83. 'id': video_id,
  84. 'title': item.find('title').text,
  85. 'url': 'rtmp://extondemand.livestream.com/ondemand',
  86. 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
  87. 'ext': 'flv',
  88. 'thumbnail': thumbnail_url,
  89. }