tele13.py 3.2 KB

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