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.

98 lines
3.4 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"(?:file|url)\s*:\s*(\\?[\"'])(?P<url>http.+?)\1", unpacked,
  52. '%s url' % version, fatal=False, group='url')
  53. if not format_url:
  54. return
  55. f = {
  56. 'url': format_url,
  57. }
  58. m = re.search(
  59. r'<a[^>]+data-quality="(?P<format_id>[^"]+)"[^>]+href="[^"]+"[^>]+class="[^"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p',
  60. page)
  61. if m:
  62. f.update({
  63. 'format_id': m.group('format_id'),
  64. 'height': int(m.group('height')),
  65. })
  66. info_dict['formats'].append(f)
  67. if not info_dict['duration']:
  68. info_dict['duration'] = parse_duration(self._search_regex(
  69. r"duration\s*:\s*(\\?[\"'])(?P<duration>.+?)\1",
  70. unpacked, 'duration', fatal=False, group='duration'))
  71. extract_format(webpage, 'default')
  72. for href, resolution in re.findall(
  73. r'<a[^>]+data-quality="[^"]+"[^>]+href="([^"]+)"[^>]+class="quality-btn"[^>]*>([0-9]+p)',
  74. webpage):
  75. webpage = self._download_webpage(
  76. href, video_id, 'Downloading %s version information' % resolution, fatal=False)
  77. if not webpage:
  78. # Manually report warning because empty page is returned when
  79. # invalid version is requested.
  80. self.report_warning('Unable to download %s version information' % resolution)
  81. continue
  82. extract_format(webpage, resolution)
  83. self._sort_formats(formats)
  84. return info_dict