You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB

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