]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/porn91.py
[porn91] the one that _search_regex returns not needs to be checked
[yt-dlp.git] / youtube_dl / extractor / porn91.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from ..compat import compat_urllib_parse
7 from .common import InfoExtractor
8 from ..utils import ExtractorError
9
10
11 class Porn91IE(InfoExtractor):
12 IE_NAME = '91porn'
13 _VALID_URL = r'(?:https?://)(?:www\.|)91porn\.com/.+?\?viewkey=(?P<id>[\w\d]+)'
14
15 _TEST = {
16 'url': 'http://91porn.com/view_video.php?viewkey=7e42283b4f5ab36da134',
17 'md5': '6df8f6d028bc8b14f5dbd73af742fb20',
18 'info_dict': {
19 'id': '7e42283b4f5ab36da134',
20 'title': '18岁大一漂亮学妹,水嫩性感,再爽一次!',
21 'ext': 'mp4'
22 }
23 }
24
25 def _real_extract(self, url):
26 mobj = re.match(self._VALID_URL, url)
27 video_id = mobj.group('id')
28 url = 'http://91porn.com/view_video.php?viewkey=%s' % video_id
29 self._set_cookie('91porn.com', 'language', 'cn_CN')
30 webpage = self._download_webpage(url, video_id, "get HTML content")
31 title = self._search_regex(
32 r'<div id="viewvideo-title">(?P<title>.+?)</div>',
33 webpage, 'title', flags=re.DOTALL)
34 title = title.replace('\n', '')
35
36 # get real url
37 n1 = self._search_regex(
38 r'so.addVariable\(\'file\',\'(?P<n1>\d+)\'', webpage, 'n1')
39 n2 = self._search_regex(
40 r'so.addVariable\(\'seccode\',\'(?P<n2>.+?)\'', webpage, 'n2')
41 n3 = self._search_regex(
42 r'so.addVariable\(\'max_vid\',\'(?P<n3>\d+)\'', webpage, 'n3')
43 url_params = compat_urllib_parse.urlencode({
44 'VID': n1,
45 'mp4': '1',
46 'seccode': n2,
47 'max_vid': n3,
48 })
49 t_url = 'http://91porn.com/getfile.php?' + url_params
50 info_cn = self._download_webpage(t_url, video_id, "get real video_url")
51 video_url = self._search_regex(r'file=(?P<url>http.+?)&', info_cn, 'url')
52
53 # construct info
54 info = {
55 'id': video_id,
56 'title': title,
57 'url': video_url,
58 }
59
60 return info