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.

80 lines
2.5 KiB

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