Browse Source

symuid-import-cmus: list paths of tracks in cmus cache

Fabian Peter Hammerle 6 years ago
parent
commit
464683bc3c
1 changed files with 43 additions and 0 deletions
  1. 43 0
      symuid-import-cmus

+ 43 - 0
symuid-import-cmus

@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+import datetime as dt
+import os
+import re
+import symuid
+# import symuid.library.cmus
+import sys
+
+CACHE_LINE_SEPARATOR = b'\xff'*56
+CACHE_COLUMN_SEPARATOR = b'\x00'
+
+def symuid_import_cmus(cache_path):
+    with open(os.path.expanduser(cache_path), 'rb') as f:
+        cache_data = [l.split(CACHE_COLUMN_SEPARATOR) for l in f.read().split(CACHE_LINE_SEPARATOR)]
+    for track_data in cache_data[1:]:
+        track_path = track_data[0]
+        if not os.path.exists(track_path):
+            sys.stderr.write('{!r}: not found\n'.format(track_path))
+        else:
+            print(track_path)
+
+def _init_argparser():
+    import argparse
+    argparser = argparse.ArgumentParser(description=None)
+    argparser.add_argument(
+        'cache_path',
+        nargs='?',
+        default='~/.config/cmus/cache',
+        help='(default: %(default)r)',
+    )
+    return argparser
+
+
+def main(argv):
+    argparser = _init_argparser()
+    args = argparser.parse_args(argv[1:])
+    symuid_import_cmus(**vars(args))
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))