Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Last active March 26, 2017 08:55
Show Gist options
  • Save utgwkk/58a009a49edcc7ea560f92aa721f5081 to your computer and use it in GitHub Desktop.
Save utgwkk/58a009a49edcc7ea560f92aa721f5081 to your computer and use it in GitHub Desktop.
Tweet #nowplaying of iTunes on Windows. Install pywin32 from https://sourceforge.net/projects/pywin32/ before using.
# coding: utf-8
import win32com.client
import webbrowser
from urllib.parse import quote
def get_itunes_client():
return win32com.client.Dispatch("iTunes.Application")
def build_nowplaying_text(client):
track = client.CurrentTrack
name = track.Name
artist = track.Artist
return "🎶 {} by {} #nowplaying".format(name, artist)
def main():
itunes = get_itunes_client()
text = build_nowplaying_text(itunes)
encoded = quote(text)
webbrowser.open('https://twitter.com/intent/tweet?text={}'.format(encoded))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment