jove.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from datetime import datetime
  5. from .common import InfoExtractor
  6. from ..utils import determine_ext, ExtractorError
  7. class JoveIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?jove\.com/video/(?P<id>[0-9]+)'
  9. _CHAPTERS_URL = 'http://www.jove.com/video-chapters?videoid={video_id:}'
  10. _TEST = {
  11. 'url': 'http://www.jove.com/video/2744/electrode-positioning-montage-transcranial-direct-current',
  12. 'md5': '93723888d82dbd6ba8b3d7d0cd65dd2b',
  13. 'info_dict': {
  14. 'id': '2744',
  15. 'ext': 'mp4',
  16. 'title': 'Electrode Positioning and Montage in Transcranial Direct Current Stimulation',
  17. 'description': 'Transcranial direct current stimulation (tDCS) is an established technique to modulate cortical excitability1,2. It has been ...',
  18. 'thumbnail': 're:^https?://.*\.png$',
  19. 'upload_date': '20110523',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage(url, video_id)
  26. title = self._html_search_meta('citation_title', webpage, 'title')
  27. thumbnail = self._og_search_thumbnail(webpage)
  28. description = self._html_search_meta(
  29. 'description', webpage, 'description', fatal=False)
  30. publish_date = self._html_search_meta(
  31. 'citation_publication_date', webpage, 'publish date', fatal=False)
  32. if publish_date:
  33. publish_date = datetime.strptime(publish_date,
  34. '%Y/%m/%d').strftime('%Y%m%d')
  35. # Not the same as video_id.
  36. chapters_id = self._html_search_regex(
  37. r'/video-chapters\?videoid=([0-9]+)', webpage, 'chapters id')
  38. chapters_xml = self._download_xml(
  39. self._CHAPTERS_URL.format(video_id=chapters_id),
  40. video_id, note='Downloading chapter XML',
  41. errnote='Failed to download chapter XML'
  42. )
  43. video_url = chapters_xml.attrib.get('video')
  44. if not video_url:
  45. raise ExtractorError('Failed to get the video URL')
  46. ext = determine_ext(video_url)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'url': video_url,
  51. 'ext': ext,
  52. 'thumbnail': thumbnail,
  53. 'description': description,
  54. 'upload_date': publish_date,
  55. }