]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/played.py
Update changelog.
[youtubedl] / youtube_dl / extractor / played.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import os.path
6
7 from .common import InfoExtractor
8 from ..utils import (
9 ExtractorError,
10 compat_urllib_parse,
11 compat_urllib_request,
12 )
13
14
15 class PlayedIE(InfoExtractor):
16 IE_NAME = 'played.to'
17 _VALID_URL = r'https?://(?:www\.)?played\.to/(?P<id>[a-zA-Z0-9_-]+)'
18
19 _TEST = {
20 'url': 'http://played.to/j2f2sfiiukgt',
21 'md5': 'c2bd75a368e82980e7257bf500c00637',
22 'info_dict': {
23 'id': 'j2f2sfiiukgt',
24 'ext': 'flv',
25 'title': 'youtube-dl_test_video.mp4',
26 },
27 }
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31
32 orig_webpage = self._download_webpage(url, video_id)
33
34 m_error = re.search(
35 r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage)
36 if m_error:
37 raise ExtractorError(m_error.group('msg'), expected=True)
38
39 fields = re.findall(
40 r'type="hidden" name="([^"]+)"\s+value="([^"]+)">', orig_webpage)
41 data = dict(fields)
42
43 self._sleep(2, video_id)
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,
62 }