foo_discord_rich
foo_discord_rich copied to clipboard
Allow artwork url as the large image
I've written some documentation about this feature (such as how to configure it) to https://s0hv.github.io/foo_discord_rich/docs/album-artwork. I also wrote a rust program for the upload process. The repository can be found here and installation instructions here.
For things not related to implementation details or problems in code such as installation problems, use the discussion forum on my repo as that's a better place to organize those discussions https://github.com/s0hv/foo_discord_rich/discussions. Also @JizzMasterBladee created a video tutorial on the installation process which you can find here https://www.youtube.com/watch?v=E-uq0WT2pwk
This PR tries to implement a simple way of using artwork in the discord status. I've implemented in a way that leaves the uploading of the file to the user in order to allow for flexibility as to where and how the uploading is done.
~Important features currently not implemented~ Should be fine now
- ~image hashes (to prevent uploading the same file multiple times)~ md5 hashes with urls stored in a json
- Calculating md5 hash should be quite simple
- Maybe behind an option in the config to toggle it on or off?
- Performance on large images?
- How to store the hash url combinations? (json?)
- ~Race condition prevention~ Implemented with a mutex
- ~Prevent trying to upload the same image multiple times~
- ~Would a global lock be sufficient for this, allowing only one upload at a time?~
- ~Error handling might not be perfect~might be ok
- Check that processes are not left open in case of an error
- ~UTF-8 support~ done
- ~User configurable metadb key~ done
- ~A sample script for uploading images~ https://github.com/s0hv/rust-imgur-upload
- Documentation to gh-pages
- https://github.com/s0hv/foo_discord_rich/tree/gh-pages
The path to the image upload command is set in Preferences -> Tools -> Discord Rich Presence Integration -> Advanced -> Artwork upload command
. A checkbox used to enable and disable this feature is also found in the advanced tab (disabled by default).
Would love to see this come to fruition.
Hey is it possible I could get a built version of this? The appveyor artifact expired a while ago and I have no clue how to compile this. Thanks!
@Elixcore Created a new release on my fork of the repo. https://github.com/s0hv/foo_discord_rich/releases/tag/1.3.0-beta You can download the build from there until this PR gets activity
@s0hv thanks a bunch! works perfectly!
two things:
how exactly do i set the uploading album art up from the new release? also, do you think it would be possible to enable the discord rich presence button feature?
@JizzMasterBladee I updated the PR description with a tiny bit more detailed instructions. The script itself still requires you to have python 3.7 or later installed with the requests library and an imgur API key. A windows batch script could also work, but UTF-8 support for that is more tricky.
As for the button feature, that is probably possible but not in the scope of this PR.
@s0hv im gonna be honest ive tried my best to follow the instructions but still have no result. is there any way i could add you on discord?
edit: seem to have figured it out by myself, thank you for the instructions though! :)
ANOTHER edit: if anybody is like me and sorta has no idea what to do, i made a really low quality but hopefully easy to follow tutorial https://youtu.be/E-uq0WT2pwk
couldn't you leverage winhttp for uploading instead of using a python script w/ requests? other than that, this seems pretty okay, though i'm a little scared of the char* caused weird random changes
comment somewhere in there lol
@sapphonie I'm not that familiar with the Windows API so I settled with something simple in terms of lines of code. Also that would require embedding the imgur API key which might create some problems (don't know what kind of ratelimits or other constraints they have). If you were wondering why I opted for a script instead of an embedded solution was for flexibility. I for example don't use imgur so it would lock me to only using that. Scripts also allow for more sophisticated solutions if you require those.
As for the char* random changes, the memory would randomly change during upload partially or completely changing the filename. Never figured out the exact reason for this but it happened after this line.
const auto md5 = static_api_ptr_t<hasher_md5>()->process_single(artwork.data->get_ptr(), artwork.data->get_size()).asString();
Might be some problem with album_art_data_ptr
causing that method to overwrite data.
I'd like to add that me, as an end-user, also prefer the custom script approach, as likewise I don't use Imgur either And modifying the module source directly (if it was baked in), as opposed to a simple python script, is much more of a pain to be honest
I've gone through all steps, even updated foobar2000 with all its plugins. I have downloaded Pyhton both from its official website and Microsoft Store. However the cover art still doesn't show in Discord. What is wrong?
@Gallus780 I created a discussion tab to my repository with a new discussion for this problem, as I don't think this PR is the correct place to talk about installation problems. You can find the discussion with my response there https://github.com/s0hv/foo_discord_rich/discussions/2. I also updated the PR description to guide others to the discussion forum instead of here for situations like this.
As the status of this PR has not really changed I started to write some of the documentation alongside a rust program that will handle the uploading to imgur with minimal user configuration. The documentation can be found here and the instructions for the rust program can also be found from the same page
Anything bout 64bit yet?
hey there, just wanted to drop by and say this component is awesome. i whipped together a script to upload to catbox.moe over imgur. perhaps this is more useful to people who don't want to sign up for an api key for imgur;
import requests
import sys
sys.stdin.reconfigure(encoding='utf-8')
filename = sys.stdin.read().strip()
with open(filename, 'rb') as f:
data = {
'reqtype': (None, 'fileupload'),
'userhash': (None, ''),
'fileToUpload': f
}
r = requests.post("https://catbox.moe/user/api.php", files=data)
if not r.ok:
print(r.text[:1000])
exit(1)
print(r.text, end='')
@mechabubba Thank you. I can add that script to the documentation if you create a gist of it.
@s0hv sure thing, posted it here: https://gist.github.com/mechabubba/db1200c05fbbecf753b23c92ee8e9271
with the original script i started having some issues with a mysterious error 259, which seemed to correspond to image size (seemed to struggle uploading anything past like 128kb?). i also posted an experimental script that sizes down and compresses the image to a reasonable size.
with some experimentation, i've had a lot more luck with this script than the original.
@mechabubba Thanks I'll add it the next time I edit the docs. Error 259 can be many different exceptions. By default exceptions get written to stderr which is not read by the plugin causing the error without error message. I updated my upload script and wrapped it inside a try except and an error printing function. You should probably wrap your script in a try except like this so it's easier to know what the error actually is instead of just a random error number.
I went ahead and made a script in Rust that uploads to catbox as well using curl. Repo is here and I built a release if you guys want to check it out
So far I want to do that and it won't let me. Can someone pass me the script?
@Markigagaxd
So far I want to do that and it won't let me. Can someone pass me the script?
The documentation at https://s0hv.github.io/foo_discord_rich/docs/album-artwork/ should have all of the necessary info and links
I've been looking at plugins for Discord RPC for foobar2000, and this seems like a really nice fork.
But one thing that bugs me is that I already have all my music tagged with MusicBrainz MBIDs. The upload strategy works well, but there is already the Cover Art Archive. Another similar project for MPD already uses this strategy, but I'm not sure how tags are exposed in foobar2000 so that you're able to grab the tag.
https://github.com/JakeStanger/mpd-discord-rpc here is the project for reference.
And https://github.com/JakeStanger/mpd-discord-rpc/blob/83cefa7ef522e0bf4f4f93bfb34a293474819f13/src/album_art.rs#L167 is the specific line; it is basically as easy as concatenating the MBID with the coverartarchive URL.
I might look into changing the code and adding this as an option in addition to the current upload strategy, but I hope it's something you think is interesting and would be fun to implement.
Thank you for your work :)
@nullobsi I think the smartest way to implement something like that would be to allow for title formatting in the command string. Then you could use something like script --param "%MUSICBRAINZ_ID%"
or whatever you need as the command and the title formatting would handle replacing the special strings. That would allow for maximum flexibility without introducing too specific features in this code. This does however require you to implement the actual script that returns the url. Also, I don't really know when I'd have time to implement and test something like this.
@Elixcore Created a new release on my fork of the repo. https://github.com/s0hv/foo_discord_rich/releases/tag/1.3.0-beta You can download the build from there until this PR gets activity
Is it possible to get the x64 version? I'd really like to try this out
Is it possible to get the x64 version? I'd really like to try this out
@bsdinis1 Here https://github.com/s0hv/foo_discord_rich/releases/tag/64-bit-prerelase
As the status of this PR has not really changed I started to write some of the documentation alongside a rust program that will handle the uploading to imgur with minimal user configuration. The documentation can be found here and the instructions for the rust program can also be found from the same page
Not sure if this is a Discord issue, or your upload script, or foo_discord_rich, but it is not working with .webp album art. Except for that, everything seems to work perfect.
Not sure if this is a Discord issue, or your upload script, or foo_discord_rich, but it is not working with .webp album art. Except for that, everything seems to work perfect.
@bsdinis1 Seems like imgur does not support webp https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-Is-there-a-size-limit- Catbox.moe which has upload scripts listed in the documentation seems to support webp though. Or you can create your own script for an image host you'd like to use.
just wanted to add this since i saw the imgur and catbox.moe version of the upload album python script so i decided to make my own for aws s3
import boto3
import sys
try:
sys.stdin.reconfigure(encoding='utf-8')
filename = sys.stdin.read().strip()
bucket = ''
directory = 'foobar2000/albums'
region = '' # example: us-east-1
access_key = ''
secret_access_key = ''
s3 = boto3.client(
's3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_access_key,
region_name=region,
)
s3.upload_file(filename, bucket, f'{directory}/{filename}')
print(f'https://s3.{region}.amazonaws.com/{bucket}/{directory}/{filename}')
except:
import traceback
traceback.print_exc(file=sys.stdout)
exit(1)
@okdargy I can add that to the list. Could you create a gist of the script so it is easier to link.
@okdargy I can add that to the list. Could you create a gist of the script so it is easier to link.
Sure, here: https://gist.github.com/okdargy/a55f40c7b339ee0a8b10a9827015453b