Var for index name
This commit is contained in:
@@ -66,6 +66,8 @@ class ITunesParser:
|
||||
"""
|
||||
Parse an iTunes Library and produce JSON - for ELS
|
||||
"""
|
||||
ELS_INDEX_NAME = "itunessongs"
|
||||
|
||||
def __init__(self):
|
||||
self._tracks = {}
|
||||
self._albums = {}
|
||||
@@ -231,21 +233,6 @@ class ITunesParser:
|
||||
|
||||
|
||||
class WriteElsJson:
|
||||
def to_json(self):
|
||||
"""
|
||||
Just do processSong()
|
||||
or do process_songs, then _write_artists and _write_albums.
|
||||
Note: process_songs do a process_artists and process_albums...
|
||||
This method suck.
|
||||
"""
|
||||
ret = self._process_songs()
|
||||
|
||||
self._write_artists()
|
||||
self._write_albums()
|
||||
|
||||
# return json.dumps(jsonObj, indent=indent, cls=SetEncoder)
|
||||
return ret
|
||||
|
||||
@staticmethod
|
||||
def write_artists(artists, output_file):
|
||||
"""
|
||||
@@ -258,7 +245,7 @@ class WriteElsJson:
|
||||
artist['Rating'] = round(artist['Rating'])
|
||||
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "artist", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "artist", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file_artist.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -279,7 +266,7 @@ class WriteElsJson:
|
||||
album['Rating'] = round(album['Rating'])
|
||||
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "album", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "album", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file_albums.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -296,7 +283,7 @@ class WriteElsJson:
|
||||
file = io.open(output_file, 'wb')
|
||||
for persistent_id, song in songs.items():
|
||||
json_track_index = {
|
||||
"index": {"_index": "itunessongs", "_type": "song", "_id": persistent_id}
|
||||
"index": {"_index": ITunesParser.ELS_INDEX_NAME, "_type": "song", "_id": persistent_id}
|
||||
}
|
||||
|
||||
file.write(bytes(json.dumps(json_track_index, indent=None, cls=SetEncoder), 'UTF-8'))
|
||||
@@ -314,7 +301,9 @@ DEFAULT_LIBRARY_FILE = os.path.expanduser(DEFAULT_LIBRARY_FILE_NAME)
|
||||
DEFAULT_OUTPUT_FILE = os.path.dirname(os.path.realpath(__file__)) + DEFAULT_OUTPUT_FILE_NAME
|
||||
|
||||
# Get options
|
||||
parser = argparse.ArgumentParser()
|
||||
parser = argparse.ArgumentParser(description="""
|
||||
Parse an iTunes XML library file to produce JSON file for ELS bulk operation.
|
||||
""")
|
||||
parser.add_argument('-f', '--file', default=DEFAULT_LIBRARY_FILE,
|
||||
help='iTunes Library XML file path (default: ./' + DEFAULT_LIBRARY_FILE_NAME + ')')
|
||||
parser.add_argument('-o', '--output', default=DEFAULT_OUTPUT_FILE,
|
||||
|
||||
Reference in New Issue
Block a user