HOWTO: Play HTML5 and Youtube Videos in an external Player

Post your tutorials for using applications or performing related tasks here.
Note: Not for "how do I...?" Questions!
Forum rules
Tutorials and Howtos should only relate to developed software, and not to third party applications. e.g.: Don't post a generic Howto for configuring a firewall.
If you have a question how to do something, you should use one of the support boards, not this board. It is meant for people to document and post instructions.
Kiray

HOWTO: Play HTML5 and Youtube Videos in an external Player

Unread post by Kiray » 2016-11-01, 17:48

Hello,
I already Posted this in another Thread, but I'm not sure if it's easily findable there, so I'm posting it here Again.
So I made an Greasemonkey Script which extracts HTML5 Videos and Youtube Video Links, removes the HTML5 Video Element and put's them into the Clipboard where an external Player or Script can pick it up.

Here the Greasemonkey Script:

Code: Select all

// ==UserScript==
// @name        Video2Clipboard
// @namespace   none
// @description Copies "youtube.com/watch" URL and HTML5 Video Sources to Clipboard and removes the Element, so External Programs can pick them up.
// @include     *
// @version     1.0
// @grant       GM_setClipboard
// ==/UserScript==
var clipprefix="extplay ";
var regex = /https*:\/\/www.youtube.*\/watch/;

//Check if Youtube
if (regex.test(window.location.href)) {
    GM_setClipboard(clipprefix+window.location.href)
    return;
}

//Remove and copy HTML5 Videos
//document.addEventListener('DOMContentLoaded',function() {
var elems = document.querySelectorAll("video");
for (var i = 0; i < elems.length; i++) {
    elems[i].remove();
    GM_setClipboard(clipprefix+elems[i].querySelector("source").getAttribute("src"));
}
//});

//Remove and copy newly created video elements
document.addEventListener("DOMNodeInserted", function(e) {
    var elem = e.target;
    if (elem.nodeName == "VIDEO") {
        elem.remove();
        GM_setClipboard(clipprefix+elem.querySelector("source").getAttribute("src"));
    }
}, false);
Just Click on the Greasemonkey dropdown -> "New User Script", Enter any Script Name and "none" as Namespace and just overwrite the Contents in the Text Editor with above Script.

And here an Bash One-liner which detects and passes the Link to the Videoplayer (smplayer in this Case):

Code: Select all

while true; do if [[ -n $( xclip -o | grep '^extplay') ]]; then url=$(xclip -o | awk '{print $2}'); smplayer $url; echo $url | xclip -i; fi; sleep 1; done
For Youtube Videos you need
1.) an Videoplayer that supports Youtube Video Links (which is the case for smplayer)
2.) and NoScript to stop the Embedded Youtube-Player from Playing.

Locked