diff --git a/RPi-youtube/RPi-youtube-0.2.zip b/RPi-youtube/RPi-youtube-0.3.zip similarity index 90% rename from RPi-youtube/RPi-youtube-0.2.zip rename to RPi-youtube/RPi-youtube-0.3.zip index fbd0c29..71188c6 100644 Binary files a/RPi-youtube/RPi-youtube-0.2.zip and b/RPi-youtube/RPi-youtube-0.3.zip differ diff --git a/RPi-youtube/background.js b/RPi-youtube/background.js index 6c4d48b..2a56b48 100644 --- a/RPi-youtube/background.js +++ b/RPi-youtube/background.js @@ -9,9 +9,16 @@ chrome.extension.onMessage.addListener( }) }) +function matchRuleShort(str, rule) { + return new RegExp("^" + rule.split("*").join(".*") + "$").test(str); +} + chrome.browserAction.onClicked.addListener(function (tab) { chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) { var url = tabs[0].url; + if (matchRuleShort(url, '*://*youtube.com/watch*')) { + chrome.tabs.executeScript(null, {file: "injected.js"}) + } console.log("Got click") console.log(url) chrome.runtime.sendNativeMessage('run_omx', diff --git a/RPi-youtube/injected.js b/RPi-youtube/injected.js new file mode 100644 index 0000000..28eee3a --- /dev/null +++ b/RPi-youtube/injected.js @@ -0,0 +1,32 @@ +function triggerMouseEvent(element, eventName, userOptions) { + var options = { // defaults + clientX: 0, clientY: 0, button: 0, + ctrlKey: false, altKey: false, shiftKey: false, + metaKey: false, bubbles: true, cancelable: true + // create event object: + }, event = element.ownerDocument.createEvent("MouseEvents"); + + if (!/^(?:click|mouse(?:down|up|over|move|out))$/.test(eventName)) { + throw new Error("Only MouseEvents supported"); + } + + if (typeof userOptions != 'undefined'){ // set the userOptions + for (var prop in userOptions) { + if (userOptions.hasOwnProperty(prop)) + options[prop] = userOptions[prop]; + } + } + // initialize the event object + event.initMouseEvent(eventName, options.bubbles, options.cancelable, + element.ownerDocument.defaultView, options.button, + options.clientX, options.clientY, options.clientX, + options.clientY, options.ctrlKey, options.altKey, + options.shiftKey, options.metaKey, options.button, + element); + // dispatch! + element.dispatchEvent(event); +} + +// triggerMouseEvent(document.getElementById('button.ytp-play-button.ytp-button'), 'click') +var player = document.getElementsByTagName('video')[0].pause() +//player.pauseVideo() diff --git a/RPi-youtube/manifest.json b/RPi-youtube/manifest.json index 12fc994..b987f80 100644 --- a/RPi-youtube/manifest.json +++ b/RPi-youtube/manifest.json @@ -2,24 +2,20 @@ "manifest_version": 2, "name": "RPi-youtube", "description": "This extension runs youtube videos in chromium through omxplayer allowing a much smoother viewing", - "version": "0.2", + "version": "0.3", "browser_action": { "default_icon": "icon_38.png", "default_title": "Extract video!" }, - "content_scripts": [ - { - "matches": ["*://*.youtube.com/watch*"], - "js": ["spin.js","get_url.js"] - } - ], "background": { "scripts": ["background.js"], "persistent": false }, "permissions": [ "tabs", - "nativeMessaging" + "nativeMessaging", + "http://*.youtube.com/*", + "https://*.youtube.com/*" ], "icons": {"48": "icon_48.png", "128": "icon_128.png" } diff --git a/native/rpi-youtube_5.0.0-1.deb b/native/rpi-youtube_5.0.0-1.deb new file mode 100644 index 0000000..d1380e1 Binary files /dev/null and b/native/rpi-youtube_5.0.0-1.deb differ diff --git a/native/run_omxplayer.py b/native/run_omxplayer.py index bf3134b..dd29e09 100755 --- a/native/run_omxplayer.py +++ b/native/run_omxplayer.py @@ -6,7 +6,7 @@ import urllib2 import os -VERSION="0.4.3" +VERSION="0.5" def check_update(): @@ -43,5 +43,11 @@ def read_thread_func(): url = json.loads(read_thread_func())['text'] +FNULL = open(os.devnull, 'w') print 'OK' +try: + urllib2.urlopen('http://localhost:9192') +except: + subprocess.Popen(['nohup', 'ytdl_server.py', '&'], stdout=FNULL) + subprocess.call("omxplayergui ytdl " + url, shell=True)