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.

41 lines
1.3 KiB

  1. import base64
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_parse_qs,
  6. )
  7. class TutvIE(InfoExtractor):
  8. _VALID_URL=r'https?://(?:www\.)?tu\.tv/videos/(?P<id>[^/?]+)'
  9. _TEST = {
  10. u'url': u'http://tu.tv/videos/noah-en-pabellon-cuahutemoc',
  11. u'file': u'2742556.flv',
  12. u'md5': u'5eb766671f69b82e528dc1e7769c5cb2',
  13. u'info_dict': {
  14. u"title": u"Noah en pabellon cuahutemoc"
  15. }
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. video_id = mobj.group('id')
  20. webpage = self._download_webpage(url, video_id)
  21. title = self._html_search_regex(
  22. r'<meta property="og:title" content="(.*?)">', webpage, u'title')
  23. internal_id = self._search_regex(r'codVideo=([0-9]+)', webpage, u'internal video ID')
  24. data_url = u'http://tu.tv/flvurl.php?codVideo=' + str(internal_id)
  25. data_content = self._download_webpage(data_url, video_id, note=u'Downloading video info')
  26. data = compat_parse_qs(data_content)
  27. video_url = base64.b64decode(data['kpt'][0]).decode('utf-8')
  28. ext = video_url.partition(u'?')[0].rpartition(u'.')[2]
  29. info = {
  30. 'id': internal_id,
  31. 'url': video_url,
  32. 'ext': ext,
  33. 'title': title,
  34. }
  35. return [info]