]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/toypics.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / toypics.py
CommitLineData
ee8dda41
PP
1# -*- coding:utf-8 -*-
2from __future__ import unicode_literals
3
74af99fc 4from .common import InfoExtractor
74af99fc 5import re
6
231f76b5 7
74af99fc 8class ToypicsIE(InfoExtractor):
231f76b5 9 IE_DESC = 'Toypics user profile'
ee8dda41 10 _VALID_URL = r'https?://videos\.toypics\.net/view/(?P<id>[0-9]+)/.*'
74af99fc 11 _TEST = {
12 'url': 'http://videos.toypics.net/view/514/chancebulged,-2-1/',
231f76b5 13 'md5': '16e806ad6d6f58079d210fe30985e08b',
74af99fc 14 'info_dict': {
15 'id': '514',
16 'ext': 'mp4',
17 'title': 'Chance-Bulge\'d, 2',
231f76b5
PH
18 'age_limit': 18,
19 'uploader': 'kidsune',
74af99fc 20 }
21 }
74af99fc 22
23 def _real_extract(self, url):
231f76b5
PH
24 mobj = re.match(self._VALID_URL, url)
25 video_id = mobj.group('id')
26 page = self._download_webpage(url, video_id)
74af99fc 27 video_url = self._html_search_regex(
28 r'src:\s+"(http://static[0-9]+\.toypics\.net/flvideo/[^"]+)"', page, 'video URL')
29 title = self._html_search_regex(
30 r'<title>Toypics - ([^<]+)</title>', page, 'title')
31 username = self._html_search_regex(
32 r'toypics.net/([^/"]+)" class="user-name">', page, 'username')
33 return {
34 'id': video_id,
35 'url': video_url,
74af99fc 36 'title': title,
37 'uploader': username,
231f76b5
PH
38 'age_limit': 18,
39 }
40
41
42class ToypicsUserIE(InfoExtractor):
43 IE_DESC = 'Toypics user profile'
5886b38d 44 _VALID_URL = r'https?://videos\.toypics\.net/(?P<username>[^/?]+)(?:$|[?#])'
22a6f150
PH
45 _TEST = {
46 'url': 'http://videos.toypics.net/Mikey',
47 'info_dict': {
48 'id': 'Mikey',
49 },
feec0f56 50 'playlist_mincount': 19,
22a6f150 51 }
231f76b5
PH
52
53 def _real_extract(self, url):
54 mobj = re.match(self._VALID_URL, url)
55 username = mobj.group('username')
56
57 profile_page = self._download_webpage(
58 url, username, note='Retrieving profile page')
59
60 video_count = int(self._search_regex(
61 r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
62 'video count'))
63
64 PAGE_SIZE = 8
65 urls = []
66 page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
67 for n in range(1, page_count + 1):
68 lpage_url = url + '/public/%d' % n
69 lpage = self._download_webpage(
70 lpage_url, username,
71 note='Downloading page %d/%d' % (n, page_count))
72 urls.extend(
73 re.findall(
ee8dda41 74 r'<p class="video-entry-title">\s+<a href="(https?://videos.toypics.net/view/[^"]+)">',
231f76b5
PH
75 lpage))
76
77 return {
78 '_type': 'playlist',
79 'id': username,
80 'entries': [{
81 '_type': 'url',
56dd5572 82 'url': eurl,
231f76b5 83 'ie_key': 'Toypics',
56dd5572 84 } for eurl in urls]
74af99fc 85 }