telecaribe.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import traverse_obj
  4. class TelecaribePlayIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?play\.telecaribe\.co/(?P<id>[\w-]+)'
  6. _TESTS = [{
  7. 'url': 'https://www.play.telecaribe.co/breicok',
  8. 'info_dict': {
  9. 'id': 'breicok',
  10. 'title': 'Breicok',
  11. },
  12. 'playlist_count': 7,
  13. }, {
  14. 'url': 'https://www.play.telecaribe.co/si-fue-gol-de-yepes',
  15. 'info_dict': {
  16. 'id': 'si-fue-gol-de-yepes',
  17. 'title': 'Sí Fue Gol de Yepes',
  18. },
  19. 'playlist_count': 6,
  20. }, {
  21. 'url': 'https://www.play.telecaribe.co/ciudad-futura',
  22. 'info_dict': {
  23. 'id': 'ciudad-futura',
  24. 'title': 'Ciudad Futura',
  25. },
  26. 'playlist_count': 10,
  27. }, {
  28. 'url': 'https://www.play.telecaribe.co/live',
  29. 'info_dict': {
  30. 'id': 'live',
  31. 'title': r're:^Señal en vivo',
  32. 'live_status': 'is_live',
  33. 'ext': 'mp4',
  34. },
  35. 'params': {
  36. 'skip_download': 'Livestream',
  37. },
  38. }, {
  39. 'url': 'https://www.play.telecaribe.co/liveplus',
  40. 'info_dict': {
  41. 'id': 'liveplus',
  42. 'title': r're:^Señal en vivo Plus',
  43. 'live_status': 'is_live',
  44. 'ext': 'mp4',
  45. },
  46. 'params': {
  47. 'skip_download': 'Livestream',
  48. },
  49. 'skip': 'Geo-restricted to Colombia',
  50. }]
  51. def _download_player_webpage(self, webpage, display_id):
  52. page_id = self._search_regex(
  53. (r'window\.firstPageId\s*=\s*["\']([^"\']+)', r'<div[^>]+id\s*=\s*"pageBackground_([^"]+)'),
  54. webpage, 'page_id')
  55. props = self._download_json(self._search_regex(
  56. rf'<link[^>]+href\s*=\s*"([^"]+)"[^>]+id\s*=\s*"features_{page_id}"',
  57. webpage, 'json_props_url'), display_id)['props']['render']['compProps']
  58. return self._download_webpage(traverse_obj(props, (..., 'url'))[-1], display_id)
  59. def _get_clean_title(self, title):
  60. return re.sub(r'\s*\|\s*Telecaribe\s*VOD', '', title or '').strip() or None
  61. def _real_extract(self, url):
  62. display_id = self._match_id(url)
  63. webpage = self._download_webpage(url, display_id)
  64. player = self._download_player_webpage(webpage, display_id)
  65. livestream_url = self._search_regex(
  66. r'(?:let|const|var)\s+source\s*=\s*["\']([^"\']+)', player, 'm3u8 url', default=None)
  67. if not livestream_url:
  68. return self.playlist_from_matches(
  69. re.findall(r'<a[^>]+href\s*=\s*"([^"]+\.mp4)', player), display_id,
  70. self._get_clean_title(self._og_search_title(webpage)))
  71. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  72. livestream_url, display_id, 'mp4', live=True)
  73. return {
  74. 'id': display_id,
  75. 'title': self._get_clean_title(self._og_search_title(webpage)),
  76. 'formats': formats,
  77. 'subtitles': subtitles,
  78. 'is_live': True,
  79. }