logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

toypics.py (2746B)


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