]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/played.py
[/__init__] Add another cute search example
[yt-dlp.git] / youtube_dl / extractor / played.py
CommitLineData
5aa38e75
CR
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5aa38e75
CR
5import os.path
6
7from .common import InfoExtractor
1cc79574 8from ..compat import (
5aa38e75
CR
9 compat_urllib_parse,
10 compat_urllib_request,
11)
1cc79574
PH
12from ..utils import (
13 ExtractorError,
14)
5aa38e75
CR
15
16
17class 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 },
29 }
30
31 def _real_extract(self, url):
38c4d41b 32 video_id = self._match_id(url)
5aa38e75 33 orig_webpage = self._download_webpage(url, video_id)
76630645
S
34
35 m_error = re.search(
36 r'(?s)Reason for deletion:.*?<b class="err"[^>]*>(?P<msg>[^<]+)</b>', orig_webpage)
37 if m_error:
38 raise ExtractorError(m_error.group('msg'), expected=True)
39
38c4d41b
PH
40 fields = re.findall(
41 r'type="hidden" name="([^"]+)"\s+value="([^"]+)">', orig_webpage)
5aa38e75
CR
42 data = dict(fields)
43
38c4d41b 44 self._sleep(2, video_id)
5aa38e75
CR
45
46 post = compat_urllib_parse.urlencode(data)
47 headers = {
48 b'Content-Type': b'application/x-www-form-urlencoded',
49 }
50 req = compat_urllib_request.Request(url, post, headers)
51 webpage = self._download_webpage(
52 req, video_id, note='Downloading video page ...')
53
54 title = os.path.splitext(data['fname'])[0]
55
56 video_url = self._search_regex(
57 r'file: "?(.+?)",', webpage, 'video URL')
58
59 return {
60 'id': video_id,
61 'title': title,
62 'url': video_url,
38c4d41b 63 }