jove.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. unified_strdate
  5. )
  6. class JoveIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?jove\.com/video/(?P<id>[0-9]+)'
  8. _CHAPTERS_URL = 'http://www.jove.com/video-chapters?videoid={video_id:}'
  9. _TESTS = [
  10. {
  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': 'md5:015dd4509649c0908bc27f049e0262c6',
  18. 'thumbnail': r're:^https?://.*\.png$',
  19. 'upload_date': '20110523',
  20. }
  21. },
  22. {
  23. 'url': 'http://www.jove.com/video/51796/culturing-caenorhabditis-elegans-axenic-liquid-media-creation',
  24. 'md5': '914aeb356f416811d911996434811beb',
  25. 'info_dict': {
  26. 'id': '51796',
  27. 'ext': 'mp4',
  28. 'title': 'Culturing Caenorhabditis elegans in Axenic Liquid Media and Creation of Transgenic Worms by Microparticle Bombardment',
  29. 'description': 'md5:35ff029261900583970c4023b70f1dc9',
  30. 'thumbnail': r're:^https?://.*\.png$',
  31. 'upload_date': '20140802',
  32. }
  33. },
  34. ]
  35. def _real_extract(self, url):
  36. mobj = self._match_valid_url(url)
  37. video_id = mobj.group('id')
  38. webpage = self._download_webpage(url, video_id)
  39. chapters_id = self._html_search_regex(
  40. r'/video-chapters\?videoid=([0-9]+)', webpage, 'chapters id')
  41. chapters_xml = self._download_xml(
  42. self._CHAPTERS_URL.format(video_id=chapters_id),
  43. video_id, note='Downloading chapters XML',
  44. errnote='Failed to download chapters XML')
  45. video_url = chapters_xml.attrib.get('video')
  46. if not video_url:
  47. raise ExtractorError('Failed to get the video URL')
  48. title = self._html_search_meta('citation_title', webpage, 'title')
  49. thumbnail = self._og_search_thumbnail(webpage)
  50. description = self._html_search_regex(
  51. r'<div id="section_body_summary"><p class="jove_content">(.+?)</p>',
  52. webpage, 'description', fatal=False)
  53. publish_date = unified_strdate(self._html_search_meta(
  54. 'citation_publication_date', webpage, 'publish date', fatal=False))
  55. comment_count = int(self._html_search_regex(
  56. r'<meta name="num_comments" content="(\d+) Comments?"',
  57. webpage, 'comment count', fatal=False))
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'url': video_url,
  62. 'thumbnail': thumbnail,
  63. 'description': description,
  64. 'upload_date': publish_date,
  65. 'comment_count': comment_count,
  66. }