Iwaslazkis / browser-playerctl

:headphones: Implements MPRIS interface for chrome
1 stars 0 forks source link

Resize thumbnails so they maintain proper proportions #2

Open Iwaslazkis opened 2 years ago

Iwaslazkis commented 2 years ago

It seems most media control extensions I find on GNOME squish the artUrl Album Art into a square ratio. I'm assuming this doesn't have to do with MPRIS in any way,and is really just because conventionally music cover art is square shaped. Regardless of the reason however, I think these rectangular YouTube thumbnails look rather ugly squished, be nice to have them resized somehow, either letterboxed or cropped, such that the final image is still a square.

Iwaslazkis commented 2 years ago

So according to the MPRIS Specification found here, it seems that really Album Art is typically just passed around as some URI.

Perhaps this means one approach to solving this could be to donwload the image locally through the mpris python script and do image manipulation there, or do in-browser manipulation through a JS data blob and download that somewhere temporarily.

Iwaslazkis commented 2 years ago

The more simple solution might be however to just use some cheap (hopefully free) API that can resize our images given a URL. After searching around for a few hours, I did find img-resize.com offered entirely for free (and without any API keys) by Andy Chilton. The service is still up despite being seemingly a 8+ year old project, and the guy is still active in the linked twitter page. I'm going to hedge my bets that this is the best gets, and just hope the service doesn't go down too soon into the future.

Another alternative might be M3O, but they require an API key and say that their services will be free during the beta period, so I don't think this is would be a very permanent solution.

Iwaslazkis commented 2 years ago

img-resize.com takes in an image file as a binary sent as form-data in a POST request, and so it seems this might help: https://stackoverflow.com/questions/48447550/how-can-i-send-a-binary-data-blob-using-fetch-and-formdata

Iwaslazkis commented 2 years ago

So after some testing, it seems we run into CORS troubles when we try to access img-resize.com from YouTube, let alone an extension. I also later realized that the service directly outputs a the binary data in the response, so it's not like it'd be all that straightforward to convey that data through a normal URL to MPRIS.

Starting to think it might be easier to simply download the the right thumbnail locally through i.ytimg.com and do some processing through the python script, save to a file and pass that as a URI instead (as in, file:///path/to/temp-file) which gets deleted soon after usage. Nice thing about this approach is that we can convert them into png's and add proper transparency to them.