toypics.py 2.6 KB

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