]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/tinypic.py
Merge branch 'ustream-embed-recorded2' of https://github.com/anovicecodemonkey/youtub...
[youtube-dl] / 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'http://tinypic\.com/player\.php\?v=(?P<id>[^&]+)&s=\d+'
13
14     _TEST = {
15         'url': 'http://tinypic.com/player.php?v=6xw7tc%3E&s=5#.UtqZmbRFCM8',
16         'md5': '609b74432465364e72727ebc6203f044',
17         'info_dict': {
18             'id': '6xw7tc',
19             'ext': 'flv',
20             'title': 'shadow phenomenon weird',
21         }
22     }
23
24     def _real_extract(self, url):
25         mobj = re.match(self._VALID_URL, url)
26         video_id = mobj.group('id')
27
28         webpage = self._download_webpage(url, video_id, 'Downloading page')
29         
30         mobj = re.search(r'(?m)fo\.addVariable\("file",\s"(?P<fileid>[\da-z]+)"\);\n'
31             '\s+fo\.addVariable\("s",\s"(?P<serverid>\d+)"\);', webpage)
32         if mobj is None:
33             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
34
35         file_id = mobj.group('fileid')
36         server_id = mobj.group('serverid')
37
38         KEYWORDS_SUFFIX = ', Video, images, photos, videos, myspace, ebay, video hosting, photo hosting'
39         keywords = self._html_search_meta('keywords', webpage, 'title')
40         title = keywords[:-len(KEYWORDS_SUFFIX)] if keywords.endswith(KEYWORDS_SUFFIX) else ''
41
42         video_url = 'http://v%s.tinypic.com/%s.flv' % (server_id, file_id)
43         thumbnail = 'http://v%s.tinypic.com/%s_th.jpg' % (server_id, file_id)
44
45         return {
46             'id': file_id,
47             'url': video_url,
48             'thumbnail': thumbnail,
49             'title': title
50         }