From d6238bd2ad38ece7ecfd06e7990e919c40c61a07 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Fri, 3 Oct 2025 15:34:56 -0400 Subject: [PATCH] fix typos, handle paths with : properly, remove debug print --- playback2scrob.py | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/playback2scrob.py b/playback2scrob.py index 9b9b3d0306c4ae21c3b317544d52fd70b222b0cb..1bab7ff3aed8cde6ad2bcc6121e7a8479cde3b5f 100755 --- a/playback2scrob.py +++ b/playback2scrob.py @@ -14,17 +14,7 @@ config is INI-format. it supports the following parameters: API_KEY = '67c56bce3d1ae7d5574b7d51028e8db0' SECRET = '8c19d08c8ad2a4c7b490dea2b53876a0' # i guess i have to make this public? WTF. -from configparser import ConfigParser from sys import stderr, argv, exit -from dataclasses import dataclass -from typing import Optional, Iterator, List, Set -import re -import json -from hashlib import md5 -from urllib.request import urlopen -from urllib.parse import urlencode -from urllib.error import HTTPError -from time import sleep, time argv0 = 'playback2scrob' @@ -40,6 +30,29 @@ def usage(): exit(-1) +### ARGS ### + +if len(argv) < 1: + usage() +argv0 = argv[0] +argv = argv[1:] +if len(argv) != 2: + usage() + +# this is deferred so that the user doesn't need to wait +# for imports when they make a mistake +from configparser import ConfigParser +from dataclasses import dataclass +from typing import Optional, Iterator, List, Set +import re +import json +from hashlib import md5 +from urllib.request import urlopen +from urllib.parse import urlencode +from urllib.error import HTTPError +from time import sleep, time + + ### CONFIG ### @dataclass(init=False) @@ -80,7 +93,7 @@ def split_logfile(config: Config, lines: Iterator[str]) -> Iterator[RawLogEntry] if line[0] in '#': continue - when,elapsed,duration,what = line.split(':') + when,elapsed,duration,what = line.split(':', 3) yield RawLogEntry(int(when)-config.offset, what, int(elapsed), int(duration)) def filter_logfile(config: Config, entries: Iterator[RawLogEntry]) -> Iterator[RawLogEntry]: @@ -176,13 +189,6 @@ def put_scrobbles(sk: str, scrobbles: List[Scrobble]): ### BOOT ### -if len(argv) < 1: - usage() -argv0 = argv[0] -argv = argv[1:] -if len(argv) != 2: - usage() - config = ConfigParser(strict=False, interpolation=None) try: config.read_file(open(argv[0])) @@ -195,7 +201,6 @@ try: except Exception as e: die(f"can't read {argv[1]}: {e}") -print(config) logfile = split_logfile(config, logfile) @@ -223,7 +228,7 @@ while len(scrobbles) > 0: scrobbles = scrobbles[50:] put_scrobbles(sk, batch) count += len(batch) - print(f"sent {count}/{fullen} scrobbles...", end="\r") + print(f"sent {count}/{fulllen} scrobbles...", end="\r") sleep(5) print()