2015-02-12 23:14:23 -08:00
|
|
|
|
# coding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
2015-02-15 19:50:57 -08:00
|
|
|
|
import re
|
|
|
|
|
|
2015-02-12 23:14:23 -08:00
|
|
|
|
from .common import InfoExtractor
|
|
|
|
|
from ..compat import compat_urlparse
|
2015-02-15 19:50:57 -08:00
|
|
|
|
from ..utils import (
|
|
|
|
|
float_or_none,
|
|
|
|
|
month_by_abbreviation,
|
2015-03-06 08:53:52 -08:00
|
|
|
|
ExtractorError,
|
2015-02-15 19:50:57 -08:00
|
|
|
|
)
|
2015-02-12 23:14:23 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class YamIE(InfoExtractor):
|
|
|
|
|
_VALID_URL = r'http://mymedia.yam.com/m/(?P<id>\d+)'
|
|
|
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
# An audio hosted on Yam
|
|
|
|
|
'url': 'http://mymedia.yam.com/m/2283921',
|
|
|
|
|
'md5': 'c011b8e262a52d5473d9c2e3c9963b9c',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '2283921',
|
|
|
|
|
'ext': 'mp3',
|
|
|
|
|
'title': '發現 - 趙薇 京華煙雲主題曲',
|
|
|
|
|
'uploader_id': 'princekt',
|
|
|
|
|
'upload_date': '20080807',
|
|
|
|
|
'duration': 313.0,
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
# An external video hosted on YouTube
|
2015-03-06 08:53:52 -08:00
|
|
|
|
'url': 'http://mymedia.yam.com/m/3599430',
|
|
|
|
|
'md5': '03127cf10d8f35d120a9e8e52e3b17c6',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'info_dict': {
|
2015-03-06 08:53:52 -08:00
|
|
|
|
'id': 'CNpEoQlrIgA',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'ext': 'mp4',
|
2015-03-06 08:53:52 -08:00
|
|
|
|
'upload_date': '20150306',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'uploader': '新莊社大瑜伽社',
|
2015-03-06 08:53:52 -08:00
|
|
|
|
'description': 'md5:11e2e405311633ace874f2e6226c8b17',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'uploader_id': '2323agoy',
|
2015-03-06 08:53:52 -08:00
|
|
|
|
'title': '20090412陽明山二子坪-1',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
}
|
2015-03-06 08:53:52 -08:00
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://mymedia.yam.com/m/3598173',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '3598173',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
},
|
|
|
|
|
'skip': 'cause Yam system error',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'http://mymedia.yam.com/m/3599437',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '3599437',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
},
|
|
|
|
|
'skip': 'invalid YouTube URL',
|
2015-02-12 23:14:23 -08:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2015-02-15 19:50:57 -08:00
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
page = self._download_webpage(url, video_id)
|
2015-02-12 23:14:23 -08:00
|
|
|
|
|
2015-03-06 08:53:52 -08:00
|
|
|
|
# Check for errors
|
|
|
|
|
system_msg = self._html_search_regex(
|
|
|
|
|
r'系統訊息(?:<br>|\n|\r)*([^<>]+)<br>', page, 'system message',
|
|
|
|
|
default=None)
|
|
|
|
|
if system_msg:
|
|
|
|
|
raise ExtractorError(system_msg, expected=True)
|
|
|
|
|
|
2015-02-12 23:14:23 -08:00
|
|
|
|
# Is it hosted externally on YouTube?
|
|
|
|
|
youtube_url = self._html_search_regex(
|
|
|
|
|
r'<embed src="(http://www.youtube.com/[^"]+)"',
|
|
|
|
|
page, 'YouTube url', default=None)
|
|
|
|
|
if youtube_url:
|
|
|
|
|
return self.url_result(youtube_url, 'Youtube')
|
|
|
|
|
|
|
|
|
|
api_page = self._download_webpage(
|
2015-02-15 19:50:57 -08:00
|
|
|
|
'http://mymedia.yam.com/api/a/?pID=' + video_id, video_id,
|
|
|
|
|
note='Downloading API page')
|
2015-02-12 23:14:23 -08:00
|
|
|
|
api_result_obj = compat_urlparse.parse_qs(api_page)
|
|
|
|
|
|
2015-02-15 19:50:57 -08:00
|
|
|
|
uploader_id = self._html_search_regex(
|
|
|
|
|
r'<!-- 發表作者 -->:[\n ]+<a href="/([a-z]+)"',
|
|
|
|
|
page, 'uploader id', fatal=False)
|
2015-02-12 23:14:23 -08:00
|
|
|
|
mobj = re.search(r'<!-- 發表於 -->(?P<mon>[A-Z][a-z]{2}) ' +
|
|
|
|
|
r'(?P<day>\d{1,2}), (?P<year>\d{4})', page)
|
2015-02-15 19:50:57 -08:00
|
|
|
|
if mobj:
|
|
|
|
|
upload_date = '%s%02d%02d' % (
|
|
|
|
|
mobj.group('year'),
|
|
|
|
|
month_by_abbreviation(mobj.group('mon')),
|
|
|
|
|
int(mobj.group('day')))
|
|
|
|
|
else:
|
|
|
|
|
upload_date = None
|
|
|
|
|
duration = float_or_none(api_result_obj['totaltime'][0], scale=1000)
|
2015-02-12 23:14:23 -08:00
|
|
|
|
|
|
|
|
|
return {
|
2015-02-15 19:50:57 -08:00
|
|
|
|
'id': video_id,
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'url': api_result_obj['mp3file'][0],
|
|
|
|
|
'title': self._html_search_meta('description', page),
|
2015-02-15 19:50:57 -08:00
|
|
|
|
'duration': duration,
|
|
|
|
|
'uploader_id': uploader_id,
|
2015-02-12 23:14:23 -08:00
|
|
|
|
'upload_date': upload_date,
|
|
|
|
|
}
|