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.

81 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. float_or_none,
  8. month_by_abbreviation,
  9. )
  10. class YamIE(InfoExtractor):
  11. _VALID_URL = r'http://mymedia.yam.com/m/(?P<id>\d+)'
  12. _TESTS = [{
  13. # An audio hosted on Yam
  14. 'url': 'http://mymedia.yam.com/m/2283921',
  15. 'md5': 'c011b8e262a52d5473d9c2e3c9963b9c',
  16. 'info_dict': {
  17. 'id': '2283921',
  18. 'ext': 'mp3',
  19. 'title': '發現 - 趙薇 京華煙雲主題曲',
  20. 'uploader_id': 'princekt',
  21. 'upload_date': '20080807',
  22. 'duration': 313.0,
  23. }
  24. }, {
  25. # An external video hosted on YouTube
  26. 'url': 'http://mymedia.yam.com/m/3598173',
  27. 'md5': '0238ceec479c654e8c2f1223755bf3e9',
  28. 'info_dict': {
  29. 'id': 'pJ2Deys283c',
  30. 'ext': 'mp4',
  31. 'upload_date': '20150202',
  32. 'uploader': '新莊社大瑜伽社',
  33. 'description': 'md5:f5cc72f0baf259a70fb731654b0d2eff',
  34. 'uploader_id': '2323agoy',
  35. 'title': '外婆的澎湖灣KTV-潘安邦',
  36. }
  37. }]
  38. def _real_extract(self, url):
  39. video_id = self._match_id(url)
  40. page = self._download_webpage(url, video_id)
  41. # Is it hosted externally on YouTube?
  42. youtube_url = self._html_search_regex(
  43. r'<embed src="(http://www.youtube.com/[^"]+)"',
  44. page, 'YouTube url', default=None)
  45. if youtube_url:
  46. return self.url_result(youtube_url, 'Youtube')
  47. api_page = self._download_webpage(
  48. 'http://mymedia.yam.com/api/a/?pID=' + video_id, video_id,
  49. note='Downloading API page')
  50. api_result_obj = compat_urlparse.parse_qs(api_page)
  51. uploader_id = self._html_search_regex(
  52. r'<!-- 發表作者 -->:[\n ]+<a href="/([a-z]+)"',
  53. page, 'uploader id', fatal=False)
  54. mobj = re.search(r'<!-- 發表於 -->(?P<mon>[A-Z][a-z]{2}) ' +
  55. r'(?P<day>\d{1,2}), (?P<year>\d{4})', page)
  56. if mobj:
  57. upload_date = '%s%02d%02d' % (
  58. mobj.group('year'),
  59. month_by_abbreviation(mobj.group('mon')),
  60. int(mobj.group('day')))
  61. else:
  62. upload_date = None
  63. duration = float_or_none(api_result_obj['totaltime'][0], scale=1000)
  64. return {
  65. 'id': video_id,
  66. 'url': api_result_obj['mp3file'][0],
  67. 'title': self._html_search_meta('description', page),
  68. 'duration': duration,
  69. 'uploader_id': uploader_id,
  70. 'upload_date': upload_date,
  71. }