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.

83 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. determine_ext,
  10. )
  11. class FiredriveIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?firedrive\.com/' + \
  13. '(?:file|embed)/(?P<id>[0-9a-zA-Z]+)'
  14. _FILE_DELETED_REGEX = r'<div class="removed_file_image">'
  15. _TESTS = [{
  16. 'url': 'https://www.firedrive.com/file/FEB892FA160EBD01',
  17. 'md5': 'd5d4252f80ebeab4dc2d5ceaed1b7970',
  18. 'info_dict': {
  19. 'id': 'FEB892FA160EBD01',
  20. 'ext': 'flv',
  21. 'title': 'bbb_theora_486kbit.flv',
  22. 'thumbnail': 're:^http://.*\.jpg$',
  23. },
  24. }]
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  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. (?:id="[^"]+"\s+)?
  37. value="([^"]*)"
  38. ''', webpage))
  39. post = compat_urllib_parse.urlencode(fields)
  40. req = compat_urllib_request.Request(url, post)
  41. req.add_header('Content-type', 'application/x-www-form-urlencoded')
  42. # Apparently, this header is required for confirmation to work.
  43. req.add_header('Host', 'www.firedrive.com')
  44. webpage = self._download_webpage(req, video_id,
  45. 'Downloading video page')
  46. title = self._search_regex(r'class="external_title_left">(.+)</div>',
  47. webpage, 'title')
  48. thumbnail = self._search_regex(r'image:\s?"(//[^\"]+)', webpage,
  49. 'thumbnail', fatal=False)
  50. if thumbnail is not None:
  51. thumbnail = 'http:' + thumbnail
  52. ext = self._search_regex(r'type:\s?\'([^\']+)\',',
  53. webpage, 'extension', fatal=False)
  54. video_url = self._search_regex(
  55. r'file:\s?\'(http[^\']+)\',', webpage, 'file url')
  56. formats = [{
  57. 'format_id': 'sd',
  58. 'url': video_url,
  59. 'ext': ext,
  60. }]
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': thumbnail,
  65. 'formats': formats,
  66. }