Move ratingKey, title, and titleSort to front of csv headers

This commit is contained in:
JonnyWong16 2020-10-15 22:10:42 -07:00
parent 44c643d7da
commit 2578592cc7
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 11 additions and 0 deletions

View file

@ -1728,6 +1728,9 @@ class Export(object):
if self.file_format == 'csv': if self.file_format == 'csv':
csv_data = helpers.flatten_dict(result) csv_data = helpers.flatten_dict(result)
csv_headers = sorted(set().union(*csv_data), key=helpers.sort_attrs) csv_headers = sorted(set().union(*csv_data), key=helpers.sort_attrs)
# Move ratingKey, title, and titleSort to front of headers
for key in ('titleSort', 'title', 'ratingKey'):
csv_headers = helpers.move_to_front(csv_headers, key)
with open(filepath, 'w', encoding='utf-8', newline='') as outfile: with open(filepath, 'w', encoding='utf-8', newline='') as outfile:
writer = csv.DictWriter(outfile, csv_headers) writer = csv.DictWriter(outfile, csv_headers)
writer.writeheader() writer.writeheader()

View file

@ -1465,6 +1465,14 @@ def dict_to_xml(d, root_node=None, indent=None, level=0):
return xml return xml
def move_to_front(l, value):
try:
l.insert(0, l.pop(l.index(value)))
except (ValueError, IndexError):
pass
return l
def is_hdr(bit_depth, color_space): def is_hdr(bit_depth, color_space):
bit_depth = cast_to_int(bit_depth) bit_depth = cast_to_int(bit_depth)
return bit_depth > 8 and color_space == 'bt2020nc' return bit_depth > 8 and color_space == 'bt2020nc'