crtvg.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import make_archive_id, remove_end
  4. class CrtvgIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?crtvg\.es/tvg/a-carta/(?P<id>[^/#?]+)'
  6. _TESTS = [{
  7. 'url': 'https://www.crtvg.es/tvg/a-carta/os-caimans-do-tea-5839623',
  8. 'md5': 'c0958d9ff90e4503a75544358758921d',
  9. 'info_dict': {
  10. 'id': 'os-caimans-do-tea-5839623',
  11. 'title': 'Os caimáns do Tea',
  12. 'ext': 'mp4',
  13. 'description': 'md5:f71cfba21ae564f0a6f415b31de1f842',
  14. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  15. '_old_archive_ids': ['crtvg 5839623'],
  16. },
  17. 'params': {'skip_download': 'm3u8'},
  18. }, {
  19. 'url': 'https://www.crtvg.es/tvg/a-carta/a-parabolica-love-story',
  20. 'md5': '9a47b95a1749db7b7eb3214904624584',
  21. 'info_dict': {
  22. 'id': 'a-parabolica-love-story',
  23. 'title': 'A parabólica / Trabuco, o can mordedor / Love Story',
  24. 'ext': 'mp4',
  25. 'description': 'md5:f71cfba21ae564f0a6f415b31de1f842',
  26. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  27. },
  28. 'params': {'skip_download': 'm3u8'},
  29. }]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. video_url = self._search_regex(r'var\s+url\s*=\s*["\']([^"\']+)', webpage, 'video url')
  34. formats = self._extract_m3u8_formats(video_url + '/playlist.m3u8', video_id, fatal=False)
  35. formats.extend(self._extract_mpd_formats(video_url + '/manifest.mpd', video_id, fatal=False))
  36. old_video_id = None
  37. if mobj := re.fullmatch(r'[^/#?]+-(?P<old_id>\d{7})', video_id):
  38. old_video_id = [make_archive_id(self, mobj.group('old_id'))]
  39. return {
  40. 'id': video_id,
  41. '_old_archive_ids': old_video_id,
  42. 'formats': formats,
  43. 'title': remove_end(self._html_search_meta(
  44. ['og:title', 'twitter:title'], webpage, 'title', default=None), ' | CRTVG'),
  45. 'description': self._html_search_meta('description', webpage, 'description', default=None),
  46. 'thumbnail': self._html_search_meta(['og:image', 'twitter:image'], webpage, 'thumbnail', default=None),
  47. }