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.

88 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. js_to_json,
  6. unescapeHTML,
  7. int_or_none,
  8. )
  9. class R7IE(InfoExtractor):
  10. _VALID_URL = r'''(?x)https?://
  11. (?:
  12. (?:[a-zA-Z]+)\.r7\.com(?:/[^/]+)+/idmedia/|
  13. noticias\.r7\.com(?:/[^/]+)+/[^/]+-|
  14. player\.r7\.com/video/i/
  15. )
  16. (?P<id>[\da-f]{24})
  17. '''
  18. _TESTS = [{
  19. 'url': 'http://videos.r7.com/policiais-humilham-suspeito-a-beira-da-morte-morre-com-dignidade-/idmedia/54e7050b0cf2ff57e0279389.html',
  20. 'md5': '403c4e393617e8e8ddc748978ee8efde',
  21. 'info_dict': {
  22. 'id': '54e7050b0cf2ff57e0279389',
  23. 'ext': 'mp4',
  24. 'title': 'Policiais humilham suspeito à beira da morte: "Morre com dignidade"',
  25. 'thumbnail': 're:^https?://.*\.jpg$',
  26. 'duration': 98,
  27. 'like_count': int,
  28. 'view_count': int,
  29. },
  30. }, {
  31. 'url': 'http://esportes.r7.com/videos/cigano-manda-recado-aos-fas/idmedia/4e176727b51a048ee6646a1b.html',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://noticias.r7.com/record-news/video/representante-do-instituto-sou-da-paz-fala-sobre-fim-do-estatuto-do-desarmamento-5480fc580cf2285b117f438d/',
  35. 'only_matching': True,
  36. }, {
  37. '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',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. webpage = self._download_webpage(
  43. 'http://player.r7.com/video/i/%s' % video_id, video_id)
  44. item = self._parse_json(js_to_json(self._search_regex(
  45. r'(?s)var\s+item\s*=\s*({.+?});', webpage, 'player')), video_id)
  46. title = unescapeHTML(item['title'])
  47. thumbnail = item.get('init', {}).get('thumbUri')
  48. duration = None
  49. statistics = item.get('statistics', {})
  50. like_count = int_or_none(statistics.get('likes'))
  51. view_count = int_or_none(statistics.get('views'))
  52. formats = []
  53. for format_key, format_dict in item['playlist'][0].items():
  54. src = format_dict.get('src')
  55. if not src:
  56. continue
  57. format_id = format_dict.get('format') or format_key
  58. if duration is None:
  59. duration = format_dict.get('duration')
  60. if '.f4m' in src:
  61. formats.extend(self._extract_f4m_formats(src, video_id, preference=-1))
  62. elif src.endswith('.m3u8'):
  63. formats.extend(self._extract_m3u8_formats(src, video_id, 'mp4', preference=-2))
  64. else:
  65. formats.append({
  66. 'url': src,
  67. 'format_id': format_id,
  68. })
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'title': title,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'like_count': like_count,
  76. 'view_count': view_count,
  77. 'formats': formats,
  78. }