Switch to CMake

This commit is contained in:
Mike Nolan 2023-05-10 06:18:40 -05:00
parent 47a8b61af0
commit 1f673f8620
3 changed files with 221 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/*
Nintendo Wii Example For TLang
Copyright (C) 2023 Tesses
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
func main()
{
console.writeln("App running");
console.writeln("Press A to get message, Press HOME to Exit");
wpad.init();
isRunning=true;
while(isRunning)
{
buttons = 0;
wpad.scanpads();
buttons = wpad.buttonsdown(0);
if(buttons & wpad.BUTTON_HOME)
{
isRunning = false;
}
if(buttons & wpad.BUTTON_A)
{
console.writeln("A Pressed");
}
}
}

70
examples/wii-tlrun.tlang Normal file
View File

@ -0,0 +1,70 @@
#!/usr/local/bin/tlang
//this is not finished
func relto(appfile,path)
{
f=fs.parent(getabs(appfile));
while(path.startsWith("../"))
{
path = path.substring(3);
f = fs.parent(f);
}
ret fs.combine(f,path);
}
func getabs(path)
{
d = path.split(":",false);
if(d.length == 2 && d[0].length == 1)
{
if(d[1].startsWith('\\') || d[1].startsWith('/'))
{
ret path;
}
}
else
{
if(path.startsWith('\\') || path.startsWith('/'))
{
ret path;
}else{
ret fs.combine(fs.working,path);
}
}
}
filesRead = create.array();
func contains(f)
{
each(filesRead)
{
if(item == f) ret true;
}
ret false;
}
__includeStr = "#include ";
func readFile(file)
{
if(contains(file)) ret "";
filesRead.add(file);
f = fs.readalltext(file).replace("\r","").split("\n",false);
myText = "";
each(f)
{
if(item.startsWith(__includeStr))
{
myText += readFile(relto(file,item.substring(__includeStr.length))) + "\n";
}
else
{
myText += item + "\n";
}
}
ret myText;
}
func main(src,$$args)
{
code=reflection.parse_code(readFile(src));
each(args) code.add(item);
code.run();
}

View File

@ -0,0 +1,109 @@
func stream_yt_json(id)
{
ret "{\"videoId\": \""+ id + "\",\"context\": {\"client\": {\"clientName\": \"ANDROID\",\"clientVersion\": \"17.10.35\",\"androidSdkVersion\": 30,\"hl\": \"en\",\"gl\": \"US\",\"utcOffsetMinutes\": 0}}}";
}
func tytd_streams_get(id)
{
streams = create.dict();
streams.success = false;
str = stream_yt_json(id);
curl = net.curl();
curl.method = "POST";
//curl.url = "http://127.0.0.1:9999/";
curl.url = "https://www.youtube.com/youtubei/v1/player?key=AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
jsonStr="";
curl.followlocation = true;
headers = create.array();
headers.add("Connection: close");
headers.add("Content-Type: application/json");
headers.add("User-Agent: com.google.android.youtube/17.10.35 (Linux; U; Android 12; GB) gzip");
headers.add("Cookie: CONSENT=YES+cb; YSC=DwKYllHNwuw");
curl.requestheaders = headers;
curl.postfields = str;
console.writeln(str);
curl.writefunction = func(buffer,length) {
for(i = 0;i<length;i++)
{
c=buffer[i].toChar();
d=c;
if(typeof(d) == "char")
{
jsonStr += d;
}
}
}
if(curl.perform() == 0)
{
streams.data = json.decode(jsonStr);
streams.success =true;
}
ret streams;
}
func tytd_title(id)
{
curl = net.curl();
curl.url = "https://www.youtube.com/watch?v=" + id;
htmlStr = "";
curl.followlocation = true;
curl.writefunction = func(buffer,length) {
for(i = 0;i<length;i++)
{
byte=buffer[i];
htmlStr += byte.toChar();
}
}
if(curl.perform() == 0)
{
a= htmlStr.split("<title>",false,2);
a2 = a[1];
a3 = a2.split("</title>",false,2);
ret a3[0];
}
ret "Unknown";
}
func download_video(id)
{
title = tytd_title(id);
console.writeln("Downloading: " + title);
strms=tytd_streams_get(id);
if(strms.success && strms.data)
{
each(strms.data.streamingData.formats)
{
if(item.itag == 22)
{
fileName = title + "-" + id + ".mp4";
curl = net.curl();
curl.url = item.url;
f = fs.create(fileName);
curl.writefunction = f.write;
curl.perform();
f.close();
console.writeln("Downloaded: " + title);
}
}
}
}
func main($$args)
{
each(args)
{
download_video(item);
}
}