r7.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. from .common import InfoExtractor
  2. from ..utils import int_or_none
  3. class R7IE(InfoExtractor):
  4. _WORKING = False
  5. _ENABLED = None # XXX: pass through to GenericIE
  6. _VALID_URL = r'''(?x)
  7. https?://
  8. (?:
  9. (?:[a-zA-Z]+)\.r7\.com(?:/[^/]+)+/idmedia/|
  10. noticias\.r7\.com(?:/[^/]+)+/[^/]+-|
  11. player\.r7\.com/video/i/
  12. )
  13. (?P<id>[\da-f]{24})
  14. '''
  15. _TESTS = [{
  16. 'url': 'http://videos.r7.com/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-/idmedia/54e7050b0cf2ff57e0279389.html',
  17. 'md5': '403c4e393617e8e8ddc748978ee8efde',
  18. 'info_dict': {
  19. 'id': '54e7050b0cf2ff57e0279389',
  20. 'ext': 'mp4',
  21. 'title': 'Policiais humilham suspeito à beira da morte: "Morre com dignidade"',
  22. 'description': 'md5:01812008664be76a6479aa58ec865b72',
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. 'duration': 98,
  25. 'like_count': int,
  26. 'view_count': int,
  27. },
  28. }, {
  29. 'url': 'http://esportes.r7.com/videos/cigano-manda-recado-aos-fas/idmedia/4e176727b51a048ee6646a1b.html',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://noticias.r7.com/record-news/video/representante-do-instituto-sou-da-paz-fala-sobre-fim-do-estatuto-do-desarmamento-5480fc580cf2285b117f438d/',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://player.r7.com/video/i/54e7050b0cf2ff57e0279389?play=true&video=http://vsh.r7.com/54e7050b0cf2ff57e0279389/ER7_RE_BG_MORTE_JOVENS_570kbps_2015-02-2009f17818-cc82-4c8f-86dc-89a66934e633-ATOS_copy.mp4&linkCallback=http://videos.r7.com/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-/idmedia/54e7050b0cf2ff57e0279389.html&thumbnail=http://vtb.r7.com/ER7_RE_BG_MORTE_JOVENS_570kbps_2015-02-2009f17818-cc82-4c8f-86dc-89a66934e633-thumb.jpg&idCategory=192&share=true&layout=full&full=true',
  36. 'only_matching': True,
  37. }]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. video = self._download_json(
  41. f'http://player-api.r7.com/video/i/{video_id}', video_id)
  42. title = video['title']
  43. formats = []
  44. media_url_hls = video.get('media_url_hls')
  45. if media_url_hls:
  46. formats.extend(self._extract_m3u8_formats(
  47. media_url_hls, video_id, 'mp4', entry_protocol='m3u8_native',
  48. m3u8_id='hls', fatal=False))
  49. media_url = video.get('media_url')
  50. if media_url:
  51. f = {
  52. 'url': media_url,
  53. 'format_id': 'http',
  54. }
  55. # m3u8 format always matches the http format, let's copy metadata from
  56. # one to another
  57. m3u8_formats = list(filter(
  58. lambda f: f.get('vcodec') != 'none', formats))
  59. if len(m3u8_formats) == 1:
  60. f_copy = m3u8_formats[0].copy()
  61. f_copy.update(f)
  62. f_copy['protocol'] = 'http'
  63. f = f_copy
  64. formats.append(f)
  65. description = video.get('description')
  66. thumbnail = video.get('thumb')
  67. duration = int_or_none(video.get('media_duration'))
  68. like_count = int_or_none(video.get('likes'))
  69. view_count = int_or_none(video.get('views'))
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'description': description,
  74. 'thumbnail': thumbnail,
  75. 'duration': duration,
  76. 'like_count': like_count,
  77. 'view_count': view_count,
  78. 'formats': formats,
  79. }
  80. class R7ArticleIE(InfoExtractor):
  81. _WORKING = False
  82. _ENABLED = None # XXX: pass through to GenericIE
  83. _VALID_URL = r'https?://(?:[a-zA-Z]+)\.r7\.com/(?:[^/]+/)+[^/?#&]+-(?P<id>\d+)'
  84. _TEST = {
  85. 'url': 'http://tv.r7.com/record-play/balanco-geral/videos/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-16102015',
  86. 'only_matching': True,
  87. }
  88. @classmethod
  89. def suitable(cls, url):
  90. return False if R7IE.suitable(url) else super().suitable(url)
  91. def _real_extract(self, url):
  92. display_id = self._match_id(url)
  93. webpage = self._download_webpage(url, display_id)
  94. video_id = self._search_regex(
  95. r'<div[^>]+(?:id=["\']player-|class=["\']embed["\'][^>]+id=["\'])([\da-f]{24})',
  96. webpage, 'video id')
  97. return self.url_result(f'http://player.r7.com/video/i/{video_id}', R7IE.ie_key())