]>
Commit | Line | Data |
---|---|---|
dbe80ca7 S |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
2c39b0c6 | 6 | from ..utils import ExtractorError |
dbe80ca7 S |
7 | |
8 | ||
9 | class TinyPicIE(InfoExtractor): | |
10 | IE_NAME = 'tinypic' | |
11 | IE_DESC = 'tinypic.com videos' | |
5886b38d | 12 | _VALID_URL = r'https?://(?:.+?\.)?tinypic\.com/player\.php\?v=(?P<id>[^&]+)&s=\d+' |
dbe80ca7 | 13 | |
564bb5e9 S |
14 | _TESTS = [ |
15 | { | |
16 | 'url': 'http://tinypic.com/player.php?v=6xw7tc%3E&s=5#.UtqZmbRFCM8', | |
17 | 'md5': '609b74432465364e72727ebc6203f044', | |
18 | 'info_dict': { | |
19 | 'id': '6xw7tc', | |
20 | 'ext': 'flv', | |
21 | 'title': 'shadow phenomenon weird', | |
22 | }, | |
23 | }, | |
24 | { | |
25 | 'url': 'http://de.tinypic.com/player.php?v=dy90yh&s=8', | |
26 | 'only_matching': True, | |
dbe80ca7 | 27 | } |
564bb5e9 | 28 | ] |
dbe80ca7 S |
29 | |
30 | def _real_extract(self, url): | |
31 | mobj = re.match(self._VALID_URL, url) | |
32 | video_id = mobj.group('id') | |
33 | ||
34 | webpage = self._download_webpage(url, video_id, 'Downloading page') | |
5f6a1245 | 35 | |
dbe80ca7 | 36 | mobj = re.search(r'(?m)fo\.addVariable\("file",\s"(?P<fileid>[\da-z]+)"\);\n' |
9e1a5b84 | 37 | '\s+fo\.addVariable\("s",\s"(?P<serverid>\d+)"\);', webpage) |
dbe80ca7 S |
38 | if mobj is None: |
39 | raise ExtractorError('Video %s does not exist' % video_id, expected=True) | |
40 | ||
41 | file_id = mobj.group('fileid') | |
42 | server_id = mobj.group('serverid') | |
43 | ||
44 | KEYWORDS_SUFFIX = ', Video, images, photos, videos, myspace, ebay, video hosting, photo hosting' | |
45 | keywords = self._html_search_meta('keywords', webpage, 'title') | |
46 | title = keywords[:-len(KEYWORDS_SUFFIX)] if keywords.endswith(KEYWORDS_SUFFIX) else '' | |
47 | ||
48 | video_url = 'http://v%s.tinypic.com/%s.flv' % (server_id, file_id) | |
49 | thumbnail = 'http://v%s.tinypic.com/%s_th.jpg' % (server_id, file_id) | |
50 | ||
51 | return { | |
52 | 'id': file_id, | |
53 | 'url': video_url, | |
54 | 'thumbnail': thumbnail, | |
55 | 'title': title | |
5f6a1245 | 56 | } |