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.

70 lines
2.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import os.path
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. compat_urllib_parse,
  8. compat_urllib_request,
  9. )
  10. class MonikerIE(InfoExtractor):
  11. IE_DESC = 'allmyvideos.net and vidspot.net'
  12. _VALID_URL = r'https?://(?:www\.)?(?:allmyvideos|vidspot)\.net/(?P<id>[a-zA-Z0-9_-]+)'
  13. _TESTS = [{
  14. 'url': 'http://allmyvideos.net/jih3nce3x6wn',
  15. 'md5': '710883dee1bfc370ecf9fa6a89307c88',
  16. 'info_dict': {
  17. 'id': 'jih3nce3x6wn',
  18. 'ext': 'mp4',
  19. 'title': 'youtube-dl test video',
  20. },
  21. }, {
  22. 'url': 'http://vidspot.net/l2ngsmhs8ci5',
  23. 'md5': '710883dee1bfc370ecf9fa6a89307c88',
  24. 'info_dict': {
  25. 'id': 'l2ngsmhs8ci5',
  26. 'ext': 'mp4',
  27. 'title': 'youtube-dl test video',
  28. },
  29. }, {
  30. 'url': 'https://www.vidspot.net/l2ngsmhs8ci5',
  31. 'only_matching': True,
  32. }]
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. video_id = mobj.group('id')
  36. orig_webpage = self._download_webpage(url, video_id)
  37. fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
  38. data = dict(fields)
  39. post = compat_urllib_parse.urlencode(data)
  40. headers = {
  41. b'Content-Type': b'application/x-www-form-urlencoded',
  42. }
  43. req = compat_urllib_request.Request(url, post, headers)
  44. webpage = self._download_webpage(
  45. req, video_id, note='Downloading video page ...')
  46. title = os.path.splitext(data['fname'])[0]
  47. #Could be several links with different quality
  48. links = re.findall(r'"file" : "?(.+?)",', webpage)
  49. # Assume the links are ordered in quality
  50. formats = [{
  51. 'url': l,
  52. 'quality': i,
  53. } for i, l in enumerate(links)]
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'formats': formats,
  59. }