improve youtube collector/parser

This commit is contained in:
ed 2021-08-08 02:47:04 +02:00
parent 621471a7cb
commit 228f71708b
2 changed files with 40 additions and 10 deletions

View file

@ -0,0 +1,32 @@
// ==UserScript==
// @name youtube-playerdata-hub
// @match https://youtube.com/*
// @match https://*.youtube.com/*
// @version 1.0
// @grant GM_addStyle
// ==/UserScript==
function main() {
var sent = {};
function send(txt) {
if (sent[txt])
return;
fetch('https://127.0.0.1:3923/playerdata?_=' + Date.now(), { method: "PUT", body: txt });
console.log('[yt-ipr] yeet %d bytes', txt.length);
sent[txt] = 1;
}
function collect() {
setTimeout(collect, 60 * 1000);
var pd = document.querySelector('ytd-watch-flexy');
if (pd)
send(JSON.stringify(pd.playerData));
}
setTimeout(collect, 5000);
}
var scr = document.createElement('script');
scr.textContent = '(' + main.toString() + ')();';
(document.head || document.getElementsByTagName('head')[0]).appendChild(scr);
console.log('[yt-ipr] a');

View file

@ -2,6 +2,7 @@
import re
import sys
import gzip
import json
from datetime import datetime
@ -14,20 +15,17 @@ example usage:
:c,mtp=yt-id,yt-title,yt-author,yt-channel,yt-views,yt-private,yt-expires=bin/mtag/yt-ipr.py
:c,mte=yt-id,yt-title,yt-author,yt-channel,yt-views,yt-private,yt-expires
quick userscript to push them across:
console.log('a');
setTimeout(function() {
for (var scr of document.querySelectorAll('script[nonce]'))
if (scr.innerHTML.indexOf('manifest.googlevideo.com/api/manifest')>0)
fetch('https://127.0.0.1:3923/playerdata', {method:"PUT", body: scr.innerHTML});
}, 10*1000);
see res/yt-ipr.user.js for the example userscript to go with this
"""
def main():
with open(sys.argv[1], "r", encoding="utf-8") as f:
txt = f.read()
try:
with gzip.open(sys.argv[1], "rt", encoding="utf-8", errors="replace") as f:
txt = f.read()
except:
with open(sys.argv[1], "r", encoding="utf-8", errors="replace") as f:
txt = f.read()
txt = "{" + txt.split("{", 1)[1]