yesjapan.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. HEADRequest,
  4. get_element_by_attribute,
  5. parse_iso8601,
  6. )
  7. class YesJapanIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?yesjapan\.com/video/(?P<slug>[A-Za-z0-9\-]*)_(?P<id>[A-Za-z0-9]+)\.html'
  9. _TEST = {
  10. 'url': 'http://www.yesjapan.com/video/japanese-in-5-20-wa-and-ga-particle-usages_726497834.html',
  11. 'md5': 'f0be416314e5be21a12b499b330c21cf',
  12. 'info_dict': {
  13. 'id': '726497834',
  14. 'title': 'Japanese in 5! #20 - WA And GA Particle Usages',
  15. 'description': 'This should clear up some issues most students of Japanese encounter with WA and GA....',
  16. 'ext': 'mp4',
  17. 'timestamp': 1416391590,
  18. 'upload_date': '20141119',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage(url, video_id)
  25. title = self._og_search_title(webpage)
  26. video_url = self._og_search_video_url(webpage)
  27. description = self._og_search_description(webpage)
  28. thumbnail = self._og_search_thumbnail(webpage)
  29. timestamp = None
  30. submit_info = get_element_by_attribute('class', 'pm-submit-data', webpage)
  31. if submit_info:
  32. timestamp = parse_iso8601(self._search_regex(
  33. r'datetime="([^"]+)"', submit_info, 'upload date', fatal=False, default=None))
  34. # attempt to resolve the final URL in order to get a proper extension
  35. redirect_req = HEADRequest(video_url)
  36. req = self._request_webpage(
  37. redirect_req, video_id, note='Resolving final URL', errnote='Could not resolve final URL', fatal=False)
  38. if req:
  39. video_url = req.geturl()
  40. formats = [{
  41. 'format_id': 'sd',
  42. 'url': video_url,
  43. }]
  44. return {
  45. 'id': video_id,
  46. 'title': title,
  47. 'formats': formats,
  48. 'description': description,
  49. 'timestamp': timestamp,
  50. 'thumbnail': thumbnail,
  51. }