@@ 1,4 1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
"""
This script synchronizes a music collection recursivly one way from a losless format source directory to a lossy file format target directory.
@@ 44,7 44,7 @@ parser.add_option("-p", "--numberofproce
(options, args) = parser.parse_args()
-if len(args) <> 2:
+if len(args) != 2:
parser.error("incorrect number of arguments")
try:
level = int(getattr(logging, options.loglevel))
@@ 54,10 54,12 @@ except (AttributeError, ValueError, Type
for path in args:
if not os.path.exists(path):
parser.error("path does not exist: %s" % path)
+ if not os.path.isdir(path):
+ parser.error("path is not a directory: %s" % path)
if args[0] == args[1]:
parser.error("source and target path must not be the same")
-
+
if options.win:
illegal_characters = '?[],\=+<>:;"*|^'
else:
@@ 105,7 107,7 @@ def create_ID3V2_tag_values_from_flac(so
else:
try:
reference_tag = [reference_key for (reference_key, reference_values)
- in flac_tags_synonyms.items() if tag.lower() in reference_values][0]
+ in list(flac_tags_synonyms.items()) if tag.lower() in reference_values][0]
if (reference_tag in ["composer", "artist"] and id3_tags_dict[reference_tag] != ""):
#tag value is a list, mp3 id3 v2 separator is a /
id3_tags_dict[reference_tag] = id3_tags_dict[reference_tag] + "/" + value
@@ 113,7 115,7 @@ def create_ID3V2_tag_values_from_flac(so
id3_tags_dict[reference_tag] = value
except IndexError:
logging.info("unsupported id3 tag '%s' ignored" % id3)
- for key in id3_tags_dict.keys():
+ for key in list(id3_tags_dict.keys()):
id3_tags_dict[key] = shellquote(id3_tags_dict[key])
return id3_tags_dict
@@ 177,8 179,8 @@ if target_format == "ogg":
".wav":[".ogg", x_to_ogg]})
elif target_format == 'mp3':
convert_map.update({".flac":[".mp3", flac_to_mp3],
- ".wav":[".mp3", wav_to_mp3]})
-
+ ".wav":[".mp3", wav_to_mp3]})
+
def shellquote(s):
if sys.platform.startswith("win"):
@@ 189,9 191,9 @@ def shellquote(s):
def convert(source_fname):
target_fname = source_fname.replace(source_dir, target_dir)
cmd = None
-
+
if os.path.isdir(source_fname):
- cmd = convert_map["dir"][1]
+ cmd = convert_map["dir"][1]
elif os.path.isfile(source_fname) or os.path.islink(source_fname):
try:
ext = os.path.splitext(source_fname)[1].lower()
@@ 200,21 202,21 @@ def convert(source_fname):
logging.warning("File extension '%s' not supported." % (ext))
else:
target_fname = os.path.splitext(target_fname)[0] + "%s" % conv[0]
- cmd = conv[1]
-
- else:
+ cmd = conv[1]
+
+ else:
logging.error("File type not supported.")
for c in illegal_characters:
target_fname = target_fname.replace(c, "-")
-
+
if not os.path.exists(target_fname):
if cmd:
logging.debug("cmd: %s, source: %s, target: %s" % (cmd, source_fname, target_fname))
cmd(source_fname, target_fname)
else:
logging.debug("File '%s' ignored." % source_fname)
-
+
else:
logging.debug("Target '%s' already exists." % target_fname)
@@ 281,5 283,5 @@ if __name__ == '__main__':
log_elapsed_time(start, end)
if not options.nodonation:
- print "\nIf you find the script useful and would like to donate: \n" \
- "UniCredit Bank Austria AG, Gregor Horvath, IBAN: AT47 1100 0014 1436 2200, BIC: BKAUATWW"
+ print("\nIf you find the script useful and would like to donate: \n" \
+ "UniCredit Bank Austria AG, Gregor Horvath, IBAN: AT47 1100 0014 1436 2200, BIC: BKAUATWW")