Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
m1k1o
GitHub Repository: m1k1o/neko
Path: blob/master/apps/opera/fix-ffmpeg-widevine.sh
1300 views
1
#!/bin/bash
2
# From https://github.com/Ld-Hagen/fix-opera-linux-ffmpeg-widevine.
3
4
# Config section
5
readonly FIX_FFMPEG=true
6
readonly FIX_WIDEVINE=true
7
readonly FIX_DIR='/tmp/opera-fix'
8
# readonly FFMPEG_SRC_MAIN='https://api.github.com/repos/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases'
9
readonly FFMPEG_SRC_MAIN='https://api.github.com/repos/Ld-Hagen/nwjs-ffmpeg-prebuilt/releases'
10
readonly FFMPEG_SRC_ALT='https://api.github.com/repos/Ld-Hagen/fix-opera-linux-ffmpeg-widevine/releases'
11
readonly WIDEVINE_SRC='https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/main/toolkit/content/gmp-sources/widevinecdm.json'
12
readonly FFMPEG_SO_NAME='libffmpeg.so'
13
readonly WIDEVINE_SO_NAME='libwidevinecdm.so'
14
readonly WIDEVINE_MANIFEST_NAME='manifest.json'
15
16
OPERA_VERSIONS=()
17
if [ -x "$(command -v opera)" ]; then
18
OPERA_VERSIONS+=("opera")
19
fi
20
if [ -x "$(command -v opera-beta)" ]; then
21
OPERA_VERSIONS+=("opera-beta")
22
fi
23
24
# Getting download links
25
printf 'Getting download links...\n'
26
## ffmpeg
27
if $FIX_FFMPEG; then
28
readonly FFMPEG_URL_MAIN=$(curl -sL4 $FFMPEG_SRC_MAIN | jq -rS 'sort_by(.published_at) | .[-1].assets[0].browser_download_url')
29
readonly FFMPEG_URL_ALT=$(curl -sL4 $FFMPEG_SRC_ALT | jq -rS 'sort_by(.published_at) | .[-1].assets[0].browser_download_url')
30
[[ $(basename $FFMPEG_URL_ALT) < $(basename $FFMPEG_URL_MAIN) ]] && readonly FFMPEG_URL=$FFMPEG_URL_MAIN || readonly FFMPEG_URL=$FFMPEG_URL_ALT
31
if [[ -z $FFMPEG_URL ]]; then
32
printf 'Failed to get ffmpeg download URL. Exiting...\n'
33
exit 1
34
fi
35
fi
36
## Widevine
37
if $FIX_WIDEVINE; then
38
readonly WIDEVINE_URL=$(curl -sL4 $WIDEVINE_SRC | jq -r '.vendors."gmp-widevinecdm".platforms."Linux_x86_64-gcc3".mirrorUrls[0]')
39
fi
40
41
# Downloading files
42
printf 'Downloading files...\n'
43
mkdir -p "$FIX_DIR"
44
## ffmpeg
45
if $FIX_FFMPEG; then
46
curl -L4 --progress-bar $FFMPEG_URL -o "$FIX_DIR/ffmpeg.zip"
47
if [ $? -ne 0 ]; then
48
printf 'Failed to download ffmpeg. Check your internet connection or try later\n'
49
exit 1
50
fi
51
fi
52
## Widevine
53
if $FIX_WIDEVINE; then
54
curl -L4 --progress-bar "$WIDEVINE_URL" -o "$FIX_DIR/widevine.zip"
55
if [ $? -ne 0 ]; then
56
printf 'Failed to download Widevine CDM. Check your internet connection or try later\n'
57
exit 1
58
fi
59
fi
60
61
# Extracting files
62
## ffmpeg
63
if $FIX_FFMPEG; then
64
echo "Extracting ffmpeg..."
65
unzip -o "$FIX_DIR/ffmpeg.zip" -d $FIX_DIR > /dev/null
66
fi
67
## Widevine
68
if $FIX_WIDEVINE; then
69
echo "Extracting WidevineCDM..."
70
unzip -oj "$FIX_DIR/widevine.zip" -d $FIX_DIR > /dev/null 2>/dev/null
71
fi
72
73
for opera in ${OPERA_VERSIONS[@]}; do
74
echo "Doing $opera"
75
EXECUTABLE=$(command -v "$opera")
76
OPERA_DIR=$(dirname $(readlink -f $EXECUTABLE))
77
OPERA_LIB_DIR="$OPERA_DIR/lib_extra"
78
OPERA_WIDEVINE_DIR="$OPERA_LIB_DIR/WidevineCdm"
79
OPERA_WIDEVINE_SO_DIR="$OPERA_WIDEVINE_DIR/_platform_specific/linux_x64"
80
OPERA_WIDEVINE_CONFIG="$OPERA_DIR/resources/widevine_config.json"
81
82
# Removing old libraries and preparing directories
83
printf 'Removing old libraries & making directories...\n'
84
## ffmpeg
85
if $FIX_FFMPEG; then
86
rm -f "$OPERA_LIB_DIR/$FFMPEG_SO_NAME"
87
mkdir -p "$OPERA_LIB_DIR"
88
fi
89
## Widevine
90
if $FIX_WIDEVINE; then
91
rm -rf "$OPERA_WIDEVINE_DIR"
92
mkdir -p "$OPERA_WIDEVINE_SO_DIR"
93
fi
94
95
# Moving libraries to their place
96
printf 'Moving libraries to their places...\n'
97
## ffmpeg
98
if $FIX_FFMPEG; then
99
cp -f "$FIX_DIR/$FFMPEG_SO_NAME" "$OPERA_LIB_DIR"
100
chmod 0644 "$OPERA_LIB_DIR/$FFMPEG_SO_NAME"
101
fi
102
## Widevine
103
if $FIX_WIDEVINE; then
104
cp -f "$FIX_DIR/$WIDEVINE_SO_NAME" "$OPERA_WIDEVINE_SO_DIR"
105
chmod 0644 "$OPERA_WIDEVINE_SO_DIR/$WIDEVINE_SO_NAME"
106
cp -f "$FIX_DIR/$WIDEVINE_MANIFEST_NAME" "$OPERA_WIDEVINE_DIR"
107
chmod 0644 "$OPERA_WIDEVINE_DIR/$WIDEVINE_MANIFEST_NAME"
108
printf "[\n {\n \"preload\": \"$OPERA_WIDEVINE_DIR\"\n }\n]\n" > "$OPERA_WIDEVINE_CONFIG"
109
fi
110
done
111
112
# Removing temporary files
113
printf 'Removing temporary files...\n'
114
rm -rf "$FIX_DIR"
115
116