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