You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. unescapeHTML,
  7. )
  8. class TVN24IE(InfoExtractor):
  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. 'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'http://sport.tvn24.pl/pilka-nozna,105/ligue-1-kamil-glik-rozcial-glowe-monaco-tylko-remisuje-z-bastia,716522.html',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'http://tvn24bis.pl/poranek,146,m/gen-koziej-w-tvn24-bis-wracamy-do-czasow-zimnej-wojny,715660.html',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'https://www.tvn24.pl/magazyn-tvn24/angie-w-jednej-czwartej-polka-od-szarej-myszki-do-cesarzowej-europy,119,2158',
  31. 'only_matching': True,
  32. }]
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(url, video_id)
  36. title = self._og_search_title(webpage)
  37. def extract_json(attr, name, fatal=True):
  38. return self._parse_json(
  39. self._search_regex(
  40. r'\b%s=(["\'])(?P<json>(?!\1).+?)\1' % attr, webpage,
  41. name, group='json', fatal=fatal) or '{}',
  42. video_id, transform_source=unescapeHTML, fatal=fatal)
  43. quality_data = extract_json('data-quality', 'formats')
  44. formats = []
  45. for format_id, url in quality_data.items():
  46. formats.append({
  47. 'url': url,
  48. 'format_id': format_id,
  49. 'height': int_or_none(format_id.rstrip('p')),
  50. })
  51. self._sort_formats(formats)
  52. description = self._og_search_description(webpage)
  53. thumbnail = self._og_search_thumbnail(
  54. webpage, default=None) or self._html_search_regex(
  55. r'\bdata-poster=(["\'])(?P<url>(?!\1).+?)\1', webpage,
  56. 'thumbnail', group='url')
  57. share_params = extract_json(
  58. 'data-share-params', 'share params', fatal=False)
  59. if isinstance(share_params, dict):
  60. video_id = share_params.get('id') or video_id
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'description': description,
  65. 'thumbnail': thumbnail,
  66. 'formats': formats,
  67. }