Skip to content

Commit

Permalink
added subtitle downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
asakura42 committed Mar 24, 2024
1 parent eb67fe6 commit c57fe65
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Integration with [`impd`](https://github.com/ajatt-tools/impd) for condensing videos for language learning
- Real-time display of download progress and peer information
- Support for multiple languages and configurable settings
- Automatically subtitle searching using great [`osd`](https://github.com/druidamix/Opensubtitles-downloader) program

## Prerequisites

Expand All @@ -25,6 +26,7 @@ Before using `btstrm`, ensure that you have the following dependencies installed
- `Jackett` (**optional**, but **highly recommended** for torrent search integration)
- `impd` (**optional**, for language immersion enthusiasts)
- `chafa` (for displaying movie posters)
- [osd](https://github.com/druidamix/Opensubtitles-downloader) (**optional**, for subtitle downloading)
- Required Python packages: `requests`, `tqdm`, `colorama`, `beautifulsoup4`, `unidecode`

At ArchLinux you can find all these programs in repos or AUR.
Expand Down Expand Up @@ -71,6 +73,7 @@ Options:
- `-p PLAYER`, `--player PLAYER`: Specify the media player to use for streaming (default: auto-detect)
- `-k`, `--keep`: Keep the downloaded files after streaming (default: delete files)
- `-i`, `--impd`: Add the downloaded files to impd playlist (default: disabled)
- `-s [MOVIE_NAME]`, `--subtitles [MOVIE_NAME]`: Search opensubtitles for subs with optional name title
- `-t TITLE`, `--title TITLE`: Search for alternative movie titles and select using fzf

URI:
Expand Down
35 changes: 34 additions & 1 deletion btstrm/btstrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ def main():
parser.add_argument(
"-t", "--title", action="store", help="search for alternative titles"
)
parser.add_argument(
"-s",
"--subtitles",
nargs='?',
const='',
default=False,
help="Download subtitles using osd program",
)
parser.add_argument(
"URI",
nargs="?",
Expand Down Expand Up @@ -581,8 +589,33 @@ def main():

read_log(log)


if args.subtitles is not False:
for file_path in file_paths:
while not os.path.exists(file_path):
time.sleep(1)

# If there is a subtitle name provided.
if args.subtitles != '':
result = subprocess.run(["osd", file_path],
stderr=subprocess.PIPE, text=True)

if "No subtitles found." in result.stderr:
subprocess.run(["osd", "-c", args.subtitles, file_path])

else: # Case when -s/--subtitle was passed with no argument.
subprocess.run(["osd", file_path])

if "mpv" in player[0]:
sub_option = f'--sub-file-paths={":".join([dirpath for dirpath, _, _ in os.walk(last_created_dir + "/files")])}'
player_with_options = list(player) + [sub_option]
else:
# For other players, just use original command.
player_with_options = list(player)


if media:
status = subprocess.call(list(player) + media, stdin=sys.stdin)
status = subprocess.call(player_with_options + media, stdin=sys.stdin)
else:
print("No video media found", file=sys.stderr)
status = 3
Expand Down

0 comments on commit c57fe65

Please sign in to comment.