Configure an HTTP Proxy for TMDB in Synology Video Station
Synology Video Station uses TMDB to retrieve movie and TV metadata. In some network environments, the built-in TMDB plugin cannot access api.themoviedb.org directly.
The following script adds an HTTP proxy to the TMDB plugin. It also:
- Configures the TMDB API key
- Enables the TMDB plugin
- Clears the old TMDB cache
- Restarts Video Station
Requirements
You need:
- SSH access to the Synology NAS
- Root privileges
- A working HTTP or mixed proxy
- A TMDB API key
- Video Station installed
Example proxy address:
http://192.168.1.10:7890
Create the script
Create a file named:
setup_videostation_tmdb.sh
Paste the following content into it:
#!/bin/sh
set -eu
BASE="/var/packages/VideoStation"
PLUGIN_BASE="$BASE/target/plugins"
TMDB="$PLUGIN_BASE/syno_themoviedb"
SEARCHINC="$TMDB/searchinc.py"
CONSTANT="$TMDB/constant.py"
CONF1="$BASE/etc/plugin.conf"
CONF2="$BASE/target/etc/plugin.conf"
CACHE="$PLUGIN_BASE/plugin_data/com.synology.TheMovieDb"
PROXY="${1:-}"
APIKEY="${2:-}"
[ "$(id -u)" -eq 0 ] || {
echo "Run as root."
exit 1
}
[ -n "$PROXY" ] && [ -n "$APIKEY" ] || {
echo "Usage: $0 http://proxy-ip:port api_key"
exit 1
}
for file in "$SEARCHINC" "$CONSTANT" "$CONF1" "$CONF2"; do
[ -f "$file" ] || {
echo "File not found: $file"
exit 1
}
done
STAMP="$(date +%Y%m%d%H%M%S)"
for file in "$SEARCHINC" "$CONSTANT" "$CONF1" "$CONF2"; do
cp "$file" "$file.bak.$STAMP"
done
python3 - \
"$SEARCHINC" \
"$CONSTANT" \
"$CONF1" \
"$CONF2" \
"$PROXY" \
"$APIKEY" <<'PY'
import json
import re
import sys
from pathlib import Path
searchinc = Path(sys.argv[1])
constant = Path(sys.argv[2])
config_files = [Path(sys.argv[3]), Path(sys.argv[4])]
proxy = sys.argv[5]
apikey = sys.argv[6]
text = searchinc.read_text()
if "# TMDB_PROXY_BEGIN" in text:
text, count = re.subn(
r"(?m)^ proxy_url = .*$",
f" proxy_url = {proxy!r}",
text,
count=1,
)
if count != 1:
raise SystemExit("Proxy update failed.")
else:
old = (
" handler = urllib.request.HTTPCookieProcessor(cookie)\n"
" opener = urllib.request.build_opener(handler)\n"
)
new = (
" # TMDB_PROXY_BEGIN\n"
f" proxy_url = {proxy!r}\n"
" proxy_handler = urllib.request.ProxyHandler({\n"
" 'http': proxy_url,\n"
" 'https': proxy_url\n"
" })\n"
" cookie_handler = urllib.request.HTTPCookieProcessor(cookie)\n"
" opener = urllib.request.build_opener(\n"
" proxy_handler,\n"
" cookie_handler\n"
" )\n"
" # TMDB_PROXY_END\n"
)
if old not in text:
raise SystemExit("Proxy target code not found.")
text = text.replace(old, new, 1)
searchinc.write_text(text)
text = constant.read_text()
text, count = re.subn(
r"(?m)^DEFAULT_APIKEY\s*=.*$",
f"DEFAULT_APIKEY = {apikey!r}",
text,
count=1,
)
if count != 1:
raise SystemExit("DEFAULT_APIKEY not found.")
constant.write_text(text)
for path in config_files:
data = json.loads(path.read_text())
changed = False
for section in data.values():
if not isinstance(section, dict):
continue
for item in section.get("metadata", []):
if item.get("id") == "com.synology.TheMovieDb":
item["enable"] = True
changed = True
if not changed:
raise SystemExit(f"TMDB entry not found: {path}")
path.write_text(
json.dumps(
data,
ensure_ascii=False,
separators=(",", ":"),
)
)
PY
python3 -m py_compile "$SEARCHINC" "$CONSTANT"
synopkg stop VideoStation
rm -rf "$CACHE"
mkdir -p "$CACHE"
chmod -R 777 "$PLUGIN_BASE/plugin_data"
rm -rf "$TMDB/__pycache__"
synopkg start VideoStation
echo "Done."
echo "Proxy: $PROXY"
echo "TMDB plugin enabled."
echo "Backup suffix: .bak.$STAMP"Run the script
Connect to the NAS through SSH and switch to root:
sudo -i
Make the script executable:
chmod +x setup_videostation_tmdb.sh
Run it with your proxy address and TMDB API key:
./setup_videostation_tmdb.sh \ http://192.168.1.10:7890 \ YOUR_TMDB_API_KEY
Verify the proxy configuration
Run:
grep -n "TMDB_PROXY\|proxy_url" \ /var/packages/VideoStation/target/plugins/syno_themoviedb/searchinc.py
You should see your proxy address.
You can also test the proxy directly:
curl -I \ -x http://192.168.1.10:7890 \ https://api.themoviedb.org
The script enables the TMDB plugin for both movies and TV shows. The built-in plugin test may still fail because it does not use the proxy configuration added to the Python plugin. This test result can be ignored as long as metadata retrieval works normally in Video Station.
Video Station updates or package repairs may overwrite the modified files. Run the script again if TMDB stops working after an update.
Recent Comments