mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 01:02:59 -07:00
Add ability to export custom fields
This commit is contained in:
parent
112811190e
commit
4ee9dbab41
2 changed files with 48 additions and 8 deletions
|
@ -49,21 +49,32 @@ class Export(object):
|
||||||
'movie',
|
'movie',
|
||||||
'show', 'season', 'episode',
|
'show', 'season', 'episode',
|
||||||
'artist', 'album', 'track',
|
'artist', 'album', 'track',
|
||||||
'photo album', 'photo',
|
'photoalbum', 'photo',
|
||||||
'collection',
|
'collection',
|
||||||
'playlist'
|
'playlist'
|
||||||
)
|
)
|
||||||
METADATA_LEVELS = (1, 2, 3, 9)
|
METADATA_LEVELS = (1, 2, 3, 9)
|
||||||
MEDIA_INFO_LEVELS = (1, 2, 3, 9)
|
MEDIA_INFO_LEVELS = (1, 2, 3, 9)
|
||||||
|
CUSTOM_FIELD_KEYS = (
|
||||||
|
'movies',
|
||||||
|
'shows', 'seasons', 'episodes',
|
||||||
|
'artists', 'albums', 'tracks',
|
||||||
|
'photoalbums', 'photos',
|
||||||
|
'collections', 'children',
|
||||||
|
'playlists', 'items'
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, section_id=None, rating_key=None, file_format='json',
|
def __init__(self, section_id=None, rating_key=None, file_format='json',
|
||||||
metadata_level=1, media_info_level=1, include_images=False):
|
metadata_level=1, media_info_level=1, include_images=False,
|
||||||
|
custom_fields=''):
|
||||||
self.section_id = helpers.cast_to_int(section_id)
|
self.section_id = helpers.cast_to_int(section_id)
|
||||||
self.rating_key = helpers.cast_to_int(rating_key)
|
self.rating_key = helpers.cast_to_int(rating_key)
|
||||||
self.file_format = file_format
|
self.file_format = file_format
|
||||||
self.metadata_level = helpers.cast_to_int(metadata_level)
|
self.metadata_level = helpers.cast_to_int(metadata_level)
|
||||||
self.media_info_level = helpers.cast_to_int(media_info_level)
|
self.media_info_level = helpers.cast_to_int(media_info_level)
|
||||||
self.include_images = include_images
|
self.include_images = include_images
|
||||||
|
self.custom_fields = custom_fields
|
||||||
|
self._custom_fields = {}
|
||||||
|
|
||||||
self.timestamp = helpers.timestamp()
|
self.timestamp = helpers.timestamp()
|
||||||
|
|
||||||
|
@ -955,7 +966,7 @@ class Export(object):
|
||||||
'artist': artist_attrs,
|
'artist': artist_attrs,
|
||||||
'album': album_attrs,
|
'album': album_attrs,
|
||||||
'track': track_attrs,
|
'track': track_attrs,
|
||||||
'photo album': photo_album_attrs,
|
'photoalbum': photo_album_attrs,
|
||||||
'photo': photo_attrs,
|
'photo': photo_attrs,
|
||||||
'collection': collection_attrs,
|
'collection': collection_attrs,
|
||||||
'playlist': playlist_attrs,
|
'playlist': playlist_attrs,
|
||||||
|
@ -1246,7 +1257,7 @@ class Export(object):
|
||||||
return _metadata_levels, _media_info_levels
|
return _metadata_levels, _media_info_levels
|
||||||
|
|
||||||
def photo_album_levels():
|
def photo_album_levels():
|
||||||
_media_type = 'photo album'
|
_media_type = 'photoalbum'
|
||||||
_metadata_levels = {
|
_metadata_levels = {
|
||||||
1: [
|
1: [
|
||||||
'ratingKey', 'title', 'titleSort', 'addedAt',
|
'ratingKey', 'title', 'titleSort', 'addedAt',
|
||||||
|
@ -1351,7 +1362,7 @@ class Export(object):
|
||||||
'artist': artist_levels,
|
'artist': artist_levels,
|
||||||
'album': album_levels,
|
'album': album_levels,
|
||||||
'track': track_levels,
|
'track': track_levels,
|
||||||
'photo album': photo_album_levels,
|
'photoalbum': photo_album_levels,
|
||||||
'photo': photo_levels,
|
'photo': photo_levels,
|
||||||
'collection': collection_levels,
|
'collection': collection_levels,
|
||||||
'playlist': playlist_levels
|
'playlist': playlist_levels
|
||||||
|
@ -1408,7 +1419,7 @@ class Export(object):
|
||||||
item_title = item.title
|
item_title = item.title
|
||||||
|
|
||||||
if self.media_type == 'photo' and item.TAG == 'Directory':
|
if self.media_type == 'photo' and item.TAG == 'Directory':
|
||||||
self.media_type = 'photo album'
|
self.media_type = 'photoalbum'
|
||||||
|
|
||||||
filename = '{} - {} [{}].{}'.format(
|
filename = '{} - {} [{}].{}'.format(
|
||||||
self.media_type.title(), item_title, self.rating_key,
|
self.media_type.title(), item_title, self.rating_key,
|
||||||
|
@ -1442,6 +1453,8 @@ class Export(object):
|
||||||
if self.include_images and self.media_type not in ('movie', 'show', 'season', 'artist', 'album'):
|
if self.include_images and self.media_type not in ('movie', 'show', 'season', 'artist', 'album'):
|
||||||
self.include_images = False
|
self.include_images = False
|
||||||
|
|
||||||
|
self._process_custom_fields()
|
||||||
|
|
||||||
self.filename = '{}.{}'.format(helpers.clean_filename(filename), self.file_format)
|
self.filename = '{}.{}'.format(helpers.clean_filename(filename), self.file_format)
|
||||||
self.export_id = self.add_export()
|
self.export_id = self.add_export()
|
||||||
if not self.export_id:
|
if not self.export_id:
|
||||||
|
@ -1452,6 +1465,22 @@ class Export(object):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _process_custom_fields(self):
|
||||||
|
for field in self.custom_fields.split(','):
|
||||||
|
field = field.strip()
|
||||||
|
|
||||||
|
media_type = self.media_type
|
||||||
|
for key in self.CUSTOM_FIELD_KEYS:
|
||||||
|
if field.startswith(key + '.'):
|
||||||
|
media_type, field = field.split('.', maxsplit=1)
|
||||||
|
if key != 'children':
|
||||||
|
media_type = media_type[:-1]
|
||||||
|
|
||||||
|
if media_type in self._custom_fields:
|
||||||
|
self._custom_fields[media_type].add(field)
|
||||||
|
else:
|
||||||
|
self._custom_fields[media_type] = {field}
|
||||||
|
|
||||||
def add_export(self):
|
def add_export(self):
|
||||||
keys = {'timestamp': self.timestamp,
|
keys = {'timestamp': self.timestamp,
|
||||||
'section_id': self.section_id,
|
'section_id': self.section_id,
|
||||||
|
@ -1559,6 +1588,12 @@ class Export(object):
|
||||||
if image_attr in media_attrs:
|
if image_attr in media_attrs:
|
||||||
export_attrs_set.add(image_attr)
|
export_attrs_set.add(image_attr)
|
||||||
|
|
||||||
|
export_attrs_set.update(self._custom_fields.get(media_type, []))
|
||||||
|
if self.media_type == 'collection' and 'children' in self._custom_fields:
|
||||||
|
export_attrs_set.update(self._custom_fields['children'])
|
||||||
|
elif self.media_type == 'playlist' and 'items' in self._custom_fields:
|
||||||
|
export_attrs_set.update(self._custom_fields['items'])
|
||||||
|
|
||||||
for attr in export_attrs_set:
|
for attr in export_attrs_set:
|
||||||
try:
|
try:
|
||||||
value = helpers.get_dict_value_by_path(media_attrs, attr)
|
value = helpers.get_dict_value_by_path(media_attrs, attr)
|
||||||
|
|
|
@ -6492,7 +6492,8 @@ class WebInterface(object):
|
||||||
@requireAuth(member_of("admin"))
|
@requireAuth(member_of("admin"))
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def export_metadata(self, section_id=None, rating_key=None, file_format='json',
|
def export_metadata(self, section_id=None, rating_key=None, file_format='json',
|
||||||
metadata_level=1, media_info_level=1, include_images=False, **kwargs):
|
metadata_level=1, media_info_level=1, include_images=False,
|
||||||
|
custom_fields='', **kwargs):
|
||||||
""" Export library or media metadata to a file
|
""" Export library or media metadata to a file
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -6504,6 +6505,9 @@ class WebInterface(object):
|
||||||
file_format (str): 'json' (default) or 'csv'
|
file_format (str): 'json' (default) or 'csv'
|
||||||
metadata_level (int): The level of metadata to export (default 1)
|
metadata_level (int): The level of metadata to export (default 1)
|
||||||
media_info_level (int): The level of media info to export (default 1)
|
media_info_level (int): The level of media info to export (default 1)
|
||||||
|
include_images (bool): True or False to export artwork and posters images
|
||||||
|
custom_fields (str): Comma separated list of custom fields to export
|
||||||
|
in addition to the export level selected
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
json:
|
json:
|
||||||
|
@ -6517,7 +6521,8 @@ class WebInterface(object):
|
||||||
file_format=file_format,
|
file_format=file_format,
|
||||||
metadata_level=metadata_level,
|
metadata_level=metadata_level,
|
||||||
media_info_level=media_info_level,
|
media_info_level=media_info_level,
|
||||||
include_images=helpers.bool_true(include_images)).export()
|
include_images=helpers.bool_true(include_images),
|
||||||
|
custom_fields=custom_fields).export()
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return {'result': 'success', 'message': 'Metadata export has started.'}
|
return {'result': 'success', 'message': 'Metadata export has started.'}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue