moniker.py 3.9 KB

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