Merge remote-tracking branch 'diffycat/thvideo'
[youtube-dl] / youtube_dl / extractor / dropbox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import os.path
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import compat_urllib_parse_unquote, url_basename
9
10
11 class DropboxIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?dropbox[.]com/sh?/(?P<id>[a-zA-Z0-9]{15})/.*'
13     _TESTS = [{
14         'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0',
15         'info_dict': {
16             'id': 'nelirfsxnmcfbfh',
17             'ext': 'mp4',
18             'title': 'youtube-dl test video \'รค"BaW_jenozKc'
19         }
20     },
21     {
22         'url': 'https://www.dropbox.com/sh/662glsejgzoj9sr/AAByil3FGH9KFNZ13e08eSa1a/Pregame%20Ceremony%20Program%20PA%2020140518.m4v',
23         'only_matching': True,
24     },
25     ]
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30         fn = compat_urllib_parse_unquote(url_basename(url))
31         title = os.path.splitext(fn)[0]
32         video_url = (
33             re.sub(r'[?&]dl=0', '', url) +
34             ('?' if '?' in url else '&') + 'dl=1')
35
36         return {
37             'id': video_id,
38             'title': title,
39             'url': video_url,
40         }