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.

81 lines
2.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. int_or_none,
  7. qualities,
  8. )
  9. class WrzutaIE(InfoExtractor):
  10. IE_NAME = 'wrzuta.pl'
  11. _VALID_URL = r'https?://(?P<uploader>[0-9a-zA-Z]+)\.wrzuta\.pl/(?P<typ>film|audio)/(?P<id>[0-9a-zA-Z]+)'
  12. _TESTS = [{
  13. 'url': 'http://laboratoriumdextera.wrzuta.pl/film/aq4hIZWrkBu/nike_football_the_last_game',
  14. 'md5': '9e67e05bed7c03b82488d87233a9efe7',
  15. 'info_dict': {
  16. 'id': 'aq4hIZWrkBu',
  17. 'ext': 'mp4',
  18. 'title': 'Nike Football: The Last Game',
  19. 'duration': 307,
  20. 'uploader_id': 'laboratoriumdextera',
  21. 'description': 'md5:7fb5ef3c21c5893375fda51d9b15d9cd',
  22. },
  23. }, {
  24. 'url': 'http://w729.wrzuta.pl/audio/9oXJqdcndqv/david_guetta_amp_showtek_ft._vassy_-_bad',
  25. 'md5': '1e546a18e1c22ac6e9adce17b8961ff5',
  26. 'info_dict': {
  27. 'id': '9oXJqdcndqv',
  28. 'ext': 'ogg',
  29. 'title': 'David Guetta & Showtek ft. Vassy - Bad',
  30. 'duration': 270,
  31. 'uploader_id': 'w729',
  32. 'description': 'md5:4628f01c666bbaaecefa83476cfa794a',
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. mobj = re.match(self._VALID_URL, url)
  37. video_id = mobj.group('id')
  38. typ = mobj.group('typ')
  39. uploader = mobj.group('uploader')
  40. webpage = self._download_webpage(url, video_id)
  41. quality = qualities(['SD', 'MQ', 'HQ', 'HD'])
  42. audio_table = {'flv': 'mp3', 'webm': 'ogg'}
  43. embedpage = self._download_json('http://www.wrzuta.pl/npp/embed/%s/%s' % (uploader, video_id), video_id)
  44. formats = []
  45. for media in embedpage['url']:
  46. if typ == 'audio':
  47. ext = audio_table[media['type'].split('@')[0]]
  48. else:
  49. ext = media['type'].split('@')[0]
  50. formats.append({
  51. 'format_id': '%s_%s' % (ext, media['quality'].lower()),
  52. 'url': media['url'],
  53. 'ext': ext,
  54. 'quality': quality(media['quality']),
  55. })
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'title': self._og_search_title(webpage),
  60. 'thumbnail': self._og_search_thumbnail(webpage),
  61. 'formats': formats,
  62. 'duration': int_or_none(embedpage['duration']),
  63. 'uploader_id': uploader,
  64. 'description': self._og_search_description(webpage),
  65. 'age_limit': embedpage.get('minimalAge', 0),
  66. }