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.

86 lines
3.2 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. compat_urllib_request,
  5. compat_urllib_parse,
  6. ExtractorError,
  7. unescapeHTML,
  8. )
  9. class DailymotionIE(InfoExtractor):
  10. """Information Extractor for Dailymotion"""
  11. _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/video/([^/]+)'
  12. IE_NAME = u'dailymotion'
  13. _TEST = {
  14. u'url': u'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
  15. u'file': u'x33vw9.mp4',
  16. u'md5': u'392c4b85a60a90dc4792da41ce3144eb',
  17. u'info_dict': {
  18. u"uploader": u"Alex and Van .",
  19. u"title": u"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
  20. }
  21. }
  22. def _real_extract(self, url):
  23. # Extract id and simplified title from URL
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group(1).split('_')[0].split('?')[0]
  26. video_extension = 'mp4'
  27. # Retrieve video webpage to extract further information
  28. request = compat_urllib_request.Request(url)
  29. request.add_header('Cookie', 'family_filter=off')
  30. webpage = self._download_webpage(request, video_id)
  31. # Extract URL, uploader and title from webpage
  32. self.report_extraction(video_id)
  33. mobj = re.search(r'\s*var flashvars = (.*)', webpage)
  34. if mobj is None:
  35. raise ExtractorError(u'Unable to extract media URL')
  36. flashvars = compat_urllib_parse.unquote(mobj.group(1))
  37. for key in ['hd1080URL', 'hd720URL', 'hqURL', 'sdURL', 'ldURL', 'video_url']:
  38. if key in flashvars:
  39. max_quality = key
  40. self.to_screen(u'Using %s' % key)
  41. break
  42. else:
  43. raise ExtractorError(u'Unable to extract video URL')
  44. mobj = re.search(r'"' + max_quality + r'":"(.+?)"', flashvars)
  45. if mobj is None:
  46. raise ExtractorError(u'Unable to extract video URL')
  47. video_url = compat_urllib_parse.unquote(mobj.group(1)).replace('\\/', '/')
  48. # TODO: support choosing qualities
  49. mobj = re.search(r'<meta property="og:title" content="(?P<title>[^"]*)" />', webpage)
  50. if mobj is None:
  51. raise ExtractorError(u'Unable to extract title')
  52. video_title = unescapeHTML(mobj.group('title'))
  53. video_uploader = None
  54. video_uploader = self._search_regex([r'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
  55. # Looking for official user
  56. r'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
  57. webpage, 'video uploader')
  58. video_upload_date = None
  59. mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
  60. if mobj is not None:
  61. video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
  62. return [{
  63. 'id': video_id,
  64. 'url': video_url,
  65. 'uploader': video_uploader,
  66. 'upload_date': video_upload_date,
  67. 'title': video_title,
  68. 'ext': video_extension,
  69. }]