Last active
December 29, 2024 19:18
-
-
Save rdyv/9d6b8172c9d0b836f05546580ba5e8e0 to your computer and use it in GitHub Desktop.
Download NRK TV Subtitles and optionally translate them into english
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if a show code is provided as an argument | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 <SHOW_CODE>" | |
echo "Example: 'DVFJ65100124' is the show code in https://tv.nrk.no/serie/der-ingen-skulle-tru-at-nokon-kunne-bu/sesong/23/episode/DVFJ65100124" | |
exit 1 | |
fi | |
# User-provided show code | |
SHOW_CODE="$1" | |
# Base URL for fetching the manifest | |
MANIFEST_URL="https://psapi.nrk.no/playback/manifest/program/$SHOW_CODE" | |
# Output file for combined subtitles | |
OUTPUT_FILE="subtitles_$SHOW_CODE.txt" | |
# Fetch the manifest and extract the preferred webVtt URL | |
WEBVTT_URL=$(curl -s "$MANIFEST_URL" | jq -r '.playable.subtitles[] | select(.type == "ttv") | .webVtt') | |
# If no 'ttv' type is found, fallback to any available subtitle | |
if [[ -z "$WEBVTT_URL" ]]; then | |
WEBVTT_URL=$(curl -s "$MANIFEST_URL" | jq -r '.playable.subtitles[0].webVtt') | |
fi | |
# Check if a valid webVtt URL was found | |
if [[ -z "$WEBVTT_URL" ]]; then | |
echo "No subtitles found for the show code: $SHOW_CODE" | |
exit 1 | |
fi | |
echo "Using subtitles from: $WEBVTT_URL" | |
# Download the subtitles and save them to the output file | |
curl -s "$WEBVTT_URL" -o "$OUTPUT_FILE" | |
if [[ $? -eq 0 ]]; then | |
echo "Subtitles saved to: $OUTPUT_FILE" | |
else | |
echo "Failed to download subtitles from: $WEBVTT_URL" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And to convert these subtitles into Anki flashcard ready unique set of words using Anthropic APIs: