periscope.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_iso8601,
  6. unescapeHTML,
  7. )
  8. class PeriscopeIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?periscope\.tv/w/(?P<id>[^/?#]+)'
  10. _TEST = {
  11. 'url': 'https://www.periscope.tv/w/aJUQnjY3MjA3ODF8NTYxMDIyMDl2zCg2pECBgwTqRpQuQD352EMPTKQjT4uqlM3cgWFA-g==',
  12. 'md5': '65b57957972e503fcbbaeed8f4fa04ca',
  13. 'info_dict': {
  14. 'id': '56102209',
  15. 'ext': 'mp4',
  16. 'title': 'Bec Boop - 🚠✈️🇬🇧 Fly above #London in Emirates Air Line cable car at night 🇬🇧✈️🚠 #BoopScope 🎀💗',
  17. 'timestamp': 1438978559,
  18. 'upload_date': '20150807',
  19. 'uploader': 'Bec Boop',
  20. 'uploader_id': '1465763',
  21. },
  22. 'skip': 'Expires in 24 hours',
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. replay = self._download_json(
  27. 'https://api.periscope.tv/api/v2/getAccessPublic?token=%s' % video_id, video_id)
  28. video_url = replay['replay_url']
  29. webpage = self._download_webpage(url, video_id)
  30. broadcast_data = self._parse_json(
  31. unescapeHTML(self._html_search_meta(
  32. 'broadcast-data', webpage, 'broadcast data', fatal=True)),
  33. video_id)
  34. broadcast = broadcast_data['broadcast']
  35. status = broadcast['status']
  36. uploader = broadcast.get('user_display_name') or broadcast_data.get('user', {}).get('display_name')
  37. uploader_id = broadcast.get('user_id') or broadcast_data.get('user', {}).get('id')
  38. title = '%s - %s' % (uploader, status) if uploader else status
  39. timestamp = parse_iso8601(broadcast.get('created_at'))
  40. thumbnails = [{
  41. 'url': broadcast[image],
  42. } for image in ('image_url', 'image_url_small') if broadcast.get(image)]
  43. return {
  44. 'id': broadcast.get('id') or video_id,
  45. 'url': video_url,
  46. 'ext': 'mp4',
  47. 'protocol': 'm3u8_native',
  48. 'title': title,
  49. 'timestamp': timestamp,
  50. 'uploader': uploader,
  51. 'uploader_id': uploader_id,
  52. 'thumbnails': thumbnails,
  53. }