aboutsummaryrefslogtreecommitdiffstats
path: root/sticker
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2025-03-25 20:06:31 +0200
committerTulir Asokan <tulir@maunium.net>2025-03-25 20:06:48 +0200
commit4b96d236212b1212976f4c3c60479e7aaed866cb (patch)
tree581805ef20edf5f84f9b2ece73ff408d234560b5 /sticker
parent3ce380645da442187d033656bd75350bb9e4b548 (diff)
Add sticker-download-thumbnails for adding thumbnails to an existing pack
Diffstat (limited to 'sticker')
-rw-r--r--sticker/download_thumbnails.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/sticker/download_thumbnails.py b/sticker/download_thumbnails.py
new file mode 100644
index 0000000..e082914
--- /dev/null
+++ b/sticker/download_thumbnails.py
@@ -0,0 +1,58 @@
+# maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
+# Copyright (C) 2025 Tulir Asokan
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+from pathlib import Path
+from typing import Dict
+import argparse
+import asyncio
+import json
+
+from aiohttp import ClientSession
+from yarl import URL
+
+from .lib import matrix, util
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--config",
+ help="Path to JSON file with Matrix homeserver and access_token",
+ type=str, default="config.json", metavar="file")
+parser.add_argument("path", help="Path to the sticker pack JSON file", type=str)
+
+
+async def main(args: argparse.Namespace) -> None:
+ await matrix.load_config(args.config)
+ with util.open_utf8(args.path) as pack_file:
+ pack = json.load(pack_file)
+ print(f"Loaded existing pack meta from {args.path}")
+
+ stickers_data: Dict[str, bytes] = {}
+ async with ClientSession() as sess:
+ for sticker in pack["stickers"]:
+ dl_url = URL(matrix.homeserver_url) / "_matrix/client/v1/media/download" / sticker["url"].removeprefix("mxc://")
+ print("Downloading", sticker["url"])
+ async with sess.get(dl_url, headers={"Authorization": f"Bearer {matrix.access_token}"}) as resp:
+ resp.raise_for_status()
+ stickers_data[sticker["url"]] = await resp.read()
+
+ print("All stickers downloaded, generating thumbnails...")
+ util.add_thumbnails(pack["stickers"], stickers_data, Path(args.path).parent)
+ print("Done!")
+
+def cmd():
+ asyncio.run(main(parser.parse_args()))
+
+
+if __name__ == "__main__":
+ cmd()
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage