[ie/box] Fix formats extraction (#8649)
[yt-dlp3.git] / yt_dlp / extractor / tinypic.py
blob216208cbdc93020baa3dd675732d29b143cd26a0
1 import re
3 from .common import InfoExtractor
4 from ..utils import ExtractorError
7 class TinyPicIE(InfoExtractor):
8 IE_NAME = 'tinypic'
9 IE_DESC = 'tinypic.com videos'
10 _VALID_URL = r'https?://(?:.+?\.)?tinypic\.com/player\.php\?v=(?P<id>[^&]+)&s=\d+'
12 _TESTS = [
14 'url': 'http://tinypic.com/player.php?v=6xw7tc%3E&s=5#.UtqZmbRFCM8',
15 'md5': '609b74432465364e72727ebc6203f044',
16 'info_dict': {
17 'id': '6xw7tc',
18 'ext': 'flv',
19 'title': 'shadow phenomenon weird',
23 'url': 'http://de.tinypic.com/player.php?v=dy90yh&s=8',
24 'only_matching': True,
28 def _real_extract(self, url):
29 mobj = self._match_valid_url(url)
30 video_id = mobj.group('id')
32 webpage = self._download_webpage(url, video_id, 'Downloading page')
34 mobj = re.search(r'(?m)fo\.addVariable\("file",\s"(?P<fileid>[\da-z]+)"\);\n'
35 r'\s+fo\.addVariable\("s",\s"(?P<serverid>\d+)"\);', webpage)
36 if mobj is None:
37 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
39 file_id = mobj.group('fileid')
40 server_id = mobj.group('serverid')
42 KEYWORDS_SUFFIX = ', Video, images, photos, videos, myspace, ebay, video hosting, photo hosting'
43 keywords = self._html_search_meta('keywords', webpage, 'title')
44 title = keywords[:-len(KEYWORDS_SUFFIX)] if keywords.endswith(KEYWORDS_SUFFIX) else ''
46 video_url = 'http://v%s.tinypic.com/%s.flv' % (server_id, file_id)
47 thumbnail = 'http://v%s.tinypic.com/%s_th.jpg' % (server_id, file_id)
49 return {
50 'id': file_id,
51 'url': video_url,
52 'thumbnail': thumbnail,
53 'title': title