trutube.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. )
  7. class TruTubeIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?trutube\.tv/video/(?P<id>[0-9]+)/.*'
  9. _TEST = {
  10. 'url': 'http://trutube.tv/video/14880/Ramses-II-Proven-To-Be-A-Red-Headed-Caucasoid-',
  11. 'md5': 'c5b6e301b0a2040b074746cbeaa26ca1',
  12. 'info_dict': {
  13. 'id': '14880',
  14. 'ext': 'flv',
  15. 'title': 'Ramses II - Proven To Be A Red Headed Caucasoid',
  16. 'thumbnail': 're:^http:.*\.jpg$',
  17. }
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. webpage = self._download_webpage(url, video_id)
  23. video_title = self._og_search_title(webpage).strip()
  24. thumbnail = self._search_regex(
  25. r"var splash_img = '([^']+)';", webpage, 'thumbnail', fatal=False)
  26. all_formats = re.finditer(
  27. r"var (?P<key>[a-z]+)_video_file\s*=\s*'(?P<url>[^']+)';", webpage)
  28. formats = [{
  29. 'format_id': m.group('key'),
  30. 'quality': -i,
  31. 'url': m.group('url'),
  32. } for i, m in enumerate(all_formats)]
  33. self._sort_formats(formats)
  34. return {
  35. 'id': video_id,
  36. 'title': video_title,
  37. 'formats': formats,
  38. 'thumbnail': thumbnail,
  39. }