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.

136 lines
4.5 KiB

  1. import re
  2. import socket
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_http_client,
  6. compat_str,
  7. compat_urllib_error,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. ExtractorError,
  11. unified_strdate,
  12. )
  13. class ArteTvIE(InfoExtractor):
  14. """arte.tv information extractor."""
  15. _VALID_URL = r'(?:http://)?videos\.arte\.tv/(?:fr|de)/videos/.*'
  16. _LIVE_URL = r'index-[0-9]+\.html$'
  17. IE_NAME = u'arte.tv'
  18. def fetch_webpage(self, url):
  19. request = compat_urllib_request.Request(url)
  20. try:
  21. self.report_download_webpage(url)
  22. webpage = compat_urllib_request.urlopen(request).read()
  23. except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
  24. raise ExtractorError(u'Unable to retrieve video webpage: %s' % compat_str(err))
  25. except ValueError as err:
  26. raise ExtractorError(u'Invalid URL: %s' % url)
  27. return webpage
  28. def grep_webpage(self, url, regex, regexFlags, matchTuples):
  29. page = self.fetch_webpage(url)
  30. mobj = re.search(regex, page, regexFlags)
  31. info = {}
  32. if mobj is None:
  33. raise ExtractorError(u'Invalid URL: %s' % url)
  34. for (i, key, err) in matchTuples:
  35. if mobj.group(i) is None:
  36. raise ExtractorError(err)
  37. else:
  38. info[key] = mobj.group(i)
  39. return info
  40. # TODO implement Live Stream
  41. # def extractLiveStream(self, url):
  42. # video_lang = url.split('/')[-4]
  43. # info = self.grep_webpage(
  44. # url,
  45. # r'src="(.*?/videothek_js.*?\.js)',
  46. # 0,
  47. # [
  48. # (1, 'url', u'Invalid URL: %s' % url)
  49. # ]
  50. # )
  51. # http_host = url.split('/')[2]
  52. # next_url = 'http://%s%s' % (http_host, compat_urllib_parse.unquote(info.get('url')))
  53. # info = self.grep_webpage(
  54. # next_url,
  55. # r'(s_artestras_scst_geoFRDE_' + video_lang + '.*?)\'.*?' +
  56. # '(http://.*?\.swf).*?' +
  57. # '(rtmp://.*?)\'',
  58. # re.DOTALL,
  59. # [
  60. # (1, 'path', u'could not extract video path: %s' % url),
  61. # (2, 'player', u'could not extract video player: %s' % url),
  62. # (3, 'url', u'could not extract video url: %s' % url)
  63. # ]
  64. # )
  65. # video_url = u'%s/%s' % (info.get('url'), info.get('path'))
  66. def extractPlus7Stream(self, url):
  67. video_lang = url.split('/')[-3]
  68. info = self.grep_webpage(
  69. url,
  70. r'param name="movie".*?videorefFileUrl=(http[^\'"&]*)',
  71. 0,
  72. [
  73. (1, 'url', u'Invalid URL: %s' % url)
  74. ]
  75. )
  76. next_url = compat_urllib_parse.unquote(info.get('url'))
  77. info = self.grep_webpage(
  78. next_url,
  79. r'<video lang="%s" ref="(http[^\'"&]*)' % video_lang,
  80. 0,
  81. [
  82. (1, 'url', u'Could not find <video> tag: %s' % url)
  83. ]
  84. )
  85. next_url = compat_urllib_parse.unquote(info.get('url'))
  86. info = self.grep_webpage(
  87. next_url,
  88. r'<video id="(.*?)".*?>.*?' +
  89. '<name>(.*?)</name>.*?' +
  90. '<dateVideo>(.*?)</dateVideo>.*?' +
  91. '<url quality="hd">(.*?)</url>',
  92. re.DOTALL,
  93. [
  94. (1, 'id', u'could not extract video id: %s' % url),
  95. (2, 'title', u'could not extract video title: %s' % url),
  96. (3, 'date', u'could not extract video date: %s' % url),
  97. (4, 'url', u'could not extract video url: %s' % url)
  98. ]
  99. )
  100. return {
  101. 'id': info.get('id'),
  102. 'url': compat_urllib_parse.unquote(info.get('url')),
  103. 'uploader': u'arte.tv',
  104. 'upload_date': unified_strdate(info.get('date')),
  105. 'title': info.get('title').decode('utf-8'),
  106. 'ext': u'mp4',
  107. 'format': u'NA',
  108. 'player_url': None,
  109. }
  110. def _real_extract(self, url):
  111. video_id = url.split('/')[-1]
  112. self.report_extraction(video_id)
  113. if re.search(self._LIVE_URL, video_id) is not None:
  114. raise ExtractorError(u'Arte live streams are not yet supported, sorry')
  115. # self.extractLiveStream(url)
  116. # return
  117. else:
  118. info = self.extractPlus7Stream(url)
  119. return [info]