thechive.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import unified_strdate
  5. class TheChiveIE(InfoExtractor):
  6. _VALID_URL = r'http://(www\.)?thechive\.com/[^/]+/[^/]+/[^/]+/(?P<video_id>[A-Za-z\-]+)'
  7. _TEST = {
  8. 'url': "http://thechive.com/2015/02/20/so-thats-what-a-set-of-redneck-bagpipes-sound-like-video/",
  9. 'md5': "366710dda77cfa727bdef3523ba8466f",
  10. 'info_dict': {
  11. 'id': "so-thats-what-a-set-of-redneck-bagpipes-sound-like-video",
  12. 'title': "So that's what a set of redneck bagpipes sound like... (Video)",
  13. 'description': "Okay that was pretty good. Now play Freebird!...",
  14. 'thumbnail': "https://thechive.files.wordpress.com/2015/02/0_07dghz0w-thumbnail2.jpg",
  15. 'author': "Ben",
  16. 'upload_date': "20150220",
  17. 'ext': "mp4"
  18. }
  19. }
  20. def _real_extract(self, url):
  21. mobj = re.match(self._VALID_URL, url)
  22. video_id = mobj.group('video_id')
  23. webpage = self._download_webpage(url, video_id)
  24. title = self._og_search_title(webpage)
  25. description = self._html_search_regex(r'(?s)<meta name="description" content="(.*?)" />', webpage, 'description')
  26. thumbnail = self._og_search_thumbnail(webpage)
  27. author = self._html_search_regex(
  28. r'(?s)itemprop="author">(.+?)</span>', webpage, 'author', fatal=False).capitalize()
  29. upload_date = unified_strdate(self._html_search_regex(
  30. r'(?s)itemprop="datePublished" datetime="(.+?)">', webpage, 'upload_date', fatal=False))
  31. # Adapted from extractor/musicvault.py
  32. VIDEO_URL_TEMPLATE = 'http://cdnapi.kaltura.com/p/%(uid)s/sp/%(wid)s/playManifest/entryId/%(entry_id)s/format/url/protocol/http'
  33. kaltura_id = self._search_regex(
  34. r'entry_id=([^"]+)',
  35. webpage, 'kaltura ID')
  36. video_url = VIDEO_URL_TEMPLATE % {
  37. 'entry_id': kaltura_id,
  38. 'wid': self._search_regex(r'partner_id/([0-9]+)\?', webpage, 'wid'),
  39. 'uid': self._search_regex(r'uiconf_id/([0-9]+)/', webpage, 'uid'),
  40. }
  41. return {
  42. 'url': video_url,
  43. 'id': video_id,
  44. 'title': title,
  45. 'description': description,
  46. 'thumbnail': thumbnail,
  47. 'author': author,
  48. 'upload_date': upload_date,
  49. 'ext': 'mp4'
  50. }