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.

85 lines
2.7 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. _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. mobj = re.match(self._VALID_URL, url)
  48. username = mobj.group('username')
  49. profile_page = self._download_webpage(
  50. url, username, note='Retrieving profile page')
  51. video_count = int(self._search_regex(
  52. r'public/">Public Videos \(([0-9]+)\)</a></li>', profile_page,
  53. 'video count'))
  54. PAGE_SIZE = 8
  55. urls = []
  56. page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
  57. for n in range(1, page_count + 1):
  58. lpage_url = url + '/public/%d' % n
  59. lpage = self._download_webpage(
  60. lpage_url, username,
  61. note='Downloading page %d/%d' % (n, page_count))
  62. urls.extend(
  63. re.findall(
  64. r'<p class="video-entry-title">\s+<a href="(https?://videos.toypics.net/view/[^"]+)">',
  65. lpage))
  66. return {
  67. '_type': 'playlist',
  68. 'id': username,
  69. 'entries': [{
  70. '_type': 'url',
  71. 'url': eurl,
  72. 'ie_key': 'Toypics',
  73. } for eurl in urls]
  74. }