uol.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. clean_html,
  7. int_or_none,
  8. parse_duration,
  9. update_url_query,
  10. str_or_none,
  11. )
  12. class UOLIE(InfoExtractor):
  13. IE_NAME = 'uol.com.br'
  14. _VALID_URL = r'https?://(?:.+?\.)?uol\.com\.br/.*?(?:(?:mediaId|v)=|view/(?:[a-z0-9]+/)?|video(?:=|/(?:\d{4}/\d{2}/\d{2}/)?))(?P<id>\d+|[\w-]+-[A-Z0-9]+)'
  15. _TESTS = [{
  16. 'url': 'http://player.mais.uol.com.br/player_video_v3.swf?mediaId=15951931',
  17. 'md5': '25291da27dc45e0afb5718a8603d3816',
  18. 'info_dict': {
  19. 'id': '15951931',
  20. 'ext': 'mp4',
  21. 'title': 'Miss simpatia é encontrada morta',
  22. 'description': 'md5:3f8c11a0c0556d66daf7e5b45ef823b2',
  23. }
  24. }, {
  25. 'url': 'http://tvuol.uol.com.br/video/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326',
  26. 'md5': 'e41a2fb7b7398a3a46b6af37b15c00c9',
  27. 'info_dict': {
  28. 'id': '15954259',
  29. 'ext': 'mp4',
  30. 'title': 'Incêndio destrói uma das maiores casas noturnas de Londres',
  31. 'description': 'Em Londres, um incêndio destruiu uma das maiores boates da cidade. Não há informações sobre vítimas.',
  32. }
  33. }, {
  34. 'url': 'http://mais.uol.com.br/static/uolplayer/index.html?mediaId=15951931',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://mais.uol.com.br/view/15954259',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://noticias.band.uol.com.br/brasilurgente/video/2016/08/05/15951931/miss-simpatia-e-encontrada-morta.html',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://videos.band.uol.com.br/programa.asp?e=noticias&pr=brasil-urgente&v=15951931&t=Policia-desmonte-base-do-PCC-na-Cracolandia',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://mais.uol.com.br/view/cphaa0gl2x8r/incendio-destroi-uma-das-maiores-casas-noturnas-de-londres-04024E9A3268D4C95326',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://noticias.uol.com.br//videos/assistir.htm?video=rafaela-silva-inspira-criancas-no-judo-04024D983968D4C95326',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://mais.uol.com.br/view/e0qbgxid79uv/15275470',
  53. 'only_matching': True,
  54. }]
  55. _FORMATS = {
  56. '2': {
  57. 'width': 640,
  58. 'height': 360,
  59. },
  60. '5': {
  61. 'width': 1080,
  62. 'height': 720,
  63. },
  64. '6': {
  65. 'width': 426,
  66. 'height': 240,
  67. },
  68. '7': {
  69. 'width': 1920,
  70. 'height': 1080,
  71. },
  72. '8': {
  73. 'width': 192,
  74. 'height': 144,
  75. },
  76. '9': {
  77. 'width': 568,
  78. 'height': 320,
  79. },
  80. }
  81. def _real_extract(self, url):
  82. video_id = self._match_id(url)
  83. if not video_id.isdigit():
  84. embed_page = self._download_webpage('https://jsuol.com.br/c/tv/uol/embed/?params=[embed,%s]' % video_id, video_id)
  85. video_id = self._search_regex(r'mediaId=(\d+)', embed_page, 'media id')
  86. video_data = self._download_json(
  87. 'http://mais.uol.com.br/apiuol/v3/player/getMedia/%s.json' % video_id,
  88. video_id)['item']
  89. title = video_data['title']
  90. query = {
  91. 'ver': video_data.get('numRevision', 2),
  92. 'r': 'http://mais.uol.com.br',
  93. }
  94. formats = []
  95. for f in video_data.get('formats', []):
  96. f_url = f.get('url') or f.get('secureUrl')
  97. if not f_url:
  98. continue
  99. format_id = str_or_none(f.get('id'))
  100. fmt = {
  101. 'format_id': format_id,
  102. 'url': update_url_query(f_url, query),
  103. }
  104. fmt.update(self._FORMATS.get(format_id, {}))
  105. formats.append(fmt)
  106. self._sort_formats(formats)
  107. tags = []
  108. for tag in video_data.get('tags', []):
  109. tag_description = tag.get('description')
  110. if not tag_description:
  111. continue
  112. tags.append(tag_description)
  113. return {
  114. 'id': video_id,
  115. 'title': title,
  116. 'description': clean_html(video_data.get('desMedia')),
  117. 'thumbnail': video_data.get('thumbnail'),
  118. 'duration': int_or_none(video_data.get('durationSeconds')) or parse_duration(video_data.get('duration')),
  119. 'tags': tags,
  120. 'formats': formats,
  121. }