mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-07-07 03:54: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:
|
if success:
|
||||||
try:
|
try:
|
||||||
self.set_xattrs(filename, info_dict)
|
|
||||||
self.post_process(filename, info_dict)
|
self.post_process(filename, info_dict)
|
||||||
|
self.set_xattrs(filename, info_dict)
|
||||||
except (PostProcessingError) as err:
|
except (PostProcessingError) as err:
|
||||||
self.report_error(u'postprocessing: %s' % str(err))
|
self.report_error(u'postprocessing: %s' % str(err))
|
||||||
return
|
return
|
||||||
@ -604,7 +604,7 @@ class YoutubeDL(object):
|
|||||||
return datestring
|
return datestring
|
||||||
|
|
||||||
def set_xattrs(self, filename, info_dict):
|
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:
|
# More info about extended attributes for media:
|
||||||
# http://freedesktop.org/wiki/CommonExtendedAttributes/
|
# http://freedesktop.org/wiki/CommonExtendedAttributes/
|
||||||
@ -620,18 +620,25 @@ class YoutubeDL(object):
|
|||||||
|
|
||||||
self.to_screen('[download] Writing metadata to file')
|
self.to_screen('[download] Writing metadata to file')
|
||||||
|
|
||||||
xattrs = {
|
xattr_mapping = {
|
||||||
'user.xdg.referrer.url': 'https://www.youtube.com/watch?v='+info_dict['id'],
|
'user.xdg.referrer.url': 'referrer',
|
||||||
# 'user.xdg.comment': info_dict['description'],
|
# 'user.xdg.comment': 'description',
|
||||||
'user.dublincore.title': info_dict['fulltitle'],
|
'user.dublincore.title': 'fulltitle',
|
||||||
'user.dublincore.date': self.hyphenate_date(info_dict['upload_date']),
|
'user.dublincore.date': 'upload_date',
|
||||||
'user.dublincore.description': info_dict['description'],
|
'user.dublincore.description': 'description',
|
||||||
'user.dublincore.contributor': info_dict['uploader'],
|
'user.dublincore.contributor': 'uploader',
|
||||||
'user.dublincore.format': info_dict['format'],
|
'user.dublincore.format': 'format',
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, value in xattrs.items():
|
for xattrname, infoname in xattr_mapping.items():
|
||||||
xattr.set(filename, key, value)
|
|
||||||
|
value = info_dict.get(infoname)
|
||||||
|
|
||||||
|
if value:
|
||||||
|
if infoname == "upload_date":
|
||||||
|
value = self.hyphenate_date(value)
|
||||||
|
|
||||||
|
xattr.set(filename, xattrname, value)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -639,7 +646,7 @@ class YoutubeDL(object):
|
|||||||
# The filesystem doesn't support extended attributes
|
# The filesystem doesn't support extended attributes
|
||||||
return False
|
return False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# The 'xattr' module wasn't installed, so fail.
|
# The 'xattr' module wasn't installed.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def post_process(self, filename, ie_info):
|
def post_process(self, filename, ie_info):
|
||||||
|
@ -19,6 +19,7 @@ class VimeoIE(InfoExtractor):
|
|||||||
# _VALID_URL matches Vimeo URLs
|
# _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]+)(?:[?].*)?$'
|
_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'
|
_NETRC_MACHINE = 'vimeo'
|
||||||
|
_REFERRER_URL = 'https://vimeo.com/%s'
|
||||||
IE_NAME = u'vimeo'
|
IE_NAME = u'vimeo'
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
{
|
{
|
||||||
@ -205,6 +206,7 @@ class VimeoIE(InfoExtractor):
|
|||||||
return [{
|
return [{
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_url,
|
'url': video_url,
|
||||||
|
'referrer': self._REFERRER_URL % video_id,
|
||||||
'uploader': video_uploader,
|
'uploader': video_uploader,
|
||||||
'uploader_id': video_uploader_id,
|
'uploader_id': video_uploader_id,
|
||||||
'upload_date': video_upload_date,
|
'upload_date': video_upload_date,
|
||||||
|
@ -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'
|
_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'
|
_AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
|
||||||
_NETRC_MACHINE = 'youtube'
|
_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
|
# If True it will raise an error if no login info is provided
|
||||||
_LOGIN_REQUIRED = False
|
_LOGIN_REQUIRED = False
|
||||||
|
|
||||||
@ -1479,6 +1481,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
|
|||||||
results.append({
|
results.append({
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'url': video_real_url,
|
'url': video_real_url,
|
||||||
|
'referrer': self._REFERRER_URL % video_id,
|
||||||
'uploader': video_uploader,
|
'uploader': video_uploader,
|
||||||
'uploader_id': video_uploader_id,
|
'uploader_id': video_uploader_id,
|
||||||
'upload_date': upload_date,
|
'upload_date': upload_date,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user