Doc + clean
This commit is contained in:
@@ -70,37 +70,32 @@ class ITunesParser:
|
|||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
"""
|
"""
|
||||||
Just do processSong() - This method suck
|
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()
|
ret = self._process_songs()
|
||||||
|
|
||||||
# self._write_artists()
|
self._write_artists()
|
||||||
# self._write_albums()
|
self._write_albums()
|
||||||
|
|
||||||
# return json.dumps(jsonObj, indent=indent, cls=SetEncoder)
|
# return json.dumps(jsonObj, indent=indent, cls=SetEncoder)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def to_json_p(self): # TODO parameter, rating=4):
|
|
||||||
"""
|
|
||||||
Produce JSON-P content
|
|
||||||
"""
|
|
||||||
|
|
||||||
json_content = self.to_json()
|
|
||||||
jsonp = ';itgCallback(' + json_content + ');'
|
|
||||||
return jsonp
|
|
||||||
|
|
||||||
|
|
||||||
def _read_tracks(self):
|
def _read_tracks(self):
|
||||||
"""
|
"""
|
||||||
Read library and return Tracks part
|
Read library and return Tracks part
|
||||||
"""
|
"""
|
||||||
plist = plistlib.readPlist(self.library_file)
|
plist = plistlib.readPlist(self.library_file)
|
||||||
|
print(plist['Features'])
|
||||||
return plist['Tracks']
|
return plist['Tracks']
|
||||||
|
|
||||||
def _process_songs(self):
|
def _process_songs(self):
|
||||||
"""
|
"""
|
||||||
Return an output JSON for an ELS Bulk request - Not a correct format
|
Return an output JSON for an ELS Bulk request - Not a correct format
|
||||||
|
This method call process_album & process_artist
|
||||||
TODO Just return a _correct_ JSON and treat in another place/class
|
TODO Just return a _correct_ JSON and treat in another place/class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -152,6 +147,7 @@ class ITunesParser:
|
|||||||
|
|
||||||
# Compute information
|
# Compute information
|
||||||
rating = (track['Rating'] // 20) if 'Rating' in track else 0
|
rating = (track['Rating'] // 20) if 'Rating' in track else 0
|
||||||
|
# TODO Improve rating that currently can go ahead to 100
|
||||||
plays = track['Play Count'] if 'Play Count' in track else 0
|
plays = track['Play Count'] if 'Play Count' in track else 0
|
||||||
|
|
||||||
self._artists[akey]['count'] += 1
|
self._artists[akey]['count'] += 1
|
||||||
@@ -190,6 +186,7 @@ class ITunesParser:
|
|||||||
|
|
||||||
self._albums[akey]['count'] += 1
|
self._albums[akey]['count'] += 1
|
||||||
self._albums[akey]['rating'] += rating
|
self._albums[akey]['rating'] += rating
|
||||||
|
# TODO Improve rating that currently can go ahead to 100
|
||||||
self._albums[akey]['plays'] += plays
|
self._albums[akey]['plays'] += plays
|
||||||
|
|
||||||
if 'Genre' not in track:
|
if 'Genre' not in track:
|
||||||
@@ -240,7 +237,7 @@ class ITunesParser:
|
|||||||
#### main block ####
|
#### main block ####
|
||||||
|
|
||||||
# Default input & output files
|
# Default input & output files
|
||||||
DEFAULT_LIBRARY_FILE = os.path.expanduser('iTunesMiniLibrary.xml')
|
DEFAULT_LIBRARY_FILE = os.path.expanduser('iTunesLibrary.xml')
|
||||||
DEFAULT_OUTPUT_FILE = os.path.dirname(os.path.realpath(__file__)) + '/es-music-data.json'
|
DEFAULT_OUTPUT_FILE = os.path.dirname(os.path.realpath(__file__)) + '/es-music-data.json'
|
||||||
|
|
||||||
# Get options
|
# Get options
|
||||||
@@ -253,8 +250,6 @@ parser.add_option('-o', '--output', dest='output', type='string',
|
|||||||
default=DEFAULT_OUTPUT_FILE)
|
default=DEFAULT_OUTPUT_FILE)
|
||||||
parser.add_option('-c', '--console', dest='console', action='store_true',
|
parser.add_option('-c', '--console', dest='console', action='store_true',
|
||||||
help='Output to console instead of file')
|
help='Output to console instead of file')
|
||||||
parser.add_option('-p', '--jsonp', dest='jsonp', action='store_true',
|
|
||||||
help='Output in JSON-P format')
|
|
||||||
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
|
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
|
||||||
help='Verbose output')
|
help='Verbose output')
|
||||||
|
|
||||||
@@ -262,10 +257,7 @@ if __name__ == '__main__':
|
|||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
itunes_parser = ITunesParser(options.file)
|
itunes_parser = ITunesParser(options.file)
|
||||||
if options.jsonp:
|
output = itunes_parser.to_json()
|
||||||
output = itunes_parser.to_json_p()
|
|
||||||
else:
|
|
||||||
output = itunes_parser.to_json()
|
|
||||||
|
|
||||||
if options.console:
|
if options.console:
|
||||||
print(output)
|
print(output)
|
||||||
|
|||||||
Reference in New Issue
Block a user