Last active
March 26, 2017 08:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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