jove.py 2.9 KB

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