diff --git a/btstrm/btstrm.py b/btstrm/btstrm.py index 71660f5..cd3854c 100644 --- a/btstrm/btstrm.py +++ b/btstrm/btstrm.py @@ -40,6 +40,7 @@ def load_config(): "JACKETT_API_KEY": "", "JACKETT_URL": "http://127.0.0.1:9117", "TIMEOUT": "30", + "REMOVE_PLAYED_FROM_LIST": "False", } config = CaseSensitiveConfigParser() @@ -584,8 +585,8 @@ def main(): mountpoint_removed = [m.replace(mountpoint, "") for m in media] file_paths = [last_created_dir + "/files" + m for m in mountpoint_removed] - for file_path in file_paths: - print(file_path) + # for file_path in file_paths: + # print(file_path) read_log(log) @@ -613,8 +614,32 @@ def main(): # For other players, just use original command. player_with_options = list(player) - if media: + + + if len(media) == 1: + print(f"Playing: {os.path.basename(media[0])}") status = subprocess.call(player_with_options + media, stdin=sys.stdin) + elif len(media) > 1: + while media: + selection_list = "\n".join(f"{index}: {os.path.basename(path)}" for index, path in enumerate(media)) + process = subprocess.Popen(['fzf', '--with-nth', '2..'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + selected, _ = process.communicate(input=selection_list.encode('utf-8')) + if process.returncode == 0: + selected_index = int(selected.decode('utf-8').split(':')[0]) + selected_file = media[selected_index] + + print(f"Playing: {os.path.basename(selected_file)}") + status = subprocess.call(player_with_options + [selected_file], stdin=sys.stdin) + + if REMOVE_PLAYED_FROM_LIST: + media.pop(selected_index) + else: + print("Exiting.") + break + + + # if media: + # status = subprocess.call(player_with_options + media, stdin=sys.stdin) else: print("No video media found", file=sys.stderr) status = 3 diff --git a/pyproject.toml b/pyproject.toml index 06fa24f..a322c94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "btstrm" -version = "0.1.6" +version = "0.1.7" description = "A script to stream torrents using BTFS" readme = "README.md" authors = [{ name = "asakura42" }]