Skip to content

Commit 2dda574

Browse files
committed
select episodes with fzf
1 parent d024fcc commit 2dda574

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

btstrm/btstrm.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def load_config():
4040
"JACKETT_API_KEY": "",
4141
"JACKETT_URL": "http://127.0.0.1:9117",
4242
"TIMEOUT": "30",
43+
"REMOVE_PLAYED_FROM_LIST": "False",
4344
}
4445

4546
config = CaseSensitiveConfigParser()
@@ -584,8 +585,8 @@ def main():
584585
mountpoint_removed = [m.replace(mountpoint, "") for m in media]
585586
file_paths = [last_created_dir + "/files" + m for m in mountpoint_removed]
586587

587-
for file_path in file_paths:
588-
print(file_path)
588+
# for file_path in file_paths:
589+
# print(file_path)
589590

590591
read_log(log)
591592

@@ -613,8 +614,32 @@ def main():
613614
# For other players, just use original command.
614615
player_with_options = list(player)
615616

616-
if media:
617+
618+
619+
if len(media) == 1:
620+
print(f"Playing: {os.path.basename(media[0])}")
617621
status = subprocess.call(player_with_options + media, stdin=sys.stdin)
622+
elif len(media) > 1:
623+
while media:
624+
selection_list = "\n".join(f"{index}: {os.path.basename(path)}" for index, path in enumerate(media))
625+
process = subprocess.Popen(['fzf', '--with-nth', '2..'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
626+
selected, _ = process.communicate(input=selection_list.encode('utf-8'))
627+
if process.returncode == 0:
628+
selected_index = int(selected.decode('utf-8').split(':')[0])
629+
selected_file = media[selected_index]
630+
631+
print(f"Playing: {os.path.basename(selected_file)}")
632+
status = subprocess.call(player_with_options + [selected_file], stdin=sys.stdin)
633+
634+
if REMOVE_PLAYED_FROM_LIST:
635+
media.pop(selected_index)
636+
else:
637+
print("Exiting.")
638+
break
639+
640+
641+
# if media:
642+
# status = subprocess.call(player_with_options + media, stdin=sys.stdin)
618643
else:
619644
print("No video media found", file=sys.stderr)
620645
status = 3

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "btstrm"
7-
version = "0.1.6"
7+
version = "0.1.7"
88
description = "A script to stream torrents using BTFS"
99
readme = "README.md"
1010
authors = [{ name = "asakura42" }]

0 commit comments

Comments
 (0)