]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/toypics.py
[vk] Update test
[yt-dlp.git] / youtube_dl / extractor / toypics.py
CommitLineData
74af99fc 1from .common import InfoExtractor
74af99fc 2import re
3
231f76b5 4
74af99fc 5class ToypicsIE(InfoExtractor):
231f76b5
PH
6 IE_DESC = 'Toypics user profile'
7 _VALID_URL = r'http://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',
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):
231f76b5
PH
21 mobj = re.match(self._VALID_URL, url)
22 video_id = mobj.group('id')
23 page = self._download_webpage(url, video_id)
74af99fc 24 video_url = self._html_search_regex(
25 r'src:\s+"(http://static[0-9]+\.toypics\.net/flvideo/[^"]+)"', page, 'video URL')
26 title = self._html_search_regex(
27 r'<title>Toypics - ([^<]+)</title>', page, 'title')
28 username = self._html_search_regex(
29 r'toypics.net/([^/"]+)" class="user-name">', page, 'username')
30 return {
31 'id': video_id,
32 'url': video_url,
74af99fc 33 'title': title,
34 'uploader': username,
231f76b5
PH
35 'age_limit': 18,
36 }
37
38
39class ToypicsUserIE(InfoExtractor):
40 IE_DESC = 'Toypics user profile'
41 _VALID_URL = r'http://videos\.toypics\.net/(?P<username>[^/?]+)(?:$|[?#])'
42
43 def _real_extract(self, url):
44 mobj = re.match(self._VALID_URL, url)
45 username = mobj.group('username')
46
47 profile_page = self._download_webpage(
48 url, username, note='Retrieving profile page')
49
50 video_count = int(self._search_regex(
51 r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
52 'video count'))
53
54 PAGE_SIZE = 8
55 urls = []
56 page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
57 for n in range(1, page_count + 1):
58 lpage_url = url + '/public/%d' % n
59 lpage = self._download_webpage(
60 lpage_url, username,
61 note='Downloading page %d/%d' % (n, page_count))
62 urls.extend(
63 re.findall(
64 r'<p class="video-entry-title">\n\s*<a href="(http://videos.toypics.net/view/[^"]+)">',
65 lpage))
66
67 return {
68 '_type': 'playlist',
69 'id': username,
70 'entries': [{
71 '_type': 'url',
56dd5572 72 'url': eurl,
231f76b5 73 'ie_key': 'Toypics',
56dd5572 74 } for eurl in urls]
74af99fc 75 }