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.

40 lines
1.2 KiB

  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 compat_urllib_parse_unquote
  7. from ..utils import url_basename
  8. class DropboxIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?dropbox[.]com/sh?/(?P<id>[a-zA-Z0-9]{15})/.*'
  10. _TESTS = [{
  11. 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0',
  12. 'info_dict': {
  13. 'id': 'nelirfsxnmcfbfh',
  14. 'ext': 'mp4',
  15. 'title': 'youtube-dl test video \'ä"BaW_jenozKc'
  16. }
  17. },
  18. {
  19. 'url': 'https://www.dropbox.com/sh/662glsejgzoj9sr/AAByil3FGH9KFNZ13e08eSa1a/Pregame%20Ceremony%20Program%20PA%2020140518.m4v',
  20. 'only_matching': True,
  21. },
  22. ]
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. fn = compat_urllib_parse_unquote(url_basename(url))
  27. title = os.path.splitext(fn)[0]
  28. video_url = re.sub(r'[?&]dl=0', '', url)
  29. video_url += ('?' if '?' not in video_url else '&') + 'dl=1'
  30. return {
  31. 'id': video_id,
  32. 'title': title,
  33. 'url': video_url,
  34. }