You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class TestTubeIE(InfoExtractor):
  5. _VALID_URL = r'https?://testtube\.com/[^/?#]+/(?P<id>[^/?#]+)'
  6. _TESTS = [{
  7. 'url': 'https://testtube.com/dnews/5-weird-ways-plants-can-eat-animals?utm_source=FB&utm_medium=DNews&utm_campaign=DNewsSocial',
  8. 'info_dict': {
  9. 'id': '60163',
  10. 'display_id': '5-weird-ways-plants-can-eat-animals',
  11. 'duration': 275,
  12. 'ext': 'mp4',
  13. 'title': '5 Weird Ways Plants Can Eat Animals',
  14. 'description': 'Why have some plants evolved to eat meat?',
  15. 'thumbnail': 're:^https?://.*\.jpg$',
  16. 'uploader': 'DNews',
  17. 'uploader_id': 'dnews',
  18. },
  19. }]
  20. def _real_extract(self, url):
  21. display_id = self._match_id(url)
  22. webpage = self._download_webpage(url, display_id)
  23. video_id = self._search_regex(
  24. r"player\.loadRevision3Item\('video_id',\s*([0-9]+)\);",
  25. webpage, 'video ID')
  26. all_info = self._download_json(
  27. 'https://testtube.com/api/getPlaylist.json?api_key=ba9c741bce1b9d8e3defcc22193f3651b8867e62&codecs=h264,vp8,theora&video_id=%s' % video_id,
  28. video_id)
  29. info = all_info['items'][0]
  30. formats = []
  31. for vcodec, fdatas in info['media'].items():
  32. for name, fdata in fdatas.items():
  33. formats.append({
  34. 'format_id': '%s-%s' % (vcodec, name),
  35. 'url': fdata['url'],
  36. 'vcodec': vcodec,
  37. 'tbr': fdata.get('bitrate'),
  38. })
  39. self._sort_formats(formats)
  40. duration = int_or_none(info.get('duration'))
  41. return {
  42. 'id': video_id,
  43. 'display_id': display_id,
  44. 'title': info['title'],
  45. 'description': info.get('summary'),
  46. 'thumbnail': info.get('images', {}).get('large'),
  47. 'uploader': info.get('show', {}).get('name'),
  48. 'uploader_id': info.get('show', {}).get('slug'),
  49. 'duration': duration,
  50. 'formats': formats,
  51. }