Make metadata work for more than just Youtube.

This commit is contained in:
epitron 2013-09-27 17:00:45 -04:00
parent a1a7472868
commit c753a38cda
3 changed files with 45 additions and 33 deletions

View File

@ -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):

View File

@ -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 = [
{ {
@ -203,15 +204,16 @@ class VimeoIE(InfoExtractor):
%(video_id, sig, timestamp, video_quality, video_codec.upper()) %(video_id, sig, timestamp, video_quality, video_codec.upper())
return [{ return [{
'id': video_id, 'id': video_id,
'url': video_url, 'url': video_url,
'uploader': video_uploader, 'referrer': self._REFERRER_URL % video_id,
'uploader': video_uploader,
'uploader_id': video_uploader_id, 'uploader_id': video_uploader_id,
'upload_date': video_upload_date, 'upload_date': video_upload_date,
'title': video_title, 'title': video_title,
'ext': video_extension, 'ext': video_extension,
'thumbnail': video_thumbnail, 'thumbnail': video_thumbnail,
'description': video_description, 'description': video_description,
}] }]

View File

@ -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
@ -1477,19 +1479,20 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
' ('+self._special_itags[format_param]+')' if format_param in self._special_itags else '') ' ('+self._special_itags[format_param]+')' if format_param in self._special_itags else '')
results.append({ results.append({
'id': video_id, 'id': video_id,
'url': video_real_url, 'url': video_real_url,
'uploader': video_uploader, 'referrer': self._REFERRER_URL % video_id,
'uploader': video_uploader,
'uploader_id': video_uploader_id, 'uploader_id': video_uploader_id,
'upload_date': upload_date, 'upload_date': upload_date,
'title': video_title, 'title': video_title,
'ext': video_extension, 'ext': video_extension,
'format': video_format, 'format': video_format,
'thumbnail': video_thumbnail, 'thumbnail': video_thumbnail,
'description': video_description, 'description': video_description,
'player_url': player_url, 'player_url': player_url,
'subtitles': video_subtitles, 'subtitles': video_subtitles,
'duration': video_duration 'duration': video_duration
}) })
return results return results