Target crosslang v0.0.11, add channel tags, descriptions and thumbnail downloading
Build and Deploy on Tag / 🔨 Build (push) Successful in 22s

This commit is contained in:
2026-09-30 04:03:51 -05:00
parent f73c45bb48
commit c993977e65
27 changed files with 331 additions and 90 deletions
+3 -3
View File
@@ -2,7 +2,7 @@
"info": {
"description": "Download YouTube Videos (using CrossLang)",
"maintainer": "Mike Nolan",
"repo":"https://onedev.site.tesses.net/tytd2025",
"repo":"https://git.tesses.org/tytd2025",
"homepage": "https://tesses.net/apps/tytd/2025/",
"type": "lib",
"license": "GPLv3-or-later"
@@ -14,6 +14,6 @@
}
],
"name": "Tesses.YouTubeDownloader",
"version": "1.0.1.0-dev",
"version": "1.0.2.0-dev",
"icon": "icon.png"
}
}
+4 -4
View File
@@ -20,10 +20,10 @@ class SubscriptionBell
{name="Disabled",value=SubscriptionBell.Disabled},
{name="Notify",value=SubscriptionBell.Bell},
{name="Notify and Download (Low)", value=SubscriptionBell.BellLow},
{name="Notify and Download (High)", value=SubscriptionBell.BellHigh},
{name="Download (Low)", value=SubscriptionBell.DownloadLow},
{name="Download (High)", value=SubscriptionBell.DownloadHigh}
// {name="Notify and Download (High)", value=SubscriptionBell.BellHigh},
{name="Download (Low)", value=SubscriptionBell.DownloadLow}
// ,{name="Download (High)", value=SubscriptionBell.DownloadHigh}
];
}
}
}
@@ -131,7 +131,7 @@ class TYTD.Downloader {
};
this.BeforeQueued.Invoke(this, ent);
if(ent.Cancel) {
this.LOG("Adding video canceled: {theVideoId}");
this.LOG($"Adding video canceled: {theVideoId}");
return;
}
}
@@ -199,6 +199,7 @@ class TYTD.Downloader {
if(cid != null)
{
DownloadChannelMetadataIfNotExists(cid);
const ent = {
Id = cid,
@@ -451,23 +452,30 @@ class TYTD.Downloader {
public GetChannelContents(id, offset, count)
{
id = TYTD.GetChannelId(id);
//title TEXT, description TEXT, tags TEXT
if(id == null) return {
authorName = "N/A",
description = "",
tags = [],
items = []
};
this.Mutex.Lock();
var db = this.OpenDB();
var authorName = "";
var description = "";
var tags = [];
var res = Sqlite.Exec(db, $"SELECT * FROM videos v WHERE (v.channelId = {Sqlite.Escape(id)}) LIMIT {count} OFFSET {offset*count};");
if(TypeOf(res) != "List" || res.Length == 0) {
var res2 = Sqlite.Exec(db,"SELECT * FROM channels c WHERE c.channelId = {Sqlite.Escape(id)};");
if(TypeOf(res2) == "List" && res2.Length > 0)
{
authorName = res2[0].title;
}
var res2 = Sqlite.Exec(db,$"SELECT * FROM channels c WHERE c.channelId = {Sqlite.Escape(id)};");
if(TypeOf(res2) == "List" && res2.Length > 0)
{
authorName = res2[0].title;
description = res2[0].description ?? "";
tags = Json.Decode(res2[0].tags ?? "[]") ?? [];
}
else {
else if(TypeOf(res) == "List" && res.Length > 0)
{
authorName = res[0].author;
}
Sqlite.Close(db);
@@ -489,6 +497,8 @@ class TYTD.Downloader {
}
return {
authorName,
description,
tags,
items = res
};
}
@@ -508,6 +518,12 @@ class TYTD.Downloader {
this.Mutex.Unlock();
if(TypeOf(res) != "List") throw res;
each(var item in res)
{
item.description ??= "";
item.tags = Json.Decode(item.tags ?? "[]");
}
return res;
}
@@ -811,11 +827,20 @@ class TYTD.Downloader {
if(TypeOf(res) == "List" && res.Count > 0) return res[0].bell;
return null;
}
public GetSubscriptions()
{
this.Mutex.Lock();
var db = this.OpenDB();
var res = Sqlite.Exec(db,"SELECT subscriptions.channelId, subscriptions.bell, channels.title FROM subscriptions INNER JOIN channels ON subscriptions.channelId = channels.channelId;");
Sqlite.Close(db);
this.Mutex.Unlock();
return res;
}
public GetSubscriptionUrls()
{
var cid = TYTD.GetChannelId(url);
if(cid == null) return [];
//Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS subscriptions (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId TEXT UNIQUE ON CONFLICT REPLACE, bell TEXT);");
this.Mutex.Lock();
var db = this.OpenDB();
@@ -951,6 +976,11 @@ class TYTD.Downloader {
{
var id = TYTD.GetChannelId(id);
if(id == null) return FS.ReadAllBytes(this.Storage,/"Streams"/"nullthumb.jpg");
const videoThumb = /"ChannelThumbnails"/id.Substring(0,4)/id.Substring(4) + ".jpg";
if(Storage.FileExists(videoThumb)) return FS.ReadAllBytes(Storage, videoThumb);
this.Mutex.Lock();
var db = this.OpenDB();
var _res = Sqlite.Exec(db,$"SELECT * FROM videos WHERE channelId = {Sqlite.Escape(id)} LIMIT 1;");
@@ -1075,6 +1105,7 @@ class TYTD.Downloader {
}
public Start()
{
this.Storage.CreateDirectory("ChannelThumbnails");
this.Storage.CreateDirectory(/"Streams");
this.Storage.CreateDirectory(/"Plugins");
if(!this.Storage.FileExists(/"Streams"/"nullthumb.jpg"))
@@ -1514,8 +1545,85 @@ class TYTD.Downloader {
var d = $"INSERT INTO videos (videoId,title,lengthSeconds,keywords,channelId,shortDescription,viewCount,author,addDate,tytdTag) VALUES ({Sqlite.Escape(info.videoId)},{Sqlite.Escape(info.title)},{info.lengthSeconds},{keywordsStr},{Sqlite.Escape(info.channelId)},{Sqlite.Escape(info.shortDescription)},{info.viewCount},{Sqlite.Escape(info.author)},{DateTime.NowEpoch},{Sqlite.Escape(this.TYTDTag)});";
Sqlite.Exec(db, d);
Sqlite.Exec(db, $"INSERT INTO channels (channelId,title) VALUES ({Sqlite.Escape(info.channelId)},{Sqlite.Escape(info.author)});");
Sqlite.Close(db);
this.Mutex.Unlock();
DownloadChannelMetadataIfNotExists(info.channelId);
}
private DownloadChannelMetadataIfNotExists(id)
{
this.Mutex.Lock();
var db = this.OpenDB();
const results=Sqlite.Exec(db, $"SELECT * FROM channels WHERE channelId = {Sqlite.Escape(id)};");
Sqlite.Close(db);
this.Mutex.Unlock();
if(TypeIsList(results) && results.Length > 0) return;
try {
const result = {Id = id ,Tags = [], Title = "", Thumbnail = "", Description=""};
const str= Net.Http.DownloadToString($"https://www.youtube.com/channel/{id}");
const html = Net.Http.ParseHtml(str);
const headers = html.FindNodes("meta");
each(var item in headers)
{
const content = item.Attributes["content"] ?? null;
const property = item.Attributes["property"] ?? null;
if(TypeIsString(content) && TypeIsString(property))
{
switch(property)
{
case "og:image":
result.Thumbnail = content;
break;
case "og:title":
result.Title = content;
break;
case "og:description":
result.Description = content;
break;
case "og:video:tag":
result.Tags.Add(content);
break;
}
}
}
PutChannelMetadataIfNotExists(result);
}catch(ex) {
try{
this.LOG($"Failed to get info on getting metadata for channel {ex}");
}catch(ex2){}
}
}
private PutChannelMetadataIfNotExists(metadata)
{
const videoThumb = /"ChannelThumbnails"/metadata.Id.Substring(0,4)/metadata.Id.Substring(4) + ".jpg";
if(!Storage.FileExists(videoThumb))
{
Storage.CreateDirectory(videoThumb.GetParent());
const resp = Net.Http.MakeRequest(metadata.Thumbnail,{FollowRedirects=true});
if(resp.StatusCode >= 200 && resp.StatusCode <= 299)
{
const strm=this.Storage.OpenFile(videoThumb,"wb");
resp.CopyToStream(strm);
strm.Close();
}
}
this.Mutex.Lock();
var db = this.OpenDB();
//CREATE TABLE IF NOT EXISTS channels (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId TEXT UNIQUE, title TEXT, description TEXT, tags TEXT);
Sqlite.Exec(db, $"INSERT INTO channels (channelId,title,description, tags) VALUES ({Sqlite.Escape(metadata.Id)}, {Sqlite.Escape(metadata.Title)}, {Sqlite.Escape(metadata.Description)}, {Sqlite.Escape(Json.Encode(metadata.Tags))});");
Sqlite.Close(db);
this.Mutex.Unlock();
}
@@ -1525,7 +1633,7 @@ class TYTD.Downloader {
var db = this.OpenDB();
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS videos (id INTEGER PRIMARY KEY AUTOINCREMENT, videoId TEXT UNIQUE, title TEXT, lengthSeconds INTEGER, keywords TEXT, channelId TEXT, shortDescription TEXT, viewCount INTEGER, author TEXT, addDate INTEGER, tytdTag TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS playlists (id INTEGER PRIMARY KEY AUTOINCREMENT, playlistId TEXT UNIQUE,channelId TEXT,channelTitle TEXT, title TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS channels (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId TEXT UNIQUE, title TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS channels (id INTEGER PRIMARY KEY AUTOINCREMENT, channelId TEXT UNIQUE, title TEXT, description TEXT, tags TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS playlist_entries (id INTEGER PRIMARY KEY AUTOINCREMENT, playlistId INTEGER, videoId TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS personal_lists (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, description TEXT);");
Sqlite.Exec(db,"CREATE TABLE IF NOT EXISTS personal_list_entries (id INTEGER PRIMARY KEY AUTOINCREMENT, listName TEXT, videoId TEXT);");
@@ -1578,34 +1686,7 @@ class TYTD.Downloader {
}
}
private DownloadChannelThumbInternal(channelId, thumbnail_url)
{
var id = TYTD.GetChannelId(channelId);
var path = /"ChannelThumbnails"/id.Substring(2,4)/id.Substring(6);
this.Storage.CreateDirectory(path.GetParent());
if(!(this.Storage.FileExists(path + ".webp") || this.Storage.FileExists(path+".jpg")))
{
if(thumbnail_url.StartsWith("//")) thumbnail_url = $"https:{thumbnail_url}";
var dl = Net.Http.MakeRequest(thumbnail_url);
if(dl.StatusCode >= 200 && dl.StatusCode <= 299)
{
var ct=dl.ResponseHeaders.TryGetFirst("Content-Type");
if(TypeOf(ct) == "String")
{
var s = ct.Split("; ",true,2);
var ext = ".jpg";
if(s[0] == "image/webp")
ext = ".webp";
var dest = this.Storage.OpenFile(path+ext,"wb");
dl.CopyToStream(dest);
dest.Close();
}
}
}
}
private DiscoverInternal(q,continuation,params)
{
if(continuation == undefined) var continuation = null;