playVideoOnDreambox as WebExtension master github/master v0.6.0
authorChristian Weiske <cweiske@cweiske.de>
Thu, 7 Mar 2019 21:42:24 +0000 (22:42 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 7 Mar 2019 21:42:24 +0000 (22:42 +0100)
.gitignore [new file with mode: 0644]
README.rst [new file with mode: 0644]
build.sh [new file with mode: 0755]
src/background-script.js [new file with mode: 0644]
src/icon.png [new file with mode: 0644]
src/manifest.json [new file with mode: 0644]
src/options.html [new file with mode: 0644]
src/options.js [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b68d6d8
--- /dev/null
@@ -0,0 +1,3 @@
+/node_modules/
+/dist/
+/package-lock.json
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..d9cda20
--- /dev/null
@@ -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 (executable)
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 (file)
index 0000000..1e9af9e
--- /dev/null
@@ -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 (file)
index 0000000..c74bb35
Binary files /dev/null and b/src/icon.png differ
diff --git a/src/manifest.json b/src/manifest.json
new file mode 100644 (file)
index 0000000..1adf8f3
--- /dev/null
@@ -0,0 +1,34 @@
+{
+    "manifest_version": 2,
+    "name": "playVideoOnDreambox",
+    "version": "0.6.0",
+    "description": "Play videos from websites on your Dreambox satellite receiver",
+    "homepage_url": "https://cweiske.de/playVideoOnDreambox.htm#firefox",
+    "author": "Christian Weiske",
+    "icons": {
+        "32": "icon.png"
+    },
+    "permissions": [
+        "activeTab",
+        "menus",
+        "notifications",
+        "storage"
+    ],
+    "browser_action": {
+        "default_icon": "icon.png",
+        "default_title": "Play video on Dreambox"
+    },
+    "background": {
+        "scripts": ["background-script.js"]
+    },
+    "options_ui": {
+        "page": "options.html",
+        "browser_style": true,
+        "chrome_style": true
+    },
+    "browser_specific_settings": {
+        "gecko": {
+            "id": "@playvideoondreambox"
+        }
+    }
+}
diff --git a/src/options.html b/src/options.html
new file mode 100644 (file)
index 0000000..b59ad1d
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <meta charset="utf-8"/>
+ </head>
+ <body>
+  <form>
+   <label>playVideoOnDreambox<strong>Proxy</strong> URL</label>
+   <input type="url" id="proxyUrl" placeholder="http://.../play.php"/>
+   <button type="submit">Save</button>
+   <p>
+    You need to have the
+    <a href="https://cweiske.de/playVideoOnDreambox.htm#proxy">proxy application</a>
+    running on a server in your network.
+   </p>
+  </form>
+  <script src="options.js" type="text/javascript"></script>
+ </body>
+</html>
diff --git a/src/options.js b/src/options.js
new file mode 100644 (file)
index 0000000..3ca011f
--- /dev/null
@@ -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);