]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toypics.py
0f389bd93a1f35eb35346f7ee99b0b91a9c9b876
[youtubedl] / youtube_dl / extractor / toypics.py
1 # -*- coding:utf-8 -*-
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 import re
6
7
8 class ToypicsIE(InfoExtractor):
9 IE_DESC = 'Toypics user profile'
10 _VALID_URL = r'https?://videos\.toypics\.net/view/(?P<id>[0-9]+)/.*'
11 _TEST = {
12 'url': 'http://videos.toypics.net/view/514/chancebulged,-2-1/',
13 'md5': '16e806ad6d6f58079d210fe30985e08b',
14 'info_dict': {
15 'id': '514',
16 'ext': 'mp4',
17 'title': 'Chance-Bulge\'d, 2',
18 'age_limit': 18,
19 'uploader': 'kidsune',
20 }
21 }
22
23 def _real_extract(self, url):
24 mobj = re.match(self._VALID_URL, url)
25 video_id = mobj.group('id')
26 page = self._download_webpage(url, video_id)
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,
36 'title': title,
37 'uploader': username,
38 'age_limit': 18,
39 }
40
41
42 class ToypicsUserIE(InfoExtractor):
43 IE_DESC = 'Toypics user profile'
44 _VALID_URL = r'http://videos\.toypics\.net/(?P<username>[^/?]+)(?:$|[?#])'
45
46 def _real_extract(self, url):
47 mobj = re.match(self._VALID_URL, url)
48 username = mobj.group('username')
49
50 profile_page = self._download_webpage(
51 url, username, note='Retrieving profile page')
52
53 video_count = int(self._search_regex(
54 r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
55 'video count'))
56
57 PAGE_SIZE = 8
58 urls = []
59 page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
60 for n in range(1, page_count + 1):
61 lpage_url = url + '/public/%d' % n
62 lpage = self._download_webpage(
63 lpage_url, username,
64 note='Downloading page %d/%d' % (n, page_count))
65 urls.extend(
66 re.findall(
67 r'<p class="video-entry-title">\s+<a href="(https?://videos.toypics.net/view/[^"]+)">',
68 lpage))
69
70 return {
71 '_type': 'playlist',
72 'id': username,
73 'entries': [{
74 '_type': 'url',
75 'url': eurl,
76 'ie_key': 'Toypics',
77 } for eurl in urls]
78 }