diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a5cede --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +### Note ### +The WebExtension, which can be found under "add-on", connects to the native application and downloads the video using youtube-dl + +The native application, which can be found under "app", listens for messages from the WebExtension. When it receives a message, the native application runs youtube-dl in the Downloads folder for the passed url from the WebExtension. + +*** Look in your Downloads folder to find your video. *** + +### Mac OS/Linux Setup ### +To get this working do the following: + +1. Check that the [file permissions](https://en.wikipedia.org/wiki/File_system_permissions) for "youtube-dl-bridge.py" include the `execute` permission. +2. Edit the "path" property of "web_video_dl.json" to point to the location of "youtube-dl-bridge.py" on your computer. +3. copy "web_video_dl.json" to the correct location on your computer. See [App manifest location ](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_manifests#Manifest_location) to find the correct location for your OS. +4. Install the webextension and enjoy! diff --git a/add-on/background.js b/add-on/background.js new file mode 100644 index 0000000..2f3c45f --- /dev/null +++ b/add-on/background.js @@ -0,0 +1,10 @@ +// On a click on the browser action, send the app a message. +browser.browserAction.onClicked.addListener(() => { + // Create new connect to the app so we can dl multiple stuff at same time. + let port = browser.runtime.connectNative("web_video_dl"); + browser.tabs.query({currentWindow: true, active: true}).then((tab) => { + tab = tab[0]; + console.log("Downloding: " + tab.url); + port.postMessage(tab.url); + }); +}); diff --git a/add-on/icons/video.png b/add-on/icons/video.png new file mode 100644 index 0000000..933ca39 Binary files /dev/null and b/add-on/icons/video.png differ diff --git a/add-on/manifest.json b/add-on/manifest.json new file mode 100644 index 0000000..6aa5213 --- /dev/null +++ b/add-on/manifest.json @@ -0,0 +1,19 @@ +{ + "name": "Web Video Downloader", + "description": "Use youtube-dl to download videos from the web.", + "manifest_version": 2, + "version": "1.0", + "icons": { "64": "icons/video.png" }, + + "applications": { + "gecko": { + "id": "1itdominator@gmail.com", + "strict_min_version": "50.0" + } + }, + + "permissions": ["nativeMessaging", "activeTab"], + "background": { "scripts": ["background.js"] }, + "browser_action": { "default_icon": "icons/video.png" } + +} diff --git a/app/web_video_dl.json b/app/web_video_dl.json new file mode 100644 index 0000000..bac40cc --- /dev/null +++ b/app/web_video_dl.json @@ -0,0 +1,7 @@ +{ + "name": "web_video_dl", + "description": "Video downloader using youtube-dl", + "path": "/insert/your/path/here/to/youtube-dl-bridge.py", + "type": "stdio", + "allowed_extensions": [ "1itdominator@gmail.com" ] +} diff --git a/app/youtube-dl-bridge.py b/app/youtube-dl-bridge.py new file mode 100755 index 0000000..0420397 --- /dev/null +++ b/app/youtube-dl-bridge.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import sys +import json +import struct +import subprocess + +# Python 2.x version (if sys.stdin.buffer is not defined) +# Read a message from stdin and decode it. +def getMessage(): + rawLength = sys.stdin.read(4) + if len(rawLength) == 0: + sys.exit(0) + messageLength = struct.unpack('@I', rawLength)[0] + message = sys.stdin.read(messageLength) + return json.loads(message) + +while True: + receivedMessage = getMessage() + + if receivedMessage: + command = "cd ~/Downloads && youtube-dl " + receivedMessage; + subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)