canteen's blog

small recent programming projects

Preface

I found this in my drafts. I apparently wrote it 3 months ago. I'm just going to publish it, because it looks like it goes over some projects I wrote (back then it was recently).

Lil' projects

It has been a while since I made any posts about code, but I did do a bunch of coding recently! So I figured it describe them briefly here. Maybe they do things you like!

transcode

Why

I sometimes send my friends videos on platforms that want the size of those videos to stay under a specific barrier. At first it was fine to have an ffmpeg command in my command history and just adapting that every time, but the effort of pulling in the clip, compressing it just right (often having to fiddle with the encoder so it became small enough) and then hoping I didn't forget to check the audio codec kind of drove me nuts.

At the time I had also just found a package manager for python called rye. I was very excited to use it as it pulls in a given version of python specifically for that venv. This is perfect, because I've been using python for so long I've probably encountered every single python packaging solution there is. They all have a seriously irritating dependency on the system python install, and distributing it (even to yourself on the same machine a year later) generally means something has broken wherever it's used.

Given that this was a nice small project that just glued some stuff together this was a good moment to write some nice clean typed python with a package manager that actually works.

The little bits

yt-dlp

It fetches whatever you stick in there as a url using yt-dlp. It is a very cool project that does amazing things, but I found working with it a pain in the ass. Essentially nothing is typed, there are dictionaries everywhere and the documentation (even on the big entrypoint functions) is far from always correct (or perhaps I don't understand what it says).

That said, I would use it again. Once you get past the sort of rough introduction it's very reliable. This is very positive for actual usage.

simpleparsing

To parse cli arguments I like to stick everything in dataclasses. Doing this with argparse is singularly unpleasant, so I went looking for the simplest thing that turns cli arguments into dataclasses with a minimum of decoration and a maximum of doing what I want (parse into dataclasses and allow nesting).

SimpleParsing does that. You have to carefully ignore all the examples (which in my opinion stray very far from the light of god). Use

And make good use of fields and Union types to achieve what you want.

ffmpeg, but typed

Lastly I wanted a way to interact with ffmpeg that had good typing. That way I could be certain what I made works and it also lowered the frustration of working with ffmpeg, which is IMO a nightmare. There are a ton of options, but the docs are not very prescriptive so you end up having to go online to really figure out what the differences between different things are. This is a bad idea, because those forum discussions are full of lies and make believe and it can be a real challenge to figure out which is which if you don't already know the answer (and if you do you wouldn't be there).

Anyway, having it typed doesn't actually solve that. But it solves having to think about whether or not I'm putting the correct thing in the correct place. typed-ffmpeg does what you'd think it does and is good at it. While there are edge cases it doesn't cover (especially for I guess m

License

The repository doesn't have a license file. I will put an AGPL license file into it soon, like I do to most of my small projects.

https://git.sr.ht/~canteen/transcode

#code #computer