Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Add youtube pause and speed up using ytdl_server.py
  • Loading branch information
kusti8 committed Apr 30, 2016
2 parents 6f75558 + 372d66c commit 879080d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
Binary file not shown.
7 changes: 7 additions & 0 deletions RPi-youtube/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
32 changes: 32 additions & 0 deletions RPi-youtube/injected.js
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 4 additions & 8 deletions RPi-youtube/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Binary file added native/rpi-youtube_5.0.0-1.deb
Binary file not shown.
8 changes: 7 additions & 1 deletion native/run_omxplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import urllib2
import os

VERSION="0.4.3"
VERSION="0.5"


def check_update():
Expand Down Expand Up @@ -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)

0 comments on commit 879080d

Please sign in to comment.