Created
March 14, 2026 09:03
-
-
Save jvarn/a57c4c37d2d73d90cb0755a70f96d84a to your computer and use it in GitHub Desktop.
Example of how to use TheTVDB API
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 | |
| # API Key Sign Up Page: https://www.thetvdb.com/api-information | |
| # Official v4 API Documentation: https://thetvdb.github.io/v4-api/ | |
| # 1. Configuration | |
| API_KEY="your-api-key-here" | |
| SERIES_NAME="Star Trek Voyager" | |
| SERIES_YEAR="1995" | |
| SEASON_NUMBER="2" | |
| EPISODE_NUMBER="1" | |
| # 2. Get the Auth Token | |
| # We extract the 'token' field from the login response | |
| THETVDB_TOKEN=$(curl -s -X POST https://api4.thetvdb.com/v4/login \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"apikey\": \"$API_KEY\"}" | jq -r '.data.token') | |
| if [ "$THETVDB_TOKEN" == "null" ] || [ -z "$THETVDB_TOKEN" ]; then | |
| echo "Error: Failed to get Auth Token. Check your API Key." | |
| exit 1 | |
| fi | |
| # 3. Search for the Series ID | |
| # We use --data-urlencode to safely handle the show name | |
| THETVDB_SERIES_ID=$(curl -s -G "https://api4.thetvdb.com/v4/search" \ | |
| -H "Authorization: Bearer $THETVDB_TOKEN" \ | |
| --data-urlencode "query=$SERIES_NAME" \ | |
| --data-urlencode "type=series" \ | |
| --data-urlencode "year=$SERIES_YEAR" | jq -r '.data[0].tvdb_id') | |
| echo "Found Series ID: $THETVDB_SERIES_ID" | |
| # 4. Get the Episode ID | |
| # We query the official aired order for the specific season and episode | |
| THETVDB_EPISODE_ID=$(curl -s -G "https://api4.thetvdb.com/v4/series/$THETVDB_SERIES_ID/episodes/official" \ | |
| -H "Authorization: Bearer $THETVDB_TOKEN" \ | |
| --data-urlencode "season=$SEASON_NUMBER" \ | |
| --data-urlencode "episodeNumber=$EPISODE_NUMBER" | jq -r '.data.episodes[0].id') | |
| echo "Found Episode ID: $THETVDB_EPISODE_ID" | |
| # 5. Get the Final Extended Data | |
| echo "--- Episode Description ---" | |
| curl -s -X GET "https://api4.thetvdb.com/v4/episodes/$THETVDB_EPISODE_ID/extended" \ | |
| -H "Authorization: Bearer $THETVDB_TOKEN" \ | |
| -H "Accept: application/json" | jq -r '.data.overview' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment