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.

75 lines
2.7 KiB

  1. # coding: utf-8
  2. import re
  3. import xml.etree.ElementTree
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. unified_strdate,
  8. )
  9. class TouTvIE(InfoExtractor):
  10. IE_NAME = u'tou.tv'
  11. _VALID_URL = r'https?://www\.tou\.tv/(?P<id>[a-zA-Z0-9_-]+(?:/(?P<episode>S[0-9]+E[0-9]+)))'
  12. _TEST = {
  13. u'url': u'http://www.tou.tv/30-vies/S04E41',
  14. u'file': u'30-vies_S04E41.mp4',
  15. u'info_dict': {
  16. u'title': u'30 vies Saison 4 / Épisode 41',
  17. u'description': u'md5:da363002db82ccbe4dafeb9cab039b09',
  18. u'age_limit': 8,
  19. u'uploader': u'Groupe des Nouveaux Médias',
  20. u'duration': 1296,
  21. u'upload_date': u'20131118',
  22. u'thumbnail': u'http://static.tou.tv/medias/images/2013-11-18_19_00_00_30VIES_0341_01_L.jpeg',
  23. },
  24. u'params': {
  25. u'skip_download': True, # Requires rtmpdump
  26. },
  27. u'xskip': 'Only available in Canada'
  28. }
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. webpage = self._download_webpage(url, video_id)
  33. mediaId = self._search_regex(
  34. r'"idMedia":\s*"([^"]+)"', webpage, u'media ID')
  35. # TODO test from de
  36. streams_url = u'http://release.theplatform.com/content.select?pid=' + mediaId
  37. streams_webpage = self._download_webpage(
  38. streams_url, video_id, note=u'Downloading stream list')
  39. streams_doc = xml.etree.ElementTree.fromstring(
  40. streams_webpage.encode('utf-8'))
  41. video_url = next(n.text
  42. for n in streams_doc.findall('.//choice/url')
  43. if u'//ad.doubleclick' not in n.text)
  44. if video_url.endswith('/Unavailable.flv'):
  45. raise ExtractorError(
  46. u'Access to this video is blocked from outside of Canada',
  47. expected=True)
  48. duration_str = self._html_search_meta(
  49. 'video:duration', webpage, u'duration')
  50. duration = int(duration_str) if duration_str else None
  51. upload_date_str = self._html_search_meta(
  52. 'video:release_date', webpage, u'upload date')
  53. upload_date = unified_strdate(upload_date_str) if upload_date_str else None
  54. return {
  55. 'id': video_id,
  56. 'title': self._og_search_title(webpage),
  57. 'url': video_url,
  58. 'description': self._og_search_description(webpage),
  59. 'uploader': self._dc_search_uploader(webpage),
  60. 'thumbnail': self._og_search_thumbnail(webpage),
  61. 'age_limit': self._media_rating_search(webpage),
  62. 'duration': duration,
  63. 'upload_date': upload_date,
  64. 'ext': 'mp4',
  65. }