]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bigflix.py
debian/control: Remove mplayer2 from recommends. (Closes: #841187)
[youtubedl] / youtube_dl / extractor / bigflix.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import base64
5 import re
6
7 from .common import InfoExtractor
8 from ..compat import compat_urllib_parse_unquote
9
10
11 class BigflixIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?bigflix\.com/.+/(?P<id>[0-9]+)'
13 _TESTS = [{
14 # 2 formats
15 'url': 'http://www.bigflix.com/Tamil-movies/Drama-movies/Madarasapatinam/16070',
16 'info_dict': {
17 'id': '16070',
18 'ext': 'mp4',
19 'title': 'Madarasapatinam',
20 'description': 'md5:9f0470b26a4ba8e824c823b5d95c2f6b',
21 'formats': 'mincount:2',
22 },
23 'params': {
24 'skip_download': True,
25 }
26 }, {
27 # multiple formats
28 'url': 'http://www.bigflix.com/Malayalam-movies/Drama-movies/Indian-Rupee/15967',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34
35 webpage = self._download_webpage(url, video_id)
36
37 title = self._html_search_regex(
38 r'<div[^>]+class=["\']pagetitle["\'][^>]*>(.+?)</div>',
39 webpage, 'title')
40
41 def decode_url(quoted_b64_url):
42 return base64.b64decode(compat_urllib_parse_unquote(
43 quoted_b64_url).encode('ascii')).decode('utf-8')
44
45 formats = []
46 for height, encoded_url in re.findall(
47 r'ContentURL_(\d{3,4})[pP][^=]+=([^&]+)', webpage):
48 video_url = decode_url(encoded_url)
49 f = {
50 'url': video_url,
51 'format_id': '%sp' % height,
52 'height': int(height),
53 }
54 if video_url.startswith('rtmp'):
55 f['ext'] = 'flv'
56 formats.append(f)
57
58 file_url = self._search_regex(
59 r'file=([^&]+)', webpage, 'video url', default=None)
60 if file_url:
61 video_url = decode_url(file_url)
62 if all(f['url'] != video_url for f in formats):
63 formats.append({
64 'url': decode_url(file_url),
65 })
66
67 self._sort_formats(formats)
68
69 description = self._html_search_meta('description', webpage)
70
71 return {
72 'id': video_id,
73 'title': title,
74 'description': description,
75 'formats': formats
76 }