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.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .youtube import YoutubeIE
  5. from ..utils import (
  6. js_to_json,
  7. qualities,
  8. determine_ext,
  9. )
  10. class Tele13IE(InfoExtractor):
  11. _VALID_URL = r'^http://(?:www\.)?t13\.cl/videos(?:/[^/]+)+/(?P<id>[\w-]+)'
  12. _TESTS = [
  13. {
  14. 'url': 'http://www.t13.cl/videos/actualidad/el-circulo-de-hierro-de-michelle-bachelet-en-su-regreso-a-la-moneda',
  15. 'md5': '4cb1fa38adcad8fea88487a078831755',
  16. 'info_dict': {
  17. 'id': 'el-circulo-de-hierro-de-michelle-bachelet-en-su-regreso-a-la-moneda',
  18. 'ext': 'mp4',
  19. 'title': 'El círculo de hierro de Michelle Bachelet en su regreso a La Moneda',
  20. },
  21. 'params': {
  22. # HTTP Error 404: Not Found
  23. 'skip_download': True,
  24. },
  25. },
  26. {
  27. 'url': 'http://www.t13.cl/videos/mundo/tendencias/video-captan-misteriosa-bola-fuego-cielos-bangkok',
  28. 'md5': '867adf6a3b3fef932c68a71d70b70946',
  29. 'info_dict': {
  30. 'id': 'rOoKv2OMpOw',
  31. 'ext': 'mp4',
  32. 'title': 'Shooting star seen on 7-Sep-2015',
  33. 'description': 'md5:7292ff2a34b2f673da77da222ae77e1e',
  34. 'uploader': 'Porjai Jaturongkhakun',
  35. 'upload_date': '20150906',
  36. 'uploader_id': 'UCnLY_3ezwNcDSC_Wc6suZxw',
  37. },
  38. 'add_ie': ['Youtube'],
  39. }
  40. ]
  41. def _real_extract(self, url):
  42. display_id = self._match_id(url)
  43. webpage = self._download_webpage(url, display_id)
  44. setup_js = self._search_regex(
  45. r"(?s)jwplayer\('player-vivo'\).setup\((\{.*?\})\)",
  46. webpage, 'setup code')
  47. sources = self._parse_json(self._search_regex(
  48. r'sources\s*:\s*(\[[^\]]+\])', setup_js, 'sources'),
  49. display_id, js_to_json)
  50. preference = qualities(['Móvil', 'SD', 'HD'])
  51. formats = []
  52. urls = []
  53. for f in sources:
  54. format_url = f['file']
  55. if format_url and format_url not in urls:
  56. ext = determine_ext(format_url)
  57. if ext == 'm3u8':
  58. formats.extend(self._extract_m3u8_formats(
  59. format_url, display_id, 'mp4', 'm3u8_native',
  60. m3u8_id='hls', fatal=False))
  61. elif YoutubeIE.suitable(format_url):
  62. return self.url_result(format_url, 'Youtube')
  63. else:
  64. formats.append({
  65. 'url': format_url,
  66. 'format_id': f.get('label'),
  67. 'preference': preference(f.get('label')),
  68. 'ext': ext,
  69. })
  70. urls.append(format_url)
  71. self._sort_formats(formats)
  72. return {
  73. 'id': display_id,
  74. 'title': self._search_regex(
  75. r'title\s*:\s*"([^"]+)"', setup_js, 'title'),
  76. 'description': self._html_search_meta(
  77. 'description', webpage, 'description'),
  78. 'thumbnail': self._search_regex(
  79. r'image\s*:\s*"([^"]+)"', setup_js, 'thumbnail', default=None),
  80. 'formats': formats,
  81. }