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.

52 lines
2.3 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import compat_urllib_parse_urlparse, compat_urlparse
  5. class LivestreamIE(InfoExtractor):
  6. _VALID_URL = r'http://new.livestream.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
  7. _TEST = {
  8. u'url': u'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
  9. u'file': u'4719370.mp4',
  10. u'md5': u'0d2186e3187d185a04b3cdd02b828836',
  11. u'info_dict': {
  12. u'title': u'Live from Webster Hall NYC',
  13. u'upload_date': u'20121012',
  14. }
  15. }
  16. def _extract_video_info(self, video_data):
  17. video_url = video_data.get('progressive_url_hd') or video_data.get('progressive_url')
  18. return {'id': video_data['id'],
  19. 'url': video_url,
  20. 'ext': 'mp4',
  21. 'title': video_data['caption'],
  22. 'thumbnail': video_data['thumbnail_url'],
  23. 'upload_date': video_data['updated_at'].replace('-','')[:8],
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. event_name = mobj.group('event_name')
  29. webpage = self._download_webpage(url, video_id or event_name)
  30. if video_id is None:
  31. # This is an event page:
  32. api_url = self._search_regex(r'event_design_eventId: \'(.+?)\'',
  33. webpage, 'api url')
  34. info = json.loads(self._download_webpage(api_url, event_name,
  35. u'Downloading event info'))
  36. videos = [self._extract_video_info(video_data['data'])
  37. for video_data in info['feed']['data'] if video_data['type'] == u'video']
  38. return self.playlist_result(videos, info['id'], info['full_name'])
  39. else:
  40. og_video = self._og_search_video_url(webpage, name=u'player url')
  41. query_str = compat_urllib_parse_urlparse(og_video).query
  42. query = compat_urlparse.parse_qs(query_str)
  43. api_url = query['play_url'][0].replace('.smil', '')
  44. info = json.loads(self._download_webpage(api_url, video_id,
  45. u'Downloading video info'))
  46. return self._extract_video_info(info)