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.

118 lines
3.9 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import os.path
  4. import re
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_urllib_parse,
  8. compat_urllib_request,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. remove_start,
  13. )
  14. class MonikerIE(InfoExtractor):
  15. IE_DESC = 'allmyvideos.net and vidspot.net'
  16. _VALID_URL = r'https?://(?:www\.)?(?:allmyvideos|vidspot)\.net/(?:(?:2|v)/v-)?(?P<id>[a-zA-Z0-9_-]+)'
  17. _TESTS = [{
  18. 'url': 'http://allmyvideos.net/jih3nce3x6wn',
  19. 'md5': '710883dee1bfc370ecf9fa6a89307c88',
  20. 'info_dict': {
  21. 'id': 'jih3nce3x6wn',
  22. 'ext': 'mp4',
  23. 'title': 'youtube-dl test video',
  24. },
  25. }, {
  26. 'url': 'http://allmyvideos.net/embed-jih3nce3x6wn',
  27. 'md5': '710883dee1bfc370ecf9fa6a89307c88',
  28. 'info_dict': {
  29. 'id': 'jih3nce3x6wn',
  30. 'ext': 'mp4',
  31. 'title': 'youtube-dl test video',
  32. },
  33. }, {
  34. 'url': 'http://vidspot.net/l2ngsmhs8ci5',
  35. 'md5': '710883dee1bfc370ecf9fa6a89307c88',
  36. 'info_dict': {
  37. 'id': 'l2ngsmhs8ci5',
  38. 'ext': 'mp4',
  39. 'title': 'youtube-dl test video',
  40. },
  41. }, {
  42. 'url': 'https://www.vidspot.net/l2ngsmhs8ci5',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'http://vidspot.net/2/v-ywDf99',
  46. 'md5': '5f8254ce12df30479428b0152fb8e7ba',
  47. 'info_dict': {
  48. 'id': 'ywDf99',
  49. 'ext': 'mp4',
  50. 'title': 'IL FAIT LE MALIN EN PORSHE CAYENNE ( mais pas pour longtemps)',
  51. 'description': 'IL FAIT LE MALIN EN PORSHE CAYENNE.',
  52. },
  53. }, {
  54. 'url': 'http://allmyvideos.net/v/v-HXZm5t',
  55. 'only_matching': True,
  56. }]
  57. def _real_extract(self, url):
  58. orig_video_id = self._match_id(url)
  59. video_id = remove_start(orig_video_id, 'embed-')
  60. url = url.replace(orig_video_id, video_id)
  61. assert re.match(self._VALID_URL, url) is not None
  62. orig_webpage = self._download_webpage(url, video_id)
  63. if '>File Not Found<' in orig_webpage:
  64. raise ExtractorError('Video %s does not exist' % video_id, expected=True)
  65. error = self._search_regex(
  66. r'class="err">([^<]+)<', orig_webpage, 'error', default=None)
  67. if error:
  68. raise ExtractorError(
  69. '%s returned error: %s' % (self.IE_NAME, error), expected=True)
  70. builtin_url = self._search_regex(
  71. r'<iframe[^>]+src=(["\'])(?P<url>.+?/builtin-.+?)\1',
  72. orig_webpage, 'builtin URL', default=None, group='url')
  73. if builtin_url:
  74. req = compat_urllib_request.Request(builtin_url)
  75. req.add_header('Referer', url)
  76. webpage = self._download_webpage(req, video_id, 'Downloading builtin page')
  77. title = self._og_search_title(orig_webpage).strip()
  78. description = self._og_search_description(orig_webpage).strip()
  79. else:
  80. fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
  81. data = dict(fields)
  82. post = compat_urllib_parse.urlencode(data)
  83. headers = {
  84. b'Content-Type': b'application/x-www-form-urlencoded',
  85. }
  86. req = compat_urllib_request.Request(url, post, headers)
  87. webpage = self._download_webpage(
  88. req, video_id, note='Downloading video page ...')
  89. title = os.path.splitext(data['fname'])[0]
  90. description = None
  91. # Could be several links with different quality
  92. links = re.findall(r'"file" : "?(.+?)",', webpage)
  93. # Assume the links are ordered in quality
  94. formats = [{
  95. 'url': l,
  96. 'quality': i,
  97. } for i, l in enumerate(links)]
  98. self._sort_formats(formats)
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'description': description,
  103. 'formats': formats,
  104. }