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