Skip to content

Commit

Permalink
select episodes with fzf
Browse files Browse the repository at this point in the history
  • Loading branch information
asakura42 committed Mar 28, 2024
1 parent d024fcc commit 2dda574
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions btstrm/btstrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
Expand Down

0 comments on commit 2dda574

Please sign in to comment.