Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ Options:
Specify the subtitle language (if no language is provided, it defaults to english)
--rofi, --external-menu
Use rofi instead of fzf
-n, --no-subs
Disable subtitles
-O, --opensubtitles
Search and select subtitles from OpenSubtitles.org (requires opensubtitles_api_key in config)
-p, --provider
Specify the provider to watch from (if no provider is provided, it defaults to Vidcloud) (currently supported: Vidcloud, UpCloud)
-q, --quality
Expand Down Expand Up @@ -541,6 +545,20 @@ Example use case:
lobster -n
```

### `-O` / `--opensubtitles` argument
Flag: Use -O or --opensubtitles when launching lobster, or set use_opensubtitles="true" in your config file.
After selecting a movie/episode and getting the video link, lobster searches OpenSubtitles.com for subtitles
using the movie title. A fzf/rofi selection appears showing each result as:
[en] Movie.Title.2021.1080p.BluRay (5000 downloads)
Download: The selected subtitle is downloaded to the temp dir and passed to the player via --sub-file.

```
Setup required — you need a free API key from https://www.opensubtitles.com/consumers. Add it to your config
(~/.config/lobster/lobster_config.sh):
opensubtitles_api_key="your_key_here" use_opensubtitles="true" # optional, or use -O flag
```
The free tier allows 5 subtitle downloads/day. Searching has no limit.

### `-r` / `--recent` `<tv|movie>` argument

By passing this argument, you can see watch most recently released movies and TV
Expand Down
69 changes: 66 additions & 3 deletions lobster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ usage() {
Use rofi instead of fzf
-n, --no-subs
Disable subtitles
-O, --opensubtitles
Search and select subtitles from OpenSubtitles.org (requires opensubtitles_api_key in config)
-p, --provider
Specify the provider to watch from (if no provider is provided, it defaults to Vidcloud) (currently supported: Vidcloud, UpCloud)
-q, --quality
Expand Down Expand Up @@ -169,8 +171,11 @@ configuration() {
[ -z "$player" ] && player="mpv"
[ -z "$download_dir" ] && download_dir="$PWD"
[ -z "$provider" ] && provider="Vidcloud"
[ -z "$subs_language" ] && subs_language="english"
[ -z "$language" ] && language="pt-br"
[ -z "$subs_language" ] && subs_language="portuguese"
subs_language="$(printf "%s" "$subs_language" | cut -c2-)"
[ -z "$opensubtitles_api_key" ] && opensubtitles_api_key=""
[ -z "$use_opensubtitles" ] && use_opensubtitles="false"
[ -z "$histfile" ] && histfile="$data_dir/lobster_history.txt" && mkdir -p "$(dirname "$histfile")"
[ -z "$history" ] && history=false
[ -z "$use_external_menu" ] && use_external_menu="false"
Expand Down Expand Up @@ -338,6 +343,7 @@ EOF
image_link=$(printf "%s" "$choice" | cut -f1)
media_id=$(printf "%s" "$choice" | cut -f2)
media_type=$(printf "%s" "$choice" | cut -f3)
year=$(printf "%s" "$choice" | cut -f4 | $sed -nE "s@.*\[(.*)\]@\1@p")
title=$(printf "%s" "$choice" | cut -f4 | $sed -nE "s@(.*) \[.*\]@\1@p")
api_media_id=$(printf "%s" "$choice" | cut -f5)
fi
Expand Down Expand Up @@ -607,6 +613,59 @@ EOF
fi
}

choose_opensubtitles() {
if [ -z "$opensubtitles_api_key" ]; then
send_notification "Set opensubtitles_api_key in config to use OpenSubtitles"
return 1
fi
send_notification "Searching OpenSubtitles..."
encoded_query=$(printf "%s" "$title" | $sed 's/ /%20/g; s/:/%3A/g; s/\//%2F/g')
send_notification "Searching OpenSubtitles for \"$title\" with language \"$language\"..."
json=$(curl -s -L --request GET --url "https://api.opensubtitles.com/api/v1/subtitles?type=${media_type}&query=${encoded_query}&languages=${language}&year=${year}" -A "lobster" -H "Api-Key: ${opensubtitles_api_key}" -H "Accept: application/json")

entries=$(printf "%s" "$json" | tr -d '\n' |
$sed 's/\[{"id"/\n{"id"/g; s/},{"id"/\n{"id"/g' |
while IFS= read -r record; do
file_id=$(printf "%s" "$record" | $sed -nE 's/.*"file_id":([0-9]+).*/\1/p' | head -1)
language=$(printf "%s" "$record" | $sed -nE 's/.*"language":"([^"]+)".*/\1/p' | head -1)
release=$(printf "%s" "$record" | $sed -nE 's/.*"release":"([^"]+)".*/\1/p' | head -1)
downloads=$(printf "%s" "$record" | $sed -nE 's/.*"download_count":([0-9]+).*/\1/p' | head -1)
[ -z "$downloads" ] && downloads="?"
[ -n "$file_id" ] && [ -n "$language" ] &&
printf "%s\t[%s] %s (%s downloads)\n" "$file_id" "$language" "$release" "$downloads"
done)

[ -z "$entries" ] && send_notification "No subtitles found on OpenSubtitles" && return 1

chosen=$(printf "%s" "$entries" | launcher "Select subtitle from OpenSubtitles: " "2")
[ $? -ne 0 ] && return 1
[ -z "$chosen" ] && return 1

file_id=$(printf "%s" "$chosen" | cut -f1)
[ -z "$file_id" ] && return 1

dl_response=$(curl -s -X POST "https://api.opensubtitles.com/api/v1/download" \
-H "Api-Key: ${opensubtitles_api_key}" \
-H "User-Agent: lobster v${LOBSTER_VERSION}" \
-H "Content-Type: application/json" \
-d "{\"file_id\": ${file_id}}")

link=$(printf "%s" "$dl_response" | $sed -nE 's/.*"link":"([^"]+)".*/\1/p')
[ -z "$link" ] && send_notification "Failed to get subtitle link from OpenSubtitles" && return 1

sub_file="$tmp_dir/opensubtitles_${file_id}.srt"
curl -s -L "$link" -o "$sub_file" -H "User-Agent: lobster v${LOBSTER_VERSION}"

if [ -f "$sub_file" ]; then
subs_arg="--sub-file"
subs_links="$sub_file"
send_notification "Subtitle loaded from OpenSubtitles"
else
send_notification "Failed to download subtitle from OpenSubtitles"
return 1
fi
}

check_history() {
if [ ! -f "$histfile" ]; then
[ "$image_preview" = "true" ] && send_notification "Now Playing" "5000" "$images_cache_dir/ $title ($media_type) $media_id.jpg" "$title"
Expand Down Expand Up @@ -899,7 +958,7 @@ EOF
ffmpeg_meta=""
ffmpeg_maps=""

if [ "$no_subs" = "true" ]; then
if [ "$no_subs" = "true" ] || [ "$use_opensubtitles" = "false" ]; then
# no subtitles
sub_ops=""
else
Expand Down Expand Up @@ -940,6 +999,7 @@ EOF
[ -z "$embed_link" ] && exit 1
extract_from_embed
[ -z "$video_link" ] && exit 1
[ "$use_opensubtitles" = "true" ] && [ "$no_subs" != "true" ] && choose_opensubtitles
if [ "$download" = "true" ]; then
if [ "$media_type" = "movie" ]; then
if [ "$image_preview" = "true" ]; then
Expand Down Expand Up @@ -1144,6 +1204,9 @@ EOF
-n | --no-subs)
no_subs="true" && shift
;;
-O | --opensubtitles)
use_opensubtitles="true" && shift
;;
*)
if [ "${1#-}" != "$1" ]; then
query="$query $1"
Expand All @@ -1170,4 +1233,4 @@ EOF
main

} 2>&1 | tee "$lobster_logfile" >&3 2>&4
exec 1>&3 2>&4
exec 1>&3 2>&4