]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/moevideo.py
Annotate changelog with bugs closed.
[youtubedl] / youtube_dl / extractor / moevideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8 from ..compat import (
9 compat_urllib_parse,
10 compat_urllib_request,
11 )
12 from ..utils import (
13 ExtractorError,
14 int_or_none,
15 )
16
17
18 class MoeVideoIE(InfoExtractor):
19 IE_DESC = 'LetitBit video services: moevideo.net, playreplay.net and videochart.net'
20 _VALID_URL = r'''(?x)
21 https?://(?P<host>(?:www\.)?
22 (?:(?:moevideo|playreplay|videochart)\.net))/
23 (?:video|framevideo)/(?P<id>[0-9]+\.[0-9A-Za-z]+)'''
24 _API_URL = 'http://api.letitbit.net/'
25 _API_KEY = 'tVL0gjqo5'
26 _TESTS = [
27 {
28 'url': 'http://moevideo.net/video/00297.0036103fe3d513ef27915216fd29',
29 'md5': '129f5ae1f6585d0e9bb4f38e774ffb3a',
30 'info_dict': {
31 'id': '00297.0036103fe3d513ef27915216fd29',
32 'ext': 'flv',
33 'title': 'Sink cut out machine',
34 'description': 'md5:f29ff97b663aefa760bf7ca63c8ca8a8',
35 'thumbnail': 're:^https?://.*\.jpg$',
36 'width': 540,
37 'height': 360,
38 'duration': 179,
39 'filesize': 17822500,
40 }
41 },
42 {
43 'url': 'http://playreplay.net/video/77107.7f325710a627383d40540d8e991a',
44 'md5': '74f0a014d5b661f0f0e2361300d1620e',
45 'info_dict': {
46 'id': '77107.7f325710a627383d40540d8e991a',
47 'ext': 'flv',
48 'title': 'Operacion Condor.',
49 'description': 'md5:7e68cb2fcda66833d5081c542491a9a3',
50 'thumbnail': 're:^https?://.*\.jpg$',
51 'width': 480,
52 'height': 296,
53 'duration': 6027,
54 'filesize': 588257923,
55 },
56 'skip': 'Video has been removed',
57 },
58 ]
59
60 def _real_extract(self, url):
61 mobj = re.match(self._VALID_URL, url)
62 video_id = mobj.group('id')
63
64 webpage = self._download_webpage(
65 'http://%s/video/%s' % (mobj.group('host'), video_id),
66 video_id, 'Downloading webpage')
67
68 title = self._og_search_title(webpage)
69 thumbnail = self._og_search_thumbnail(webpage)
70 description = self._og_search_description(webpage)
71
72 r = [
73 self._API_KEY,
74 [
75 'preview/flv_link',
76 {
77 'uid': video_id,
78 },
79 ],
80 ]
81 r_json = json.dumps(r)
82 post = compat_urllib_parse.urlencode({'r': r_json})
83 req = compat_urllib_request.Request(self._API_URL, post)
84 req.add_header('Content-type', 'application/x-www-form-urlencoded')
85
86 response = self._download_json(req, video_id)
87 if response['status'] != 'OK':
88 raise ExtractorError(
89 '%s returned error: %s' % (self.IE_NAME, response['data']),
90 expected=True
91 )
92 item = response['data'][0]
93 video_url = item['link']
94 duration = int_or_none(item['length'])
95 width = int_or_none(item['width'])
96 height = int_or_none(item['height'])
97 filesize = int_or_none(item['convert_size'])
98
99 formats = [{
100 'format_id': 'sd',
101 'http_headers': {'Range': 'bytes=0-'}, # Required to download
102 'url': video_url,
103 'width': width,
104 'height': height,
105 'filesize': filesize,
106 }]
107
108 return {
109 'id': video_id,
110 'title': title,
111 'thumbnail': thumbnail,
112 'description': description,
113 'duration': duration,
114 'formats': formats,
115 }