|
@@ -1,28 +1,27 @@
|
|
|
-
|
|
|
-
|
|
|
import argparse
|
|
|
import os
|
|
|
+import sys
|
|
|
|
|
|
import symuid
|
|
|
import symuid.library.cmus
|
|
|
from symuid._datetime import datetime_utc_now
|
|
|
|
|
|
-PLAYER_NAME = 'cmus'
|
|
|
-LIBRARY_ID_LENGTH_MIN = 8
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+_PLAYER_NAME = 'cmus'
|
|
|
+_LIBRARY_ID_LENGTH_MIN = 8
|
|
|
|
|
|
def symuid_import_cmus(library_id, cache_path):
|
|
|
- assert len(library_id) >= LIBRARY_ID_LENGTH_MIN, library_id
|
|
|
- lib = symuid.library.cmus.Cache(
|
|
|
- path=os.path.expanduser(cache_path),
|
|
|
- )
|
|
|
+ assert len(library_id) >= _LIBRARY_ID_LENGTH_MIN, library_id
|
|
|
+ lib = symuid.library.cmus.Cache(cache_path)
|
|
|
for cmus_track in lib.get_tracks():
|
|
|
if not os.path.exists(cmus_track.path):
|
|
|
sys.stderr.write('{!r}: not found\n'.format(cmus_track.path))
|
|
|
elif cmus_track.play_count > 0:
|
|
|
symuid_track = symuid.Track(path=cmus_track.path.decode())
|
|
|
last_count = symuid_track.get_latest_play_count(
|
|
|
- player=PLAYER_NAME,
|
|
|
+ player=_PLAYER_NAME,
|
|
|
library_id=library_id,
|
|
|
)
|
|
|
assert last_count is None or last_count.count <= cmus_track.play_count, \
|
|
@@ -30,7 +29,7 @@ def symuid_import_cmus(library_id, cache_path):
|
|
|
if last_count is None or last_count.count != cmus_track.play_count:
|
|
|
symuid_track.register_play_count(
|
|
|
symuid.PlayCount(
|
|
|
- player=PLAYER_NAME,
|
|
|
+ player=_PLAYER_NAME,
|
|
|
library_id=library_id,
|
|
|
register_dt=datetime_utc_now(),
|
|
|
count=cmus_track.play_count,
|
|
@@ -46,18 +45,13 @@ def _init_argparser():
|
|
|
argparser.add_argument(
|
|
|
'cache_path',
|
|
|
nargs='?',
|
|
|
- default='~/.config/cmus/cache',
|
|
|
+ default=os.path.expanduser('~/.config/cmus/cache'),
|
|
|
help='(default: %(default)r)',
|
|
|
)
|
|
|
return argparser
|
|
|
|
|
|
|
|
|
-def main(argv):
|
|
|
+def _main():
|
|
|
argparser = _init_argparser()
|
|
|
- args = argparser.parse_args(argv[1:])
|
|
|
+ args = argparser.parse_args()
|
|
|
symuid_import_cmus(**vars(args))
|
|
|
- return 0
|
|
|
-
|
|
|
-if __name__ == "__main__":
|
|
|
- import sys
|
|
|
- sys.exit(main(sys.argv))
|