|
@@ -6,6 +6,7 @@ import mutagen.id3
|
|
|
import mutagen.mp4
|
|
|
import os
|
|
|
import subprocess
|
|
|
+import urllib.parse
|
|
|
import xml.etree.ElementTree
|
|
|
|
|
|
# http://id3.org/id3v2.4.0-frames#4.1.
|
|
@@ -79,7 +80,7 @@ def get_itunes_dict_value(dict_node, key):
|
|
|
return value_node
|
|
|
|
|
|
|
|
|
-def import_itunes_play_count(itunes_library_path):
|
|
|
+def import_itunes_play_count(itunes_library_path, itunes_library_root_url):
|
|
|
lib = xml.etree.ElementTree.parse(itunes_library_path)
|
|
|
# WORKAROUND find('.//key[.="Library Persistent ID"]')
|
|
|
# -> SyntaxError: invalid predicate
|
|
@@ -91,13 +92,16 @@ def import_itunes_play_count(itunes_library_path):
|
|
|
track_url = get_itunes_dict_value(track_node, 'Location')
|
|
|
except KeyError:
|
|
|
track_url = None
|
|
|
- if track_url and track_url.startswith('file://'):
|
|
|
- print(track_url)
|
|
|
+ if track_url and track_url.startswith(itunes_library_root_url):
|
|
|
+ track_path = urllib.parse.unquote(
|
|
|
+ track_url[len(itunes_library_root_url):],
|
|
|
+ )
|
|
|
+ print(track_path)
|
|
|
|
|
|
|
|
|
-def symuid(path, itunes_library_path=None):
|
|
|
+def symuid(path, itunes_library_path=None, itunes_library_root_url=None):
|
|
|
if itunes_library_path:
|
|
|
- import_itunes_play_count(itunes_library_path)
|
|
|
+ import_itunes_play_count(itunes_library_path, itunes_library_root_url)
|
|
|
if os.path.isdir(path):
|
|
|
for dirpath, dirnames, filenames in os.walk(path):
|
|
|
for filename in filenames:
|
|
@@ -122,6 +126,11 @@ def _init_argparser():
|
|
|
argparser = argparse.ArgumentParser(description=None)
|
|
|
argparser.add_argument('path')
|
|
|
argparser.add_argument('--itunes-library-path')
|
|
|
+ argparser.add_argument(
|
|
|
+ '--itunes-library-root-url',
|
|
|
+ default='file://localhost/',
|
|
|
+ help='(default: %(default)s)',
|
|
|
+ )
|
|
|
return argparser
|
|
|
|
|
|
|