Skip to content

Instantly share code, notes, and snippets.

@JannisRex
Last active November 23, 2019 14:03
Show Gist options
  • Save JannisRex/f50894d0ca049157ea5ddbe0ef109151 to your computer and use it in GitHub Desktop.
Save JannisRex/f50894d0ca049157ea5ddbe0ef109151 to your computer and use it in GitHub Desktop.
GreaseMonkey - Download PlaysTV Video with Title
// ==UserScript==
// @name GetVideoUrl
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @require https://gist.githubusercontent.com/JannisRex/4e61fd1707d65c6e51addd5a2abc34e9/raw/5b151dcf23aecb9b285a5ddbb3bf80a16e13f9d4/download.js
// @match https://plays.tv/video/*
// @noframes
// @grant GM.deleteValue
// @grant GM.getValue
// @grant GM.setValue
// ==/UserScript==
// deleting previous stored bool
GM.deleteValue('isFetched')
let isFetched
// flag to only execute download once
(async () => {
// getting initial value
isFetched = await GM.getValue('isFetched', false)
// alert('bool: ' + isFetched)
})()
if (!isFetched) {
// waiting for initial JS
// to set video src
waitForKeyElements(
'div.video',
getLink
)
}
function getLink(jNode) {
// set flag to true
(async () => {
// Note awaiting the set -- required so the next get sees this set.
await GM.setValue('isFetched', true)
})()
// get url & create link
const videoTitle = getVideoTitle()
let vids = document.getElementsByTagName('video')
let links = vids[0].getElementsByTagName('source')
let downloadLink = links[1].src
if (links.length < 2) {
downloadLink = links[0].src
}
GM.setValue('isFetched', true)
download(downloadLink, videoTitle, 'audio/mp4')
//alert(downloadLink)
//alert(videoTitle)
}
function getVideoTitle() {
// getting title and creating regEx
let tempTitle = document.title
const hyphenBefore = /^(.*?)\-/
const hyphenAfter = /-.*$/
// getting matches from regEx
// and replacing in title afterwards
try {
let matchA = tempTitle.match(hyphenBefore)[0]
tempTitle = tempTitle.replace(matchA, '')
let matchB = tempTitle.match(hyphenAfter)[0]
tempTitle = tempTitle.replace(matchB, '')
} catch (e) {
alert(e)
}
const videoTitle = tempTitle
return videoTitle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment