From ab016cd7bf1bb2edcd9d6f8e395282bf2c97ebb7 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Sun, 6 Jan 2019 23:54:04 -0600 Subject: [PATCH] Initial code commit --- README.md | 14 ++++++++++++++ add-on/background.js | 10 ++++++++++ add-on/icons/video.png | Bin 0 -> 2546 bytes add-on/manifest.json | 19 +++++++++++++++++++ app/web_video_dl.json | 7 +++++++ app/youtube-dl-bridge.py | 23 +++++++++++++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 README.md create mode 100644 add-on/background.js create mode 100644 add-on/icons/video.png create mode 100644 add-on/manifest.json create mode 100644 app/web_video_dl.json create mode 100755 app/youtube-dl-bridge.py 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 0000000000000000000000000000000000000000..933ca3944c8133b2a96ae16a51f157f69b835e9d GIT binary patch literal 2546 zcmV&zYm-=43&lu0y)RD7J!rzJP)J<*ae(!+je3~ zTflLg=xF70Ev?98YECY_Fb%Zhmx2%gjX(pCn5qv57nC1*cRQ(v9>eeIs$?`XFH)i` zh+%EKg}@oB0Mz_vdYmA>PwK%(aCfyJG;K~=fY;N*;BTKLaN0^3o}-)&03?9y>%%*E z2oVg3P(xyO#L+>ydK|gc%9!LPFg&-z0e45`?bN_2e^iCa0LOEg&=<#W1k%-o(O< zHzPBd`RfE5zke%@o9;j;%KQWXVByA_iEsE;p@N&AVX)!$?_uA4=deGRB_L+q6V>0i z4(aCTd~7p*A_+6RE#^cb6yLC(#@oJ&Vp;Py6Rcaemiim7n^Z;jf0GL5qET{Uo?1ZP zd)wLn{7WP~e@1!7IRQZLKmN(CJMJR!@Anx3(lfXXW*va;zrD%MJMSj-!5$RTKmdcj zk2}S%Snc7+tOC&a+Mj9t(N7rMyAPosK6{ZsYP1zdSusx-_cUSKc2z*k8UUTI{*l%n z-%Dy=J4zrh;rWp7GccIO8yG+i4Iy0@uYUkPlbHyHln6Njm z9eD0}_Wa^OhPt{@^ogf#()W==F143jNYnY}5U_285V)O(75v@{gmkGs|XwuM~K6Q zTJxnZ61(^!KDz53ay`8WDUqkGBzwVEuo%M)MuBS`$7#21`<}va--If)j1y@B_WQlP z^sHTvOe80-z2_18&bRRmlYNi;8ZTKQ<&_dtmD65)mdL3q$`Z1f)(_Zo{Y`iS1NaZz z2X-R?RV5aSjqjQT;$>ADJq$bn z%#H;VUS<>nKuT02Nd5We9PyZjVNh3BM=TaY8Rb`cdwcOFo)(?rI8JON8N9<#Z*dAOL$?(wEDjnkFlrd4lNatEPwD(KKw^roFu#Aq3fMmSi$XO-;>6!3iXf$O4qw zT8wkoF!;)A(?VNGAP5+W!m`Z|SEalsGx#z$rcGC@qCw0wO>|u!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ifest.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)