tvn24.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. NO_DEFAULT,
  4. int_or_none,
  5. unescapeHTML,
  6. )
  7. class TVN24IE(InfoExtractor):
  8. _WORKING = False
  9. _VALID_URL = r'https?://(?:(?:[^/]+)\.)?tvn24(?:bis)?\.pl/(?:[^/]+/)*(?P<id>[^/]+)'
  10. _TESTS = [{
  11. 'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
  12. 'md5': 'fbdec753d7bc29d96036808275f2130c',
  13. 'info_dict': {
  14. 'id': '1584444',
  15. 'ext': 'mp4',
  16. 'title': '"Święta mają być wesołe, dlatego, ludziska, wszyscy pod jemiołę"',
  17. 'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości Szkła kontaktowego.',
  18. 'thumbnail': 're:https?://.*[.]jpeg',
  19. },
  20. }, {
  21. # different layout
  22. 'url': 'https://tvnmeteo.tvn24.pl/magazyny/maja-w-ogrodzie,13/odcinki-online,1,4,1,0/pnacza-ptaki-i-iglaki-odc-691-hgtv-odc-29,1771763.html',
  23. 'info_dict': {
  24. 'id': '1771763',
  25. 'ext': 'mp4',
  26. 'title': 'Pnącza, ptaki i iglaki (odc. 691 /HGTV odc. 29)',
  27. 'thumbnail': 're:https?://.*',
  28. },
  29. 'params': {
  30. 'skip_download': True,
  31. },
  32. }, {
  33. 'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'http://sport.tvn24.pl/pilka-nozna,105/ligue-1-kamil-glik-rozcial-glowe-monaco-tylko-remisuje-z-bastia,716522.html',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'http://tvn24bis.pl/poranek,146,m/gen-koziej-w-tvn24-bis-wracamy-do-czasow-zimnej-wojny,715660.html',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://www.tvn24.pl/magazyn-tvn24/angie-w-jednej-czwartej-polka-od-szarej-myszki-do-cesarzowej-europy,119,2158',
  43. 'only_matching': True,
  44. }]
  45. def _real_extract(self, url):
  46. display_id = self._match_id(url)
  47. webpage = self._download_webpage(url, display_id)
  48. title = self._og_search_title(
  49. webpage, default=None) or self._search_regex(
  50. r'<h\d+[^>]+class=["\']magazineItemHeader[^>]+>(.+?)</h',
  51. webpage, 'title')
  52. def extract_json(attr, name, default=NO_DEFAULT, fatal=True):
  53. return self._parse_json(
  54. self._search_regex(
  55. rf'\b{attr}=(["\'])(?P<json>(?!\1).+?)\1', webpage,
  56. name, group='json', default=default, fatal=fatal) or '{}',
  57. display_id, transform_source=unescapeHTML, fatal=fatal)
  58. quality_data = extract_json('data-quality', 'formats')
  59. formats = []
  60. for format_id, url in quality_data.items():
  61. formats.append({
  62. 'url': url,
  63. 'format_id': format_id,
  64. 'height': int_or_none(format_id.rstrip('p')),
  65. })
  66. description = self._og_search_description(webpage, default=None)
  67. thumbnail = self._og_search_thumbnail(
  68. webpage, default=None) or self._html_search_regex(
  69. r'\bdata-poster=(["\'])(?P<url>(?!\1).+?)\1', webpage,
  70. 'thumbnail', group='url')
  71. video_id = None
  72. share_params = extract_json(
  73. 'data-share-params', 'share params', default=None)
  74. if isinstance(share_params, dict):
  75. video_id = share_params.get('id')
  76. if not video_id:
  77. video_id = self._search_regex(
  78. r'data-vid-id=["\'](\d+)', webpage, 'video id',
  79. default=None) or self._search_regex(
  80. r',(\d+)\.html', url, 'video id', default=display_id)
  81. return {
  82. 'id': video_id,
  83. 'title': title,
  84. 'description': description,
  85. 'thumbnail': thumbnail,
  86. 'formats': formats,
  87. }