Skip to content

Instantly share code, notes, and snippets.

@proxium
Forked from ruario/intro-latest-widevine.md
Created February 6, 2019 17:15
Show Gist options
  • Save proxium/edfe8f8e6cb06fef8dd0392b4a0f2145 to your computer and use it in GitHub Desktop.
Save proxium/edfe8f8e6cb06fef8dd0392b4a0f2145 to your computer and use it in GitHub Desktop.
Fetches the latest Linux Widevine binary so that it can be used by Vivaldi.

With the release of Vivaldi 2.2, this page is now obsolete and unmaintained. Widevine is fetched automatically on post install of our official packages. The information below and the script are left for historical reasons but will not be updated.


Summary

A bunch of people asked how they could use this script with pure Chromium on Ubuntu. The following is a quick guide. Though I still suggest you at least try Vivaldi. Who knows, you might like it. Worried about proprietary componants? Remember that libwidevinecdm.so is a binary blob you are taking from Chrome, so by following this guide you will have already made your distro less "pure". Also all our additions to the Chromium base are open source and our UI, while not open, is written in HTML/CSS/JS. Thus you can see exactly what we are doing (no funny business).

If you still want to run Chromium, the following explains how it is done.

Note: For ARM(hf) use this instead. Beware it requires a +2Gb download of a ChromeOS recovery image. You can actually run it on a “regular” (x86 or x86_64 Linux) PC as it will create an archive file that can be copied to the target machine.

Chromium setup

  • Install the package "chromium-codecs-ffmpeg-extra" to provide H.264/MP4 support (used by videos on Netflix). After install, you need to restart Chromium. You can confirm that it is installed and working correctly by going to http://www.quirksmode.org/html5/tests/video.html and checking that the first video listed plays.

  • Next run the script (latest-widevine.sh). This will create the file "libwidevinecdm.so" in "/opt/google/chrome".

  • Replace the "libwidevinecdm.so" provided by Chromium with a symlink to the file from Chrome:

sudo ln -fs /opt/google/chrome/libwidevinecdm.so /usr/lib/chromium-browser/libwidevinecdm.so 

Note: The path is typically "/usr/lib64/chromium/lib/libwidevinecdm.so" on non Debian/Ubuntu based distros.

You can confirm that DRM'd H.264/MP4 content is now playable by going to http://demo.castlabs.com/ and trying some of the demos.

Damn you Netflix!

The final complication is that Netflix does not expect pure Chromium to be able to be able play videos and hence they do a stupid thing. If they detect that Chromium is accesing a video, they point you to install Silverlight! This is particularly dumb because: you are running Linux (no Silverlight); Silverlight is an NPAPI plugin and Chrom(e|ium) only supports PPAPI. You will need to work around this.

  • Delete any cookies or data associated with Netflix. If you have failed to play videos once, then Netflix stores information about this in a cookie and you won't be able to play vidoes, even once your system is now correctly configured. Another "WTF‽" moment from the Netflix team.

  • Via a user agent editing extention or by starting Chromium with the -user-agent switch, remove the reference to "Ubuntu Chromium/XX.0.XXXX.XX", e.g.

/usr/lib/chromium-browser/chromium-browser --user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36'

Note: An extenstion is best otherwise you will need to start Chromium from the command line every time or edit the .desktop file to include this switch.

One final point. Every time Chromium upgrades it will replace the libwidevinecdm.so symlink with its own file. Thus you will need to remove it and re-create the symlink. I would also suggest re-running latest-widevine.sh at that point, to check for new versions and upgrade if needed.

#!/bin/sh
# For ARM use this instead
# https://gist.github.com/ruario/19a28d98d29d34ec9b184c42e5f8bf29
available () {
command -v "$1" >/dev/null 2>&1
}
# Make sure we have wget or curl
if available wget; then
SILENT_DL="wget -qO-"
LOUD_DL="wget"
elif available curl; then
SILENT_DL="curl -s"
LOUD_DL="curl -O"
else
echo "Install wget or curl" >&2
exit 1
fi
# Use the architecture of the current machine or whatever the user has set
# externally
ARCH="${ARCH:-$(uname -m)}"
case "$ARCH" in
x86_64) WIDEVINE_ARCH="x64" ;;
i?86) WIDEVINE_ARCH="ia32" ;;
arm*) echo "For ARM use https://gist.github.com/ruario/19a28d98d29d34ec9b184c42e5f8bf29 instead" >&2 ; exit 1 ;;
*) echo "The architecture $ARCH is not supported." >&2 ; exit 1 ;;
esac
# Set Output dir
WIDEVINE_INSTALL_DIR="${WIDEVINE_INSTALL_DIR:-/opt/google/chrome}"
# Set temp dir
TMP="${TMP:-/tmp}"
# Set staging dir
STAGINGDIR="$TMP/widevine-staging"
# Work out the latest Widevine version
## Google's current file tends to lie. 4.10.1196.0 is the latest version as of the 6th of December 2018
## Feel free to run this script as `$ WIDEVINE_VERSION=4.10.1196.0 ./latest-widevine.sh`
WIDEVINE_VERSION="${WIDEVINE_VERSION:-$($SILENT_DL https://dl.google.com/widevine-cdm/current.txt)}"
# Error out if $CDMVERISON is unset, e.g. because previous command failed
if [ -z "$WIDEVINE_VERSION" ]; then
echo "Could not work out the latest version; exiting" >&2
exit 1
fi
# Don't start repackaging if the same version is already installed
if [ -e "$WIDEVINE_INSTALL_DIR/widevine-$WIDEVINE_VERSION" ] ; then
echo "The latest Widevine ($WIDEVINE_VERSION) is already installed"
exit 0
fi
# If the staging directory is already present from the past, clear it down and
# re-create it.
if [ -d "$STAGINGDIR" ]; then
rm -fr "$STAGINGDIR"
fi
# Stop on any error
set -eu
# Make and switch to the staging directory
mkdir -p "$STAGINGDIR"
cd "$STAGINGDIR"
# Now get the latest widevine zip for the users architecture
$LOUD_DL "https://dl.google.com/widevine-cdm/${WIDEVINE_VERSION}-linux-${WIDEVINE_ARCH}.zip"
# Extract the contents of Widevine package
if available unzip; then
unzip "${WIDEVINE_VERSION}-linux-${WIDEVINE_ARCH}.zip" libwidevinecdm.so
elif available bsdtar; then
bsdtar xf "${WIDEVINE_VERSION}-linux-${WIDEVINE_ARCH}.zip" libwidevinecdm.so
else
# The user's system has no obvious handler for Zip files. GZip can extract
# the first entry from a Zip. If libwidevinecdm.so is the first entry, we
# might just pull this off! ;)
missing_extractor_error () {
echo "Install InfoZip Unzip or BSD tar" >&2
exit 1
}
# Look in first 50 bytes for libwidevinecdm.so as it'll be mentioned there
# if it is the first entry in the zip
if head -c50 "${WIDEVINE_VERSION}-linux-${WIDEVINE_ARCH}.zip" | grep -Fq libwidevinecdm.so; then
# Hide the warning about multiple entries and ensure an exit code of 0
gzip -d < "${WIDEVINE_VERSION}-linux-${WIDEVINE_ARCH}.zip" > libwidevinecdm.so 2> /dev/null ||:
# Check that it looks like an executable
if ! file libwidevinecdm.so | grep -Fq ELF; then
missing_extractor_error
fi
else
missing_extractor_error
fi
fi
# Add version number file
touch "widevine-$WIDEVINE_VERSION"
# Escalate privileges if needed and copy files into place
if [ "$USER" = "root" ]; then
install -Dm644 libwidevinecdm.so "$WIDEVINE_INSTALL_DIR/libwidevinecdm.so"
install -Dm644 "widevine-$WIDEVINE_VERSION" "$WIDEVINE_INSTALL_DIR/widevine-$WIDEVINE_VERSION"
elif [ -r /etc/os-release ] && grep -qx 'ID=ubuntu' /etc/os-release; then
echo "Calling sudo ... If prompted, please enter your password so Widevine can be copied into place"
sudo install -Dm644 libwidevinecdm.so "$WIDEVINE_INSTALL_DIR/libwidevinecdm.so"
if [ -e "$WIDEVINE_INSTALL_DIR/libwidevinecdm.so" ]; then
sudo install -Dm644 "widevine-$WIDEVINE_VERSION" "$WIDEVINE_INSTALL_DIR/widevine-$WIDEVINE_VERSION"
else
echo "Something went wrong installing libwidevinecdm.so" >&2
exit 1
fi
else
echo "Please enter your root password so Widevine can be copied into place"
su -c "sh -c \"install -Dm644 libwidevinecdm.so $WIDEVINE_INSTALL_DIR/libwidevinecdm.so && install -Dm644 widevine-$WIDEVINE_VERSION $WIDEVINE_INSTALL_DIR/widevine-$WIDEVINE_VERSION\""
fi
# Tell the user we are done
echo "Widevine ($WIDEVINE_VERSION) installed into $WIDEVINE_INSTALL_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment