]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wrzuta.py
debian/changelog: Annotate bugs being closed.
[youtubedl] / youtube_dl / extractor / wrzuta.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 qualities,
10 )
11
12
13 class WrzutaIE(InfoExtractor):
14 IE_NAME = 'wrzuta.pl'
15
16 _VALID_URL = r'https?://(?P<uploader>[0-9a-zA-Z]+)\.wrzuta\.pl/(?P<typ>film|audio)/(?P<id>[0-9a-zA-Z]+)'
17
18 _TESTS = [{
19 'url': 'http://laboratoriumdextera.wrzuta.pl/film/aq4hIZWrkBu/nike_football_the_last_game',
20 'md5': '9e67e05bed7c03b82488d87233a9efe7',
21 'info_dict': {
22 'id': 'aq4hIZWrkBu',
23 'ext': 'mp4',
24 'title': 'Nike Football: The Last Game',
25 'duration': 307,
26 'uploader_id': 'laboratoriumdextera',
27 'description': 'md5:7fb5ef3c21c5893375fda51d9b15d9cd',
28 },
29 }, {
30 'url': 'http://w729.wrzuta.pl/audio/9oXJqdcndqv/david_guetta_amp_showtek_ft._vassy_-_bad',
31 'md5': '1e546a18e1c22ac6e9adce17b8961ff5',
32 'info_dict': {
33 'id': '9oXJqdcndqv',
34 'ext': 'ogg',
35 'title': 'David Guetta & Showtek ft. Vassy - Bad',
36 'duration': 270,
37 'uploader_id': 'w729',
38 'description': 'md5:4628f01c666bbaaecefa83476cfa794a',
39 },
40 }]
41
42 def _real_extract(self, url):
43 mobj = re.match(self._VALID_URL, url)
44 video_id = mobj.group('id')
45 typ = mobj.group('typ')
46 uploader = mobj.group('uploader')
47
48 webpage = self._download_webpage(url, video_id)
49
50 quality = qualities(['SD', 'MQ', 'HQ', 'HD'])
51
52 audio_table = {'flv': 'mp3', 'webm': 'ogg'}
53
54 embedpage = self._download_json('http://www.wrzuta.pl/npp/embed/%s/%s' % (uploader, video_id), video_id)
55
56 formats = []
57 for media in embedpage['url']:
58 if typ == 'audio':
59 ext = audio_table[media['type'].split('@')[0]]
60 else:
61 ext = media['type'].split('@')[0]
62
63 formats.append({
64 'format_id': '%s_%s' % (ext, media['quality'].lower()),
65 'url': media['url'],
66 'ext': ext,
67 'quality': quality(media['quality']),
68 })
69
70 self._sort_formats(formats)
71
72 return {
73 'id': video_id,
74 'title': self._og_search_title(webpage),
75 'thumbnail': self._og_search_thumbnail(webpage),
76 'formats': formats,
77 'duration': int_or_none(embedpage['duration']),
78 'uploader_id': uploader,
79 'description': self._og_search_description(webpage),
80 'age_limit': embedpage.get('minimalAge', 0),
81 }