Last active
April 17, 2024 10:54
-
-
Save donnaken15/acf68b8f4c9dd561ad64a5295544715b to your computer and use it in GitHub Desktop.
chorus for FastGH3; example usage: https://script.google.com/macros/s/AKfycbzdUJB_KiUDSlCchIF13hXhwHs1ObagXJ_WSmToL7RzTUb7H_npEBiYmj3k4VKPW3Wr/dev?id=1iDLvKmTLNyt0GW2DCqHQMAuvf_B12OO1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// or download from Drive link | |
// supports folders and archive files | |
// use https://script.google.com/macros/s/AKfycbzdUJB_KiUDSlCchIF13hXhwHs1ObagXJ_WSmToL7RzTUb7H_npEBiYmj3k4VKPW3Wr/dev?id=XXXXXXX | |
// or now: https://tinyurl.com/FGH3g?id=XXXXXXX | |
function runExample() { | |
doGet({ | |
"parameter": { | |
"id": "1fh7KiIhbFhikP04JHkltwJ5Dnpw1KK-P" //1Ediig76MdWu_bXoAvWahmWdlqOxC56K8" //"1rwUD1rT4Pq6wTCNJ17E-3hRWouclDLtg" <--TOO BIG 1fh7KiIhbFhikP04JHkltwJ5Dnpw1KK-P | |
} | |
}); | |
} | |
var hash = BigInt("0x5745534C45593634"), | |
hashrev = BigInt("0x343659454C534557"); | |
function WZK64(data) | |
{ | |
var _hash = hash; | |
for (var i=0;i<data.length;i++) | |
{ | |
_hash ^= BigInt((data[i] << 56) >> ((i%8)*8)); | |
} | |
_hash ^= BigInt(data.length) * BigInt(hashrev); | |
return _hash & BigInt("0xFFFFFFFFFFFFFFFF"); // getting weird 64 bit overflow | |
} | |
var timestart, time, log, dir = true, | |
html = | |
'<style>* {padding:1px; margin:1px; font-weight:400;\ | |
font-family: monospace, Roboto Mono, Courier;}\ | |
h1,h1 *{font-size:72px; padding:0; margin:0;}\ | |
h2{font-size:64px;}\ | |
div{font-size:40px;white-space:pre;}\ | |
</style><h1>chorus for \ | |
<!--wasteful but yoloswag-->\ | |
<a style="color:#0f9">Fa</a>\ | |
<a style="color:#f00">st</a>\ | |
<a style="color:#ff0">G</a>\ | |
<a style="color:#00f">H</a>\ | |
<a style="color:#f80">3</a>\ | |
</h1><h2>Log:</h2><br>', | |
htmlend = ""; | |
// don't know a fitting function name | |
function timeToFlt(val) { | |
val='2000-01-01T'+val+'Z'; | |
var date=new Date(new Date(val)-(new Date()).getTimezoneOffset() * 228000); | |
var time=(date.getHours()*3600)+(date.getMinutes()*60)+date.getSeconds()+(date.getMilliseconds()/1000); | |
return time; | |
} | |
function print(a) | |
{ | |
log += "[" + ((Date.now()-timestart)/1000).toFixed(3).padStart(7) + "] " + a + "\n"; | |
console.log(a); | |
} | |
// https://stackoverflow.com/questions/10744760/google-apps-script-to-open-a-url | |
function JS2OpenURL(url) | |
{ | |
//print("<a href=\""+url+"\">Link</a>"); | |
return '<script>var a = document.createElement("a"); a.href="'+url+'";' | |
+'if(document.createEvent){' | |
+' var event=document.createEvent("MouseEvents");' | |
+' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}' | |
+' event.initEvent("click",true,true); a.dispatchEvent(event);' | |
+'}else{ a.click() }</script>' | |
} | |
function cFGH3Link(id) | |
{ | |
return 'fastgh3://drive.google.com/uc?id='+id+"&export=download&confirm=t"; | |
} | |
function die(_html) | |
{ | |
return HtmlService.createHtmlOutput(html+_html+htmlend); | |
} | |
function doGet(e) { | |
//Logger.log(e); | |
timestart = Date.now(); | |
var cleanFolderSwitch = e.parameter.clean; | |
if (cleanFolderSwitch !== undefined) | |
{ | |
print("Got clean param"); | |
var FSPfolderName = "Z.FGH3$TMP"; | |
var FSPfolderSearch = DriveApp.getFoldersByName(FSPfolderName), FSPfolder, scan; | |
if (FSPfolderSearch.hasNext()) | |
{ | |
//DriveApp.removeFolder(FSPfolderSearch.next()); // not working | |
FSPfolder = FSPfolderSearch.next(); | |
scan = FSPfolder.getFilesByType("application/zip"); | |
while (scan.hasNext()) | |
{ | |
scan.next().setTrashed(true); | |
// how do i permanently delete | |
} | |
print("Cleaned the FSP cache folder. (trashed)"); | |
return die("<div>Cleaned the FSP cache folder. (trashed)</div>"); | |
} | |
//else | |
{ | |
console.error("The FSP cache folder does not exist."); | |
return die("<div>The FSP cache folder does not exist.</div>"); | |
} | |
} | |
var __I = e.parameter.id; | |
if (__I === undefined || __I === "" || __I === null) | |
{ | |
console.error("No file ID specified. Exiting."); | |
return die("<div>No file ID specified. Cancelling.</div>"); | |
} | |
log = ""; | |
var root, fileindex; | |
dir = false; | |
try | |
{ | |
root = DriveApp.getFolderById(__I); | |
fileindex = root.getFiles(); | |
dir = true; | |
} | |
catch | |
{ | |
try | |
{ | |
root = DriveApp.getFileById(__I); | |
dir = false; | |
} | |
catch | |
{ | |
console.error("Error while getting folder/file.\nDoes it exist?\nExiting."); | |
return die("<div>Error while getting folder/file.<br>Does it exist?<br>Exiting.</div>"); | |
} | |
} | |
if (root.getName().endsWith(".zip") || | |
root.getName().endsWith(".rar") || | |
root.getName().endsWith(".7z")) | |
{ | |
root = DriveApp.getFileById(__I); | |
dir = false; | |
} | |
var files = [], curfile; | |
var FSPfolderName = "Z.FGH3$TMP"; | |
var FSPfolderSearch = DriveApp.getFoldersByName(FSPfolderName), FSPfolder; | |
if (FSPfolderSearch.hasNext()) | |
{ | |
FSPfolder = FSPfolderSearch.next(); | |
} | |
else | |
FSPfolder = DriveApp.createFolder(FSPfolderName); | |
if (!dir) | |
{ | |
print("Archive file found."); | |
{ | |
//print(root.getId()); | |
if (root.getSharingPermission() != DriveApp.Permission.VIEW) | |
{ | |
print("ERROR: Insufficient access to file. Cancelling."); | |
return HtmlService.createHtmlOutput(html+"<div>"+log.replaceAll("\n","<br>")+"</div>"+htmlend); | |
} | |
print("PLAY!"); | |
htmlend += JS2OpenURL(cFGH3Link(root.getId())) | |
console.log("Run link: "+cFGH3Link(root.getId())) | |
return die("<div>"+log.replaceAll("\n","<br>")+"</div>"); | |
} | |
} | |
var zipHash = BigInt(0); | |
while (fileindex.hasNext()) | |
{ | |
curfile = fileindex.next(); | |
print("Getting file info for: "+curfile.getName()); | |
zipHash ^= WZK64(curfile.getId()) ^ WZK64(curfile.getLastUpdated().getTime().toString()); | |
files.unshift(curfile.getBlob()); | |
} | |
var zipHashStr = (zipHash.toString(16).toUpperCase().padStart(16,"0")); | |
var fname = "FSP"+zipHashStr+".fsp"; | |
var cacheSearch = FSPfolder.getFilesByName(fname); | |
while (cacheSearch.hasNext()) | |
{ | |
var cacheFile = cacheSearch.next(); | |
if (cacheFile.getName() == fname) | |
{ | |
print("Found cached ZIP."); | |
console.log(fname); | |
htmlend += JS2OpenURL(cFGH3Link(cacheFile.getId())) | |
console.log("Run link: "+cFGH3Link(cacheFile.getId())) | |
return die("<div>"+log.replaceAll("\n","<br>")+"</div>"); | |
} | |
} | |
{ | |
print("Creating ZIP."); | |
try { | |
var tmpfilec = Utilities.zip(files); | |
var tmpfile = DriveApp.createFile(tmpfilec), filename = fname; | |
tmpfile.moveTo(FSPfolder); | |
tmpfile.setName(filename); | |
tmpfile.setSharing(DriveApp.Access.ANYONE,DriveApp.Permission.VIEW); // just so the launcher can download it | |
} | |
catch (e) { | |
print("An error has occured while creating the ZIP."); | |
print(e); | |
return HtmlService.createHtmlOutput(html+"<div>"+log.replaceAll("\n","<br>")+"</div>"+htmlend); | |
} | |
} | |
print("PLAY!"); | |
htmlend += JS2OpenURL(cFGH3Link(tmpfile.getId())) | |
console.log("Run link: "+cFGH3Link(tmpfile.getId())) | |
return die("<div>"+log.replaceAll("\n","<br>")+"</div>"); | |
} | |
script in google apps scripts for transparency
still don't know how this looks to anyone else
https://script.google.com/d/1bBjZs0_LTRGX9L5kE1NdVCLFhuMxltTLfqZuyFvQlPacNwxtDjl-tqga/edit?usp=sharing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated for https://www.enchor.us/