You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

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