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.

82 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. (?:id="[^"]+"\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?\'(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. }