1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-14 13:25:38 +00:00
youtube-dl/youtube_dl/extractor/toypics.py

91 lines
2.7 KiB
Python
Raw Normal View History

2016-10-02 11:39:18 +00:00
# coding: utf-8
2014-06-29 06:21:23 +00:00
from __future__ import unicode_literals
2014-03-21 18:31:41 +00:00
from .common import InfoExtractor
import re
2014-03-21 18:31:41 +00:00
class ToypicsIE(InfoExtractor):
2017-05-19 18:28:42 +00:00
IE_DESC = 'Toypics video'
_VALID_URL = r'https?://videos\.toypics\.net/view/(?P<id>[0-9]+)'
2014-03-21 18:31:41 +00:00
_TEST = {
'url': 'http://videos.toypics.net/view/514/chancebulged,-2-1/',
'md5': '16e806ad6d6f58079d210fe30985e08b',
2014-03-21 18:31:41 +00:00
'info_dict': {
'id': '514',
'ext': 'mp4',
2017-05-19 18:28:42 +00:00
'title': "Chance-Bulge'd, 2",
'age_limit': 18,
'uploader': 'kidsune',
2014-03-21 18:31:41 +00:00
}
}
def _real_extract(self, url):
2017-05-19 18:28:42 +00:00
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
formats = self._parse_html5_media_entries(
url, webpage, video_id)[0]['formats']
2017-05-19 18:18:03 +00:00
title = self._html_search_regex([
r'<h1[^>]+class=["\']view-video-title[^>]+>([^<]+)</h',
r'<title>([^<]+) - Toypics</title>',
2017-05-19 18:28:42 +00:00
], webpage, 'title')
uploader = self._html_search_regex(
r'More videos from <strong>([^<]+)</strong>', webpage, 'uploader',
fatal=False)
2014-03-21 18:31:41 +00:00
return {
'id': video_id,
2017-05-19 18:18:03 +00:00
'formats': formats,
2014-03-21 18:31:41 +00:00
'title': title,
2017-05-19 18:28:42 +00:00
'uploader': uploader,
'age_limit': 18,
}
class ToypicsUserIE(InfoExtractor):
IE_DESC = 'Toypics user profile'
2017-05-19 18:28:42 +00:00
_VALID_URL = r'https?://videos\.toypics\.net/(?!view)(?P<id>[^/?#&]+)'
_TEST = {
'url': 'http://videos.toypics.net/Mikey',
'info_dict': {
'id': 'Mikey',
},
'playlist_mincount': 19,
}
def _real_extract(self, url):
2017-05-19 18:28:42 +00:00
username = self._match_id(url)
profile_page = self._download_webpage(
url, username, note='Retrieving profile page')
video_count = int(self._search_regex(
r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
'video count'))
PAGE_SIZE = 8
urls = []
page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
for n in range(1, page_count + 1):
lpage_url = url + '/public/%d' % n
lpage = self._download_webpage(
lpage_url, username,
note='Downloading page %d/%d' % (n, page_count))
urls.extend(
re.findall(
2017-05-19 18:28:42 +00:00
r'<div[^>]+class=["\']preview[^>]+>\s*<a[^>]+href="(https?://videos\.toypics\.net/view/[^"]+)"',
lpage))
return {
'_type': 'playlist',
'id': username,
'entries': [{
'_type': 'url',
'url': eurl,
'ie_key': 'Toypics',
} for eurl in urls]
2014-03-21 18:31:41 +00:00
}