|
|
|
@ -399,11 +399,11 @@ if __name__ == '__main__': |
|
|
|
|
global config |
|
|
|
|
global originPath, targetPath, targetFormat, workPath |
|
|
|
|
import configparser |
|
|
|
|
#opt, files = parse_args() |
|
|
|
|
|
|
|
|
|
opt = musicman.utils.parse_args() |
|
|
|
|
config = musicman.utils.load_config() |
|
|
|
|
|
|
|
|
|
print("opt:", opt) |
|
|
|
|
#print("opt:", opt) |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
originDir = config['origin']['path'] if opt.originDir is None else opt.originDir |
|
|
|
@ -464,169 +464,3 @@ if __name__ == '__main__': |
|
|
|
|
|
|
|
|
|
clearLine() |
|
|
|
|
print("Processing Complete!") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#for file in getLibrary(config['origin']['path']): |
|
|
|
|
# #print("File:", file) |
|
|
|
|
# if (os.path.isdir(os.path.dirname(file)) and os.path.isfile(file)): |
|
|
|
|
# clearLine() |
|
|
|
|
# print("Processing:", os.path.dirname(os.path.dirname(file)), next(spinner), end="\r") |
|
|
|
|
# #time.sleep(0.01) |
|
|
|
|
# |
|
|
|
|
# #print("Path:", os.path.dirname(file)) |
|
|
|
|
# #print("File:", os.path.basename(file)) |
|
|
|
|
#clearLine() |
|
|
|
|
#print("Processing Complete!") |
|
|
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|
#config = configparser.ConfigParser() |
|
|
|
|
#config.read('library.ini') |
|
|
|
|
|
|
|
|
|
#print(config.sections()) |
|
|
|
|
#print(config["lossless"]["Path"]) |
|
|
|
|
|
|
|
|
|
#try: |
|
|
|
|
# #print("Test1:", config.get('lossless', 'test')) |
|
|
|
|
# config.get('lossless', 'path') |
|
|
|
|
# config.get('lossless', 'format') |
|
|
|
|
# config.get('converted', 'path') |
|
|
|
|
# config.get('converted', 'format') |
|
|
|
|
#except configparser.NoOptionError as err: |
|
|
|
|
# print("ERROR: Configuration of required settings are missing:", err) |
|
|
|
|
# sys.exit(1) |
|
|
|
|
|
|
|
|
|
LosslessLibraryRoot = '/srv/public/Music-Lossless' |
|
|
|
|
#LosslessLibraryRoot = '/srv/public/Music-iTunes' |
|
|
|
|
iTunesLibraryRoot = '/srv/public/Music-iTunes' |
|
|
|
|
|
|
|
|
|
#artistWalker = os.walk(LosslessLibraryRoot) |
|
|
|
|
#dest_dir, artists, files = artistWalker.next() |
|
|
|
|
|
|
|
|
|
#print "dest_dir: %s" % dest_dir |
|
|
|
|
#print "artists: %s" % artists |
|
|
|
|
#print "files: %s" % files |
|
|
|
|
|
|
|
|
|
#for artist in artists: |
|
|
|
|
# print "Artist: %s" % artist |
|
|
|
|
|
|
|
|
|
# albumWalker = os.walk(os.path.join(dest_dir, artist)) |
|
|
|
|
# artist_dir, albums, artist_files = albumWalker.next() |
|
|
|
|
|
|
|
|
|
# print "Albums: %s" % albums |
|
|
|
|
# print "Album Dir: %s" % artist_dir |
|
|
|
|
|
|
|
|
|
# for album in albums: |
|
|
|
|
# songWalker = os.walk(os.path.join(artist_dir, album) |
|
|
|
|
# album_dir, dummy, songs = songWalker.next() |
|
|
|
|
|
|
|
|
|
for libraryDir, artists, dummy in os.walk(config['origin']['path']): |
|
|
|
|
for artist in sorted(artists): |
|
|
|
|
for artistDir, albums, dummy in os.walk(os.path.join(libraryDir, artist)): |
|
|
|
|
for album in sorted(albums): |
|
|
|
|
for albumDir, dummy, songs in os.walk(os.path.join(artistDir, album)): |
|
|
|
|
#print("AlbumDir:", albumDir) |
|
|
|
|
#print(" Artist:", artist) |
|
|
|
|
#print(" Album:", album) |
|
|
|
|
for song in songs: |
|
|
|
|
if song.endswith('.flac'): |
|
|
|
|
#print " Song: %s" % song |
|
|
|
|
metadata = MetaTag(os.path.join(albumDir, song)) |
|
|
|
|
#if os.path.isfile(os.path.join() |
|
|
|
|
#print "MetaData: %s" % metadata.tags |
|
|
|
|
#os.path.join(iTunesLibraryRoot, [metadata.tags["artist"], metadata.tags["album"]]) |
|
|
|
|
#print("\033[KArtist:", metadata.tags["artist"], end="\r") |
|
|
|
|
|
|
|
|
|
clearLine() |
|
|
|
|
print("Scanning", artistDir, next(spinner), end="\r") |
|
|
|
|
|
|
|
|
|
#if int(metadata.tags["totaldiscs"]) > 1: |
|
|
|
|
if metadata.tags.get("artist") is None: |
|
|
|
|
continue |
|
|
|
|
if metadata.tags.get("albumartist") is None: |
|
|
|
|
continue |
|
|
|
|
if metadata.tags.get('album') is None: |
|
|
|
|
continue |
|
|
|
|
if metadata.tags.get("musicbrainz_albumid") is None or len(metadata.tags.get("musicbrainz_albumid")) < 5: |
|
|
|
|
clearLine() |
|
|
|
|
print("Skipping:", os.path.join(albumDir, song)) |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
#if 'Centennial' in song: |
|
|
|
|
# print |
|
|
|
|
# print |
|
|
|
|
# print("DEBUG") |
|
|
|
|
# print("Path:", artistDir) |
|
|
|
|
# print("Song:", song) |
|
|
|
|
# print("musicbrainz_albumid:", metadata.tags.get("musicbrainz_albumid")) |
|
|
|
|
# print(type(metadata.tags.get("musicbrainz_albumid"))) |
|
|
|
|
# sys.exit(0) |
|
|
|
|
|
|
|
|
|
artistName = sanitize(metadata.tags["albumartist"]) |
|
|
|
|
albumName = sanitize(metadata.tags["album"]) |
|
|
|
|
titleName = sanitize(metadata.tags["title"]) |
|
|
|
|
outPath = '' |
|
|
|
|
outFile = '' |
|
|
|
|
|
|
|
|
|
if int(metadata.tags.get("totaldiscs", 0)) > 1: |
|
|
|
|
outPath = os.path.join(config['converted']['path'], |
|
|
|
|
artistName, |
|
|
|
|
albumName) |
|
|
|
|
outFile = '{0:d}-{1:02d}-{2}.{3}'.format(int(metadata.tags["discnumber"]), |
|
|
|
|
int(metadata.tags["tracknumber"]), |
|
|
|
|
titleName, |
|
|
|
|
'm4a') |
|
|
|
|
#print("iTunes:", os.path.join(iTunesLibraryRoot, |
|
|
|
|
# metadata.tags["artist"], |
|
|
|
|
# metadata.tags["album"], |
|
|
|
|
# '{0:d}-{1:02d}-{2}.{3}'.format(int(metadata.tags["discnumber"]), |
|
|
|
|
# int(metadata.tags["tracknumber"]), |
|
|
|
|
# metadata.tags["title"], |
|
|
|
|
# 'm4a'))) |
|
|
|
|
# #int(metadata.tags["discnumber"]) + '-' + '{0:02d}'.format(int(metadata.tags["tracknumber"])) + '-' + metadata.tags["title"] + ".m4a") |
|
|
|
|
else: |
|
|
|
|
if metadata.tags.get("tracknumber") is not None: |
|
|
|
|
outPath = os.path.join(config['converted']['path'], |
|
|
|
|
artistName, |
|
|
|
|
albumName) |
|
|
|
|
outFile = '{0:02d}-{1}.{2}'.format(int(metadata.tags["tracknumber"]), titleName, 'm4a') |
|
|
|
|
#print("iTunes:", os.path.join(iTunesLibraryRoot, |
|
|
|
|
# metadata.tags["artist"], |
|
|
|
|
# metadata.tags["album"], |
|
|
|
|
# '{0:02d}'.format(int(metadata.tags["tracknumber"])) + '-' + metadata.tags["title"] + ".m4a")) |
|
|
|
|
else: |
|
|
|
|
outPath = os.path.join(config['converted']['path'], |
|
|
|
|
artistName, |
|
|
|
|
albumName) |
|
|
|
|
outFile = '{0}.{1}'.format(titleName, 'm4a') |
|
|
|
|
#print("iTunes:", os.path.join(iTunesLibraryRoot, |
|
|
|
|
# metadata.tags["artist"], |
|
|
|
|
# metadata.tags["album"], |
|
|
|
|
# metadata.tags["title"] + ".m4a")) |
|
|
|
|
#print "iTunes: %s" % os.path.join(iTunesLibraryRoot, metadata.tags["artist"], metadata.tags["album"]) |
|
|
|
|
if not os.path.isfile(os.path.join(outPath, outFile)): |
|
|
|
|
print("NEW:", os.path.join(outPath, outFile)) |
|
|
|
|
if song.endswith('.m4a'): |
|
|
|
|
#print " Song: %s" % song |
|
|
|
|
metadata = MetaTag(os.path.join(albumDir, song)) |
|
|
|
|
#print "MetaData: %s" % metadata.tags |
|
|
|
|
clearLine() |
|
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#LosslessLibraryRoot = '/srv/public/Music-Lossless' |
|
|
|
|
# |
|
|
|
|
#for subdir, dirs, files in os.walk(LosslessLibraryRoot): |
|
|
|
|
# print subdir |
|
|
|
|
# |
|
|
|
|
# for file in files: |
|
|
|
|
# if file.endswith('.flac'): |
|
|
|
|
# audio = mutagen.File(os.path.join(subdir, file)) |
|
|
|
|
# print file |
|
|
|
|
# #print audio.tags.pprint() |
|
|
|
|
# print "Artist: %s" % audio['ARTIST'][0] |
|
|
|
|
# print "Album: %s" % audio['ALBUM'][0] |
|
|
|
|
# print "Title: %s" % audio['TITLE'][0] |
|
|
|
|
# |
|
|
|
|
# #for file in files: |
|
|
|
|
# # print os.path.join(subdir, file) |
|
|
|
|
|
|
|
|
|