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.

96 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. decode_packed_codes,
  7. ExtractorError,
  8. parse_duration
  9. )
  10. class CDAIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:(?:www\.)?cda\.pl/video|ebd\.cda\.pl/[0-9]+x[0-9]+)/(?P<id>[0-9a-z]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.cda.pl/video/5749950c',
  14. 'md5': '6f844bf51b15f31fae165365707ae970',
  15. 'info_dict': {
  16. 'id': '5749950c',
  17. 'ext': 'mp4',
  18. 'height': 720,
  19. 'title': 'Oto dlaczego przed zakrętem należy zwolnić.',
  20. 'duration': 39
  21. }
  22. }, {
  23. 'url': 'http://www.cda.pl/video/57413289',
  24. 'md5': 'a88828770a8310fc00be6c95faf7f4d5',
  25. 'info_dict': {
  26. 'id': '57413289',
  27. 'ext': 'mp4',
  28. 'title': 'Lądowanie na lotnisku na Maderze',
  29. 'duration': 137
  30. }
  31. }, {
  32. 'url': 'http://ebd.cda.pl/0x0/5749950c',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage('http://ebd.cda.pl/0x0/' + video_id, video_id)
  38. if 'Ten film jest dostępny dla użytkowników premium' in webpage:
  39. raise ExtractorError('This video is only available for premium users.', expected=True)
  40. title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title')
  41. formats = []
  42. info_dict = {
  43. 'id': video_id,
  44. 'title': title,
  45. 'formats': formats,
  46. 'duration': None,
  47. }
  48. def extract_format(page, version):
  49. unpacked = decode_packed_codes(page)
  50. format_url = self._search_regex(
  51. r"url:\\'(.+?)\\'", unpacked, '%s url' % version, fatal=False)
  52. if not format_url:
  53. return
  54. f = {
  55. 'url': format_url,
  56. }
  57. m = re.search(
  58. r'<a[^>]+data-quality="(?P<format_id>[^"]+)"[^>]+href="[^"]+"[^>]+class="[^"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p',
  59. page)
  60. if m:
  61. f.update({
  62. 'format_id': m.group('format_id'),
  63. 'height': int(m.group('height')),
  64. })
  65. info_dict['formats'].append(f)
  66. if not info_dict['duration']:
  67. info_dict['duration'] = parse_duration(self._search_regex(
  68. r"duration:\\'(.+?)\\'", unpacked, 'duration', fatal=False))
  69. extract_format(webpage, 'default')
  70. for href, resolution in re.findall(
  71. r'<a[^>]+data-quality="[^"]+"[^>]+href="([^"]+)"[^>]+class="quality-btn"[^>]*>([0-9]+p)',
  72. webpage):
  73. webpage = self._download_webpage(
  74. href, video_id, 'Downloading %s version information' % resolution, fatal=False)
  75. if not webpage:
  76. # Manually report warning because empty page is returned when
  77. # invalid version is requested.
  78. self.report_warning('Unable to download %s version information' % resolution)
  79. continue
  80. extract_format(webpage, resolution)
  81. self._sort_formats(formats)
  82. return info_dict