mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-06 11:34:14 +09:00
Make metadata work for more than just Youtube.
This commit is contained in:
parent
a1a7472868
commit
c753a38cda
@ -572,8 +572,8 @@ class YoutubeDL(object):
|
||||
|
||||
if success:
|
||||
try:
|
||||
self.set_xattrs(filename, info_dict)
|
||||
self.post_process(filename, info_dict)
|
||||
self.set_xattrs(filename, info_dict)
|
||||
except (PostProcessingError) as err:
|
||||
self.report_error(u'postprocessing: %s' % str(err))
|
||||
return
|
||||
@ -604,7 +604,7 @@ class YoutubeDL(object):
|
||||
return datestring
|
||||
|
||||
def set_xattrs(self, filename, info_dict):
|
||||
""" Set extended attributes on downloaded files (if the xattr module is installed). """
|
||||
""" Set extended attributes on downloaded file (if the xattr module is installed). """
|
||||
#
|
||||
# More info about extended attributes for media:
|
||||
# http://freedesktop.org/wiki/CommonExtendedAttributes/
|
||||
@ -620,18 +620,25 @@ class YoutubeDL(object):
|
||||
|
||||
self.to_screen('[download] Writing metadata to file')
|
||||
|
||||
xattrs = {
|
||||
'user.xdg.referrer.url': 'https://www.youtube.com/watch?v='+info_dict['id'],
|
||||
# 'user.xdg.comment': info_dict['description'],
|
||||
'user.dublincore.title': info_dict['fulltitle'],
|
||||
'user.dublincore.date': self.hyphenate_date(info_dict['upload_date']),
|
||||
'user.dublincore.description': info_dict['description'],
|
||||
'user.dublincore.contributor': info_dict['uploader'],
|
||||
'user.dublincore.format': info_dict['format'],
|
||||
xattr_mapping = {
|
||||
'user.xdg.referrer.url': 'referrer',
|
||||
# 'user.xdg.comment': 'description',
|
||||
'user.dublincore.title': 'fulltitle',
|
||||
'user.dublincore.date': 'upload_date',
|
||||
'user.dublincore.description': 'description',
|
||||
'user.dublincore.contributor': 'uploader',
|
||||
'user.dublincore.format': 'format',
|
||||
}
|
||||
|
||||
for key, value in xattrs.items():
|
||||
xattr.set(filename, key, value)
|
||||
for xattrname, infoname in xattr_mapping.items():
|
||||
|
||||
value = info_dict.get(infoname)
|
||||
|
||||
if value:
|
||||
if infoname == "upload_date":
|
||||
value = self.hyphenate_date(value)
|
||||
|
||||
xattr.set(filename, xattrname, value)
|
||||
|
||||
return True
|
||||
|
||||
@ -639,7 +646,7 @@ class YoutubeDL(object):
|
||||
# The filesystem doesn't support extended attributes
|
||||
return False
|
||||
except ImportError:
|
||||
# The 'xattr' module wasn't installed, so fail.
|
||||
# The 'xattr' module wasn't installed.
|
||||
return False
|
||||
|
||||
def post_process(self, filename, ie_info):
|
||||
|
@ -19,6 +19,7 @@ class VimeoIE(InfoExtractor):
|
||||
# _VALID_URL matches Vimeo URLs
|
||||
_VALID_URL = r'(?P<proto>https?://)?(?:(?:www|player)\.)?vimeo(?P<pro>pro)?\.com/(?:(?:(?:groups|album)/[^/]+)|(?:.*?)/)?(?P<direct_link>play_redirect_hls\?clip_id=)?(?:videos?/)?(?P<id>[0-9]+)(?:[?].*)?$'
|
||||
_NETRC_MACHINE = 'vimeo'
|
||||
_REFERRER_URL = 'https://vimeo.com/%s'
|
||||
IE_NAME = u'vimeo'
|
||||
_TESTS = [
|
||||
{
|
||||
@ -203,15 +204,16 @@ class VimeoIE(InfoExtractor):
|
||||
%(video_id, sig, timestamp, video_quality, video_codec.upper())
|
||||
|
||||
return [{
|
||||
'id': video_id,
|
||||
'url': video_url,
|
||||
'uploader': video_uploader,
|
||||
'id': video_id,
|
||||
'url': video_url,
|
||||
'referrer': self._REFERRER_URL % video_id,
|
||||
'uploader': video_uploader,
|
||||
'uploader_id': video_uploader_id,
|
||||
'upload_date': video_upload_date,
|
||||
'title': video_title,
|
||||
'ext': video_extension,
|
||||
'thumbnail': video_thumbnail,
|
||||
'description': video_description,
|
||||
'upload_date': video_upload_date,
|
||||
'title': video_title,
|
||||
'ext': video_extension,
|
||||
'thumbnail': video_thumbnail,
|
||||
'description': video_description,
|
||||
}]
|
||||
|
||||
|
||||
|
@ -40,6 +40,8 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
|
||||
_LANG_URL = r'https://www.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'
|
||||
_AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
|
||||
_NETRC_MACHINE = 'youtube'
|
||||
_REFERRER_URL = 'https://www.youtube.com/watch?v=%s'
|
||||
|
||||
# If True it will raise an error if no login info is provided
|
||||
_LOGIN_REQUIRED = False
|
||||
|
||||
@ -1477,19 +1479,20 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
|
||||
' ('+self._special_itags[format_param]+')' if format_param in self._special_itags else '')
|
||||
|
||||
results.append({
|
||||
'id': video_id,
|
||||
'url': video_real_url,
|
||||
'uploader': video_uploader,
|
||||
'id': video_id,
|
||||
'url': video_real_url,
|
||||
'referrer': self._REFERRER_URL % video_id,
|
||||
'uploader': video_uploader,
|
||||
'uploader_id': video_uploader_id,
|
||||
'upload_date': upload_date,
|
||||
'title': video_title,
|
||||
'ext': video_extension,
|
||||
'format': video_format,
|
||||
'thumbnail': video_thumbnail,
|
||||
'description': video_description,
|
||||
'player_url': player_url,
|
||||
'subtitles': video_subtitles,
|
||||
'duration': video_duration
|
||||
'upload_date': upload_date,
|
||||
'title': video_title,
|
||||
'ext': video_extension,
|
||||
'format': video_format,
|
||||
'thumbnail': video_thumbnail,
|
||||
'description': video_description,
|
||||
'player_url': player_url,
|
||||
'subtitles': video_subtitles,
|
||||
'duration': video_duration
|
||||
})
|
||||
return results
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user