canalc2.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_duration
  6. class Canalc2IE(InfoExtractor):
  7. IE_NAME = 'canalc2.tv'
  8. _VALID_URL = r'https?://(?:www\.)?canalc2\.tv/video/(?P<id>\d+)'
  9. _TEST = {
  10. 'url': 'http://www.canalc2.tv/video/12163',
  11. 'md5': '060158428b650f896c542dfbb3d6487f',
  12. 'info_dict': {
  13. 'id': '12163',
  14. 'ext': 'mp4',
  15. 'title': 'Terrasses du Numérique'
  16. },
  17. 'params': {
  18. 'skip_download': True, # Requires rtmpdump
  19. }
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. webpage = self._download_webpage(url, video_id)
  24. video_url = self._search_regex(
  25. r'jwplayer\((["\'])Player\1\)\.setup\({[^}]*file\s*:\s*(["\'])(?P<file>.+?)\2',
  26. webpage, 'video_url', group='file')
  27. formats = [{'url': video_url}]
  28. if video_url.startswith('rtmp://'):
  29. rtmp = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
  30. formats[0].update({
  31. 'url': rtmp.group('url'),
  32. 'ext': 'flv',
  33. 'app': rtmp.group('app'),
  34. 'play_path': rtmp.group('play_path'),
  35. 'page_url': url,
  36. })
  37. title = self._html_search_regex(
  38. r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.*?)</h3>', webpage, 'title')
  39. duration = parse_duration(self._search_regex(
  40. r'id=["\']video_duree["\'][^>]*>([^<]+)',
  41. webpage, 'duration', fatal=False))
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'duration': duration,
  46. 'formats': formats,
  47. }