]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tinypic.py
debian/{compat,control}: Update to debhelper compatibility level 12.
[youtubedl] / youtube_dl / extractor / tinypic.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import ExtractorError
7
8
9 class TinyPicIE(InfoExtractor):
10 IE_NAME = 'tinypic'
11 IE_DESC = 'tinypic.com videos'
12 _VALID_URL = r'https?://(?:.+?\.)?tinypic\.com/player\.php\?v=(?P<id>[^&]+)&s=\d+'
13
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,
27 }
28 ]
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')
35
36 mobj = re.search(r'(?m)fo\.addVariable\("file",\s"(?P<fileid>[\da-z]+)"\);\n'
37 r'\s+fo\.addVariable\("s",\s"(?P<serverid>\d+)"\);', webpage)
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
56 }