logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tinypic.py (1896B)


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