]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sharesix.py
f1ea9bdb208c79cb59c189c5a3b17a9e1dec460a
[youtubedl] / youtube_dl / extractor / sharesix.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_parse
8 from ..utils import (
9 parse_duration,
10 sanitized_Request,
11 )
12
13
14 class ShareSixIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?sharesix\.com/(?:f/)?(?P<id>[0-9a-zA-Z]+)'
16 _TESTS = [
17 {
18 'url': 'http://sharesix.com/f/OXjQ7Y6',
19 'md5': '9e8e95d8823942815a7d7c773110cc93',
20 'info_dict': {
21 'id': 'OXjQ7Y6',
22 'ext': 'mp4',
23 'title': 'big_buck_bunny_480p_surround-fix.avi',
24 'duration': 596,
25 'width': 854,
26 'height': 480,
27 },
28 },
29 {
30 'url': 'http://sharesix.com/lfrwoxp35zdd',
31 'md5': 'dd19f1435b7cec2d7912c64beeee8185',
32 'info_dict': {
33 'id': 'lfrwoxp35zdd',
34 'ext': 'flv',
35 'title': 'WhiteBoard___a_Mac_vs_PC_Parody_Cartoon.mp4.flv',
36 'duration': 65,
37 'width': 1280,
38 'height': 720,
39 },
40 }
41 ]
42
43 def _real_extract(self, url):
44 mobj = re.match(self._VALID_URL, url)
45 video_id = mobj.group('id')
46
47 fields = {
48 'method_free': 'Free'
49 }
50 post = compat_urllib_parse.urlencode(fields)
51 req = sanitized_Request(url, post)
52 req.add_header('Content-type', 'application/x-www-form-urlencoded')
53
54 webpage = self._download_webpage(req, video_id,
55 'Downloading video page')
56
57 video_url = self._search_regex(
58 r"var\slnk1\s=\s'([^']+)'", webpage, 'video URL')
59 title = self._html_search_regex(
60 r'(?s)<dt>Filename:</dt>.+?<dd>(.+?)</dd>', webpage, 'title')
61 duration = parse_duration(
62 self._search_regex(
63 r'(?s)<dt>Length:</dt>.+?<dd>(.+?)</dd>',
64 webpage,
65 'duration',
66 fatal=False
67 )
68 )
69
70 m = re.search(
71 r'''(?xs)<dt>Width\sx\sHeight</dt>.+?
72 <dd>(?P<width>\d+)\sx\s(?P<height>\d+)</dd>''',
73 webpage
74 )
75 width = height = None
76 if m:
77 width, height = int(m.group('width')), int(m.group('height'))
78
79 formats = [{
80 'format_id': 'sd',
81 'url': video_url,
82 'width': width,
83 'height': height,
84 }]
85
86 return {
87 'id': video_id,
88 'title': title,
89 'duration': duration,
90 'formats': formats,
91 }