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.

69 lines
2.0 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. 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. video_id = self._match_id(url)
  35. orig_webpage = self._download_webpage(url, video_id)
  36. fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
  37. data = dict(fields)
  38. post = compat_urllib_parse.urlencode(data)
  39. headers = {
  40. b'Content-Type': b'application/x-www-form-urlencoded',
  41. }
  42. req = compat_urllib_request.Request(url, post, headers)
  43. webpage = self._download_webpage(
  44. req, video_id, note='Downloading video page ...')
  45. title = os.path.splitext(data['fname'])[0]
  46. # Could be several links with different quality
  47. links = re.findall(r'"file" : "?(.+?)",', webpage)
  48. # Assume the links are ordered in quality
  49. formats = [{
  50. 'url': l,
  51. 'quality': i,
  52. } for i, l in enumerate(links)]
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'formats': formats,
  58. }