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.

81 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. compat_urllib_parse,
  8. compat_urllib_request,
  9. )
  10. class FiredriveIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?firedrive\.com/' + \
  12. '(?:file|embed)/(?P<id>[0-9a-zA-Z]+)'
  13. _FILE_DELETED_REGEX = r'<div class="removed_file_image">'
  14. _TESTS = [{
  15. 'url': 'https://www.firedrive.com/file/FEB892FA160EBD01',
  16. 'md5': 'd5d4252f80ebeab4dc2d5ceaed1b7970',
  17. 'info_dict': {
  18. 'id': 'FEB892FA160EBD01',
  19. 'ext': 'flv',
  20. 'title': 'bbb_theora_486kbit.flv',
  21. 'thumbnail': 're:^http://.*\.jpg$',
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. url = 'http://firedrive.com/file/%s' % video_id
  28. webpage = self._download_webpage(url, video_id)
  29. if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
  30. raise ExtractorError('Video %s does not exist' % video_id,
  31. expected=True)
  32. fields = dict(re.findall(r'''(?x)<input\s+
  33. type="hidden"\s+
  34. name="([^"]+)"\s+
  35. value="([^"]*)"
  36. ''', webpage))
  37. post = compat_urllib_parse.urlencode(fields)
  38. req = compat_urllib_request.Request(url, post)
  39. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  40. # Apparently, this header is required for confirmation to work.
  41. req.add_header('Host', 'www.firedrive.com')
  42. webpage = self._download_webpage(req, video_id,
  43. 'Downloading video page')
  44. title = self._search_regex(r'class="external_title_left">(.+)</div>',
  45. webpage, 'title')
  46. thumbnail = self._search_regex(r'image:\s?"(//[^\"]+)', webpage,
  47. 'thumbnail', fatal=False)
  48. if thumbnail is not None:
  49. thumbnail = 'http:' + thumbnail
  50. ext = self._search_regex(r'type:\s?\'([^\']+)\',',
  51. webpage, 'extension', fatal=False)
  52. video_url = self._search_regex(
  53. r'file:\s?loadURL\(\'(http[^\']+)\'\),', webpage, 'file url')
  54. formats = [{
  55. 'format_id': 'sd',
  56. 'url': video_url,
  57. 'ext': ext,
  58. }]
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'thumbnail': thumbnail,
  63. 'formats': formats,
  64. }