From de31b31a1e2a50daa7ea9ad116ba770aab59af2e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 7 Mar 2019 22:42:24 +0100 Subject: [PATCH] playVideoOnDreambox as WebExtension --- .gitignore | 3 + README.rst | 70 +++++++++++++++++++++ build.sh | 17 +++++ src/background-script.js | 133 +++++++++++++++++++++++++++++++++++++++ src/icon.png | Bin 0 -> 473 bytes src/manifest.json | 34 ++++++++++ src/options.html | 19 ++++++ src/options.js | 20 ++++++ 8 files changed, 296 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100755 build.sh create mode 100644 src/background-script.js create mode 100644 src/icon.png create mode 100644 src/manifest.json create mode 100644 src/options.html create mode 100644 src/options.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b68d6d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/node_modules/ +/dist/ +/package-lock.json diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..d9cda20 --- /dev/null +++ b/README.rst @@ -0,0 +1,70 @@ +************************************* +playVideoOnDreambox Firefox extension +************************************* + +Firefox__ browser addon (extension) that adds a "Play on Dreambox" button to the +toolbar. +Pressing it plays the video of the current tab on your Dreambox__ satellite +receiver. + +Works fine with a Dreambox `DM7080 HD`__. + +You can also right-click a link to a video page and select +"Play linked video on Dreambox". +That way you don't even need to open video detail pages. + +__ https://www.mozilla.org/firefox +__ http://www.dream-multimedia-tv.de/products +__ http://www.dream-multimedia-tv.de/dm7080-hd + +.. contents:: + + +Features +======== +- Toolbar button to play the video on the current page +- Context menu item to play the video on the linked page. + Nice for video lists; no need to access the detail page anymore. +- Dreambox web interface access token support +- Supports hundreds of video sites, see the `youtube-dl site support list`__. +- Errors are displayed via the operating system's notification system + +__ http://rg3.github.io/youtube-dl/supportedsites.html + + +Dependencies +============ +You need to have the playVideoOnDreamboxProxy software running in your +network. +It will do the heavy lifting of extracting the video URL from the website +and sending it to the dreambox. + +This browser extension only sends the current tab URL to this proxy service. + +In the extension settings, configure the proxy URL (it ends with ``play.php``). + + +License +======= +``playVideoOnDreambox`` is licensed under the `GPL v3`__ or later. + +__ http://www.gnu.org/licenses/gpl.html + + +Homepage +======== +Web site + http://cweiske.de/playVideoOnDreambox.htm#firefox +Source code + http://git.cweiske.de/playVideoOnDreambox.git + + Mirror: https://github.com/cweiske/playVideoOnDreambox +Firefox Add-ons site + https://addons.mozilla.org/de/firefox/addon/play-video-on-dreambox/ +Dreambox forum thread + http://www.dream-multimedia-tv.de/board/index.php?page=Thread&threadID=20224 + + +Author +====== +Written by Christian Weiske, cweiske@cweiske.de diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..daa405c --- /dev/null +++ b/build.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +version=$(jq -r .version < src/manifest.json) + +filename="dist/playVideoOnDreambox-browser-$version.zip" +test -d dist || mkdir dist + +if [ -f "$filename" ]; then + echo "File exists already: $filename" >&2 + exit 10 +fi + +cd src +zip -r "../$filename" * + +echo "File created: $filename" diff --git a/src/background-script.js b/src/background-script.js new file mode 100644 index 0000000..1e9af9e --- /dev/null +++ b/src/background-script.js @@ -0,0 +1,133 @@ +function handleToolbarPlay() +{ + browser.tabs.query({currentWindow: true, active: true}).then( + function (tabs) { + playUrl(tabs.shift().url); + } + ); +} + +function handleMenuClick(event) +{ + if ('mediaType' in event && event.mediaType == "video") { + playUrl(event.srcUrl); + } else if ('linkUrl' in event) { + playUrl(event.linkUrl); + } else { + console.error('No idea what to play here', event); + } +} + +function playUrl(url) +{ + browser.browserAction.setBadgeText({text: '⧗'}); + browser.browserAction.setBadgeTextColor({color: 'white'}); + browser.browserAction.setBadgeBackgroundColor({color: 'orange'}); + + browser.storage.sync.get('proxyUrl').then((res) => { + var proxyUrl = res.proxyUrl; + console.log(url, proxyUrl); + + fetch( + proxyUrl, + { + method: 'POST', + headers: { + 'Content-Type': 'text/plain' + }, + //mode: 'no-cors', + body: url + } + ).then(function (response) { + console.log(response.ok); + if (response.ok) { + videoPlayOk(response); + } else { + videoPlayError(response); + } + }).catch(function (error) { + //e.g. Network error (when no network available) + showError(error.message); + }); + }); +} + +function videoPlayOk(response) +{ + browser.notifications.create( + 'dreambox-playing', + { + type: 'basic', + title: 'Play video on Dreambox', + message: 'Video is playing now', + iconUrl: 'icon.png' + } + ); + + browser.browserAction.setBadgeText({text: '🗸'}); + browser.browserAction.setBadgeTextColor({color: 'white'}); + browser.browserAction.setBadgeBackgroundColor({color: 'green'}); + setBadgeRemovalTimeout(); +} + +function videoPlayError(response) +{ + response.text().then(function (text) { + showError(text); + }); +} + +function showError(message) +{ + console.log("Play error: ", message); + + browser.notifications.create( + 'dreambox-error', + { + type: 'basic', + title: 'Error playing video', + message: message, + iconUrl: 'icon.png' + } + ); + + browser.browserAction.setBadgeText({text: 'x'}); + browser.browserAction.setBadgeTextColor({color: 'white'}); + browser.browserAction.setBadgeBackgroundColor({color: 'red'}); + setBadgeRemovalTimeout(); +} + +function setBadgeRemovalTimeout() +{ + setTimeout( + function () { + browser.browserAction.setBadgeText({text:""}); + }, + 5000 + ); +} + +//toolbar button +browser.browserAction.onClicked.addListener(handleToolbarPlay); + +//context menu +browser.menus.create({ + id: "play-video-on-dreambox-link", + title: "Play linked video on dreambox", + contexts: ["link"], + onclick: handleMenuClick, + icons: { + "16": "icon.png", + "32": "icon.png", + } +}); +browser.menus.create({ + id: "play-video-on-dreambox-video", + title: "Play this video on dreambox", + contexts: ["video"], + onclick: handleMenuClick, + icons: { + "16": "icon.png", + "32": "icon.png", + } +}); diff --git a/src/icon.png b/src/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c74bb35ebeb6faa46493c38c2f69294228c1530e GIT binary patch literal 473 zcmV;~0Ve*5P)@jLJ-kUv`xHHh{MLO8T!pm(Oc$Lq{eEsL0(HAx0VMM&tF>EDDwW9Paww(3 z2*94@&)!`w7iO~=zVGX879h1+O;)Rwm{OxaHwuMm + + + + + +
+ + + +

+ You need to have the + proxy application + running on a server in your network. +

+
+ + + diff --git a/src/options.js b/src/options.js new file mode 100644 index 0000000..3ca011f --- /dev/null +++ b/src/options.js @@ -0,0 +1,20 @@ +function saveOptions(e) +{ + browser.storage.sync.set( + { + proxyUrl: document.querySelector("#proxyUrl").value + } + ); + e.preventDefault(); +} + +function restoreOptions() +{ + var gettingItem = browser.storage.sync.get('proxyUrl'); + gettingItem.then((res) => { + document.querySelector("#proxyUrl").value = res.proxyUrl || null; + }); +} + +document.addEventListener('DOMContentLoaded', restoreOptions); +document.querySelector('form').addEventListener('submit', saveOptions); -- 2.30.2