|
@@ -2,13 +2,12 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
import datetime as dt
|
|
import datetime as dt
|
|
-import dateutil.parser
|
|
|
|
import mutagen
|
|
import mutagen
|
|
import mutagen.id3
|
|
import mutagen.id3
|
|
import mutagen.mp4
|
|
import mutagen.mp4
|
|
import os
|
|
import os
|
|
|
|
+import re
|
|
import symuid.library.itunes
|
|
import symuid.library.itunes
|
|
-import urllib.parse
|
|
|
|
|
|
|
|
|
|
|
|
def generate_play_count_tag_label(player, library_id, reg_dt):
|
|
def generate_play_count_tag_label(player, library_id, reg_dt):
|
|
@@ -51,24 +50,25 @@ def set_play_count_tag(track_path, player, library_id, reg_dt, play_count):
|
|
raise Exception(track_path)
|
|
raise Exception(track_path)
|
|
|
|
|
|
|
|
|
|
-def symuid_import_itunes(xml_library_path, root_url, root_path):
|
|
+def symuid_import_itunes(xml_library_path, path_regex_sub):
|
|
- root_path = os.path.expanduser(root_path)
|
|
|
|
lib = symuid.library.itunes.XmlLibrary(xml_library_path)
|
|
lib = symuid.library.itunes.XmlLibrary(xml_library_path)
|
|
for track in lib.tracks:
|
|
for track in lib.tracks:
|
|
# TODO create tag if last_play_dt is None
|
|
# TODO create tag if last_play_dt is None
|
|
- if track.last_play_dt and track.location_url and track.location_url.startswith(root_url):
|
|
+ if track.last_play_dt and track.local:
|
|
- track_path = os.path.join(
|
|
+ track_path = track.local_path
|
|
- root_path,
|
|
+ for pattern, repl in path_regex_sub:
|
|
- urllib.parse.unquote(track.location_url[len(root_url):]),
|
|
+ track_path = re.sub(pattern, repl, track_path)
|
|
- )
|
|
+ if not os.path.exists(track_path):
|
|
- # TODO dt=dt.datetime.now()
|
|
+ raise ValueError(track_path)
|
|
- set_play_count_tag(
|
|
+ else:
|
|
- track_path=track_path,
|
|
+ # TODO dt=dt.datetime.now()
|
|
- player='itunes',
|
|
+ set_play_count_tag(
|
|
- library_id=lib.id,
|
|
+ track_path=track_path,
|
|
- reg_dt=track.last_play_dt,
|
|
+ player='itunes',
|
|
- play_count=track.play_count,
|
|
+ library_id=lib.id,
|
|
- )
|
|
+ reg_dt=track.last_play_dt,
|
|
|
|
+ play_count=track.play_count,
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
def _init_argparser():
|
|
def _init_argparser():
|
|
@@ -76,13 +76,11 @@ def _init_argparser():
|
|
argparser = argparse.ArgumentParser(description=None)
|
|
argparser = argparse.ArgumentParser(description=None)
|
|
argparser.add_argument('xml_library_path')
|
|
argparser.add_argument('xml_library_path')
|
|
argparser.add_argument(
|
|
argparser.add_argument(
|
|
- '--root-url',
|
|
+ '--path-regex-sub',
|
|
- default='file://localhost/',
|
|
+ nargs=2,
|
|
- help='(default: %(default)r)',
|
|
+ action='append',
|
|
- )
|
|
+ metavar=('regex', 'replacement'),
|
|
- argparser.add_argument(
|
|
+ default=[],
|
|
- '--root-path',
|
|
|
|
- default='',
|
|
|
|
help='(default: %(default)r)',
|
|
help='(default: %(default)r)',
|
|
)
|
|
)
|
|
return argparser
|
|
return argparser
|