Skip to content

Instantly share code, notes, and snippets.

@dewomser
Last active May 3, 2022 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dewomser/76ed3313c83674acc140b60f294364c4 to your computer and use it in GitHub Desktop.
Save dewomser/76ed3313c83674acc140b60f294364c4 to your computer and use it in GitHub Desktop.
Höre gerade und twittere mit Cover-Bildchen. Bashscript für KDE + Clementine Audioplayer
#!/bin/bash
#//config
user="twitteruser"
#//Musikinfo von Clementie Audioplayer holen
readarray a <<< "$(qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata | grep -E 'artUrl|genre|artist|album:|title:'| sed -e 's/xesam://g'| sed -e 's/mpris:artUrl: file:\/\///g')"
#//Bild kopieren
cp ${a[0]} $HOME/bin/twitter-pic/cover.jpg
# Daten an den Twitterclient
text="Ich höre gerade:${a[1]}${a[2]}${a[4]}"
#// Bildgröße in Byte ermitteln
byte=$(du -b cover.jpg | grep -Eo "^[0-9]+")
#// initialisieren
mis=$(twurl -u $user -H upload.twitter.com "/1.1/media/upload.json" -d "command=INIT&media_type=image/jpg&total_bytes=$byte" | jq .media_id_string)
mis="${mis:1: -1}"
#//hochladen
twurl -u $user -H upload.twitter.com "/1.1/media/upload.json" -d "command=APPEND&media_id=$mis&segment_index=0" --file cover.jpg --file-field "media" | jq .
#//finalisieren
twurl -u $user -H upload.twitter.com "/1.1/media/upload.json" -d "command=FINALIZE&media_id=$mis" | jq .
#//text hinzufügen
twurl -u $user "/1.1/statuses/update.json" -d "media_ids=$mis&status=$text"
@dewomser
Copy link
Author

Listen now and tweet Ein Bashscript zum vertwittern gerader gehörter Musik mit Coverbilchen.

Vorraussetzung:
Linux / KDE / Bash / Clementine Audioplayer / Twurl + jq / außerdem ein Twitter-Account
Twurl muss bei Twitter Autorisiert werden,

Ganz schön viel Vorraussetzungen !

@dewomser
Copy link
Author

dewomser commented May 3, 2022

Wird auf Github in einem eigenen repository weiterentwickelt:
https://github.com/dewomser/Tweet_and_toot_music_is_playing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment