tvn24.py 3.7 KB

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