]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/toypics.py
[extractor/generic] Use `Accept-Encoding: identity` for initial request
[yt-dlp.git] / yt_dlp / extractor / toypics.py
CommitLineData
74af99fc 1from .common import InfoExtractor
74af99fc 2import re
3
231f76b5 4
74af99fc 5class ToypicsIE(InfoExtractor):
2ca29f1a
S
6 IE_DESC = 'Toypics video'
7 _VALID_URL = r'https?://videos\.toypics\.net/view/(?P<id>[0-9]+)'
74af99fc 8 _TEST = {
9 'url': 'http://videos.toypics.net/view/514/chancebulged,-2-1/',
231f76b5 10 'md5': '16e806ad6d6f58079d210fe30985e08b',
74af99fc 11 'info_dict': {
12 'id': '514',
13 'ext': 'mp4',
2ca29f1a 14 'title': "Chance-Bulge'd, 2",
231f76b5
PH
15 'age_limit': 18,
16 'uploader': 'kidsune',
74af99fc 17 }
18 }
74af99fc 19
20 def _real_extract(self, url):
2ca29f1a
S
21 video_id = self._match_id(url)
22
23 webpage = self._download_webpage(url, video_id)
24
25 formats = self._parse_html5_media_entries(
26 url, webpage, video_id)[0]['formats']
77d682da 27 title = self._html_search_regex([
28 r'<h1[^>]+class=["\']view-video-title[^>]+>([^<]+)</h',
29 r'<title>([^<]+) - Toypics</title>',
2ca29f1a
S
30 ], webpage, 'title')
31
32 uploader = self._html_search_regex(
33 r'More videos from <strong>([^<]+)</strong>', webpage, 'uploader',
34 fatal=False)
35
74af99fc 36 return {
37 'id': video_id,
77d682da 38 'formats': formats,
74af99fc 39 'title': title,
2ca29f1a 40 'uploader': uploader,
231f76b5
PH
41 'age_limit': 18,
42 }
43
44
45class ToypicsUserIE(InfoExtractor):
46 IE_DESC = 'Toypics user profile'
2ca29f1a 47 _VALID_URL = r'https?://videos\.toypics\.net/(?!view)(?P<id>[^/?#&]+)'
22a6f150
PH
48 _TEST = {
49 'url': 'http://videos.toypics.net/Mikey',
50 'info_dict': {
51 'id': 'Mikey',
52 },
feec0f56 53 'playlist_mincount': 19,
22a6f150 54 }
231f76b5
PH
55
56 def _real_extract(self, url):
2ca29f1a 57 username = self._match_id(url)
231f76b5
PH
58
59 profile_page = self._download_webpage(
60 url, username, note='Retrieving profile page')
61
62 video_count = int(self._search_regex(
63 r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
64 'video count'))
65
66 PAGE_SIZE = 8
67 urls = []
68 page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
69 for n in range(1, page_count + 1):
70 lpage_url = url + '/public/%d' % n
71 lpage = self._download_webpage(
72 lpage_url, username,
73 note='Downloading page %d/%d' % (n, page_count))
74 urls.extend(
75 re.findall(
2ca29f1a 76 r'<div[^>]+class=["\']preview[^>]+>\s*<a[^>]+href="(https?://videos\.toypics\.net/view/[^"]+)"',
231f76b5
PH
77 lpage))
78
79 return {
80 '_type': 'playlist',
81 'id': username,
82 'entries': [{
83 '_type': 'url',
56dd5572 84 'url': eurl,
231f76b5 85 'ie_key': 'Toypics',
56dd5572 86 } for eurl in urls]
74af99fc 87 }