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.

76 lines
2.7 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>[^/]+)\.html'
  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:http://.*[.]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. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(url, video_id)
  33. title = self._og_search_title(webpage)
  34. def extract_json(attr, name, fatal=True):
  35. return self._parse_json(
  36. self._search_regex(
  37. r'\b%s=(["\'])(?P<json>(?!\1).+?)\1' % attr, webpage,
  38. name, group='json', fatal=fatal) or '{}',
  39. video_id, transform_source=unescapeHTML, fatal=fatal)
  40. quality_data = extract_json('data-quality', 'formats')
  41. formats = []
  42. for format_id, url in quality_data.items():
  43. formats.append({
  44. 'url': url,
  45. 'format_id': format_id,
  46. 'height': int_or_none(format_id.rstrip('p')),
  47. })
  48. self._sort_formats(formats)
  49. description = self._og_search_description(webpage)
  50. thumbnail = self._og_search_thumbnail(
  51. webpage, default=None) or self._html_search_regex(
  52. r'\bdata-poster=(["\'])(?P<url>(?!\1).+?)\1', webpage,
  53. 'thumbnail', group='url')
  54. share_params = extract_json(
  55. 'data-share-params', 'share params', fatal=False)
  56. if isinstance(share_params, dict):
  57. video_id = share_params.get('id') or video_id
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'description': description,
  62. 'thumbnail': thumbnail,
  63. 'formats': formats,
  64. }