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.

158 lines
5.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. qualities,
  9. remove_start,
  10. )
  11. class WrzutaIE(InfoExtractor):
  12. IE_NAME = 'wrzuta.pl'
  13. _VALID_URL = r'https?://(?P<uploader>[0-9a-zA-Z]+)\.wrzuta\.pl/(?P<typ>film|audio)/(?P<id>[0-9a-zA-Z]+)'
  14. _TESTS = [{
  15. 'url': 'http://laboratoriumdextera.wrzuta.pl/film/aq4hIZWrkBu/nike_football_the_last_game',
  16. 'md5': '9e67e05bed7c03b82488d87233a9efe7',
  17. 'info_dict': {
  18. 'id': 'aq4hIZWrkBu',
  19. 'ext': 'mp4',
  20. 'title': 'Nike Football: The Last Game',
  21. 'duration': 307,
  22. 'uploader_id': 'laboratoriumdextera',
  23. 'description': 'md5:7fb5ef3c21c5893375fda51d9b15d9cd',
  24. },
  25. 'skip': 'Redirected to wrzuta.pl',
  26. }, {
  27. 'url': 'http://vexling.wrzuta.pl/audio/01xBFabGXu6/james_horner_-_into_the_na_39_vi_world_bonus',
  28. 'md5': 'f80564fb5a2ec6ec59705ae2bf2ba56d',
  29. 'info_dict': {
  30. 'id': '01xBFabGXu6',
  31. 'ext': 'mp3',
  32. 'title': 'James Horner - Into The Na\'vi World [Bonus]',
  33. 'description': 'md5:30a70718b2cd9df3120fce4445b0263b',
  34. 'duration': 95,
  35. 'uploader_id': 'vexling',
  36. },
  37. }]
  38. def _real_extract(self, url):
  39. mobj = re.match(self._VALID_URL, url)
  40. video_id = mobj.group('id')
  41. typ = mobj.group('typ')
  42. uploader = mobj.group('uploader')
  43. webpage, urlh = self._download_webpage_handle(url, video_id)
  44. if urlh.geturl() == 'http://www.wrzuta.pl/':
  45. raise ExtractorError('Video removed', expected=True)
  46. quality = qualities(['SD', 'MQ', 'HQ', 'HD'])
  47. audio_table = {'flv': 'mp3', 'webm': 'ogg', '???': 'mp3'}
  48. embedpage = self._download_json('http://www.wrzuta.pl/npp/embed/%s/%s' % (uploader, video_id), video_id)
  49. formats = []
  50. for media in embedpage['url']:
  51. fmt = media['type'].split('@')[0]
  52. if typ == 'audio':
  53. ext = audio_table.get(fmt, fmt)
  54. else:
  55. ext = fmt
  56. formats.append({
  57. 'format_id': '%s_%s' % (ext, media['quality'].lower()),
  58. 'url': media['url'],
  59. 'ext': ext,
  60. 'quality': quality(media['quality']),
  61. })
  62. self._sort_formats(formats)
  63. return {
  64. 'id': video_id,
  65. 'title': self._og_search_title(webpage),
  66. 'thumbnail': self._og_search_thumbnail(webpage),
  67. 'formats': formats,
  68. 'duration': int_or_none(embedpage['duration']),
  69. 'uploader_id': uploader,
  70. 'description': self._og_search_description(webpage),
  71. 'age_limit': embedpage.get('minimalAge', 0),
  72. }
  73. class WrzutaPlaylistIE(InfoExtractor):
  74. """
  75. this class covers extraction of wrzuta playlist entries
  76. the extraction process bases on following steps:
  77. * collect information of playlist size
  78. * download all entries provided on
  79. the playlist webpage (the playlist is split
  80. on two pages: first directly reached from webpage
  81. second: downloaded on demand by ajax call and rendered
  82. using the ajax call response)
  83. * in case size of extracted entries not reached total number of entries
  84. use the ajax call to collect the remaining entries
  85. """
  86. IE_NAME = 'wrzuta.pl:playlist'
  87. _VALID_URL = r'https?://(?P<uploader>[0-9a-zA-Z]+)\.wrzuta\.pl/playlista/(?P<id>[0-9a-zA-Z]+)'
  88. _TESTS = [{
  89. 'url': 'http://miromak71.wrzuta.pl/playlista/7XfO4vE84iR/moja_muza',
  90. 'playlist_mincount': 14,
  91. 'info_dict': {
  92. 'id': '7XfO4vE84iR',
  93. 'title': 'Moja muza',
  94. },
  95. }, {
  96. 'url': 'http://heroesf70.wrzuta.pl/playlista/6Nj3wQHx756/lipiec_-_lato_2015_muzyka_swiata',
  97. 'playlist_mincount': 144,
  98. 'info_dict': {
  99. 'id': '6Nj3wQHx756',
  100. 'title': 'Lipiec - Lato 2015 Muzyka Świata',
  101. },
  102. }, {
  103. 'url': 'http://miromak71.wrzuta.pl/playlista/7XfO4vE84iR',
  104. 'only_matching': True,
  105. }]
  106. def _real_extract(self, url):
  107. mobj = re.match(self._VALID_URL, url)
  108. playlist_id = mobj.group('id')
  109. uploader = mobj.group('uploader')
  110. webpage = self._download_webpage(url, playlist_id)
  111. playlist_size = int_or_none(self._html_search_regex(
  112. (r'<div[^>]+class=["\']playlist-counter["\'][^>]*>\d+/(\d+)',
  113. r'<div[^>]+class=["\']all-counter["\'][^>]*>(.+?)</div>'),
  114. webpage, 'playlist size', default=None))
  115. playlist_title = remove_start(
  116. self._og_search_title(webpage), 'Playlista: ')
  117. entries = []
  118. if playlist_size:
  119. entries = [
  120. self.url_result(entry_url)
  121. for _, entry_url in re.findall(
  122. r'<a[^>]+href=(["\'])(http.+?)\1[^>]+class=["\']playlist-file-page',
  123. webpage)]
  124. if playlist_size > len(entries):
  125. playlist_content = self._download_json(
  126. 'http://%s.wrzuta.pl/xhr/get_playlist_offset/%s' % (uploader, playlist_id),
  127. playlist_id,
  128. 'Downloading playlist JSON',
  129. 'Unable to download playlist JSON')
  130. entries.extend([
  131. self.url_result(entry['filelink'])
  132. for entry in playlist_content.get('files', []) if entry.get('filelink')])
  133. return self.playlist_result(entries, playlist_id, playlist_title)