logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

dropbox.py (1299B)


  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. {
  12. 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0',
  13. 'info_dict': {
  14. 'id': 'nelirfsxnmcfbfh',
  15. 'ext': 'mp4',
  16. 'title': 'youtube-dl test video \'รค"BaW_jenozKc'
  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. }