]>
Commit | Line | Data |
---|---|---|
5aa38e75 CR |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5aa38e75 CR |
5 | import os.path |
6 | ||
7 | from .common import InfoExtractor | |
1cc79574 | 8 | from ..compat import ( |
5aa38e75 CR |
9 | compat_urllib_parse, |
10 | compat_urllib_request, | |
11 | ) | |
1cc79574 PH |
12 | from ..utils import ( |
13 | ExtractorError, | |
14 | ) | |
5aa38e75 CR |
15 | |
16 | ||
17 | class PlayedIE(InfoExtractor): | |
18 | IE_NAME = 'played.to' | |
38c4d41b | 19 | _VALID_URL = r'https?://(?:www\.)?played\.to/(?P<id>[a-zA-Z0-9_-]+)' |
5aa38e75 CR |
20 | |
21 | _TEST = { | |
22 | 'url': 'http://played.to/j2f2sfiiukgt', | |
23 | 'md5': 'c2bd75a368e82980e7257bf500c00637', | |
24 | 'info_dict': { | |
25 | 'id': 'j2f2sfiiukgt', | |
26 | 'ext': 'flv', | |
27 | 'title': 'youtube-dl_test_video.mp4', | |
28 | }, | |
62420c73 | 29 | 'skip': 'Removed for copyright infringement.', # oh wow |
5aa38e75 CR |
30 | } |
31 | ||
32 | def _real_extract(self, url): | |
38c4d41b | 33 | video_id = self._match_id(url) |
5aa38e75 | 34 | orig_webpage = self._download_webpage(url, video_id) |
76630645 S |
35 | |
36 | m_error = re.search( | |
37 | r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage) | |
38 | if m_error: | |
39 | raise ExtractorError(m_error.group('msg'), expected=True) | |
40 | ||
f8da79f8 | 41 | data = self._hidden_inputs(orig_webpage) |
5aa38e75 | 42 | |
38c4d41b | 43 | self._sleep(2, video_id) |
5aa38e75 CR |
44 | |
45 | post = compat_urllib_parse.urlencode(data) | |
46 | headers = { | |
47 | b'Content-Type': b'application/x-www-form-urlencoded', | |
48 | } | |
49 | req = compat_urllib_request.Request(url, post, headers) | |
50 | webpage = self._download_webpage( | |
51 | req, video_id, note='Downloading video page ...') | |
52 | ||
53 | title = os.path.splitext(data['fname'])[0] | |
54 | ||
55 | video_url = self._search_regex( | |
56 | r'file: "?(.+?)",', webpage, 'video URL') | |
57 | ||
58 | return { | |
59 | 'id': video_id, | |
60 | 'title': title, | |
61 | 'url': video_url, | |
38c4d41b | 62 | } |