Skip to content

Instantly share code, notes, and snippets.

@ciel
Forked from ThomasGaubert/playsong.py
Created February 17, 2019 13:20
Show Gist options
  • Save ciel/00c65e37f9e0894e39a808b8de42d77b to your computer and use it in GitHub Desktop.
Save ciel/00c65e37f9e0894e39a808b8de42d77b to your computer and use it in GitHub Desktop.

Revisions

  1. @TexasGamer TexasGamer revised this gist Feb 2, 2015. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion playsong.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    from gmusicapi import Webclient
    from gmusicapi import Mobileclient
    import vlc
    import urllib

    # Use Google account credintials. If two factor is enabled, use application specific password.
    email = '[email protected]'
    @@ -18,6 +19,8 @@
    web_client = Webclient()
    mobile_client = Mobileclient()

    p = vlc.MediaPlayer()

    print "Logging in..."

    logged_in = web_client.login(email, password)
    @@ -43,9 +46,12 @@
    song_name = song['track']['title']
    song_artist = song['track']['artist']
    stream_url = mobile_client.get_stream_url(song_id, device_id)

    # Uncomment to save most recent song
    # urllib.urlretrieve (stream_url, "mp3.mp3")

    print "Now Playing " + song_name + " by " + song_artist
    p = vlc.MediaPlayer(stream_url)
    p.set_mrl(stream_url)
    p.play()
    else:
    print "Invalid login credintials"
  2. @TexasGamer TexasGamer revised this gist Feb 2, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion playsong.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    from gmusicapi import Webclient
    from gmusicapi import Mobileclient
    import vlc
    import time

    # Use Google account credintials. If two factor is enabled, use application specific password.
    email = '[email protected]'
  3. @TexasGamer TexasGamer revised this gist Feb 2, 2015. 1 changed file with 9 additions and 11 deletions.
    20 changes: 9 additions & 11 deletions playsong.py
    Original file line number Diff line number Diff line change
    @@ -26,17 +26,16 @@

    # logged_in is True if login was successful
    if logged_in == True:
    while True:
    print "Successfully logged in"
    print "Successfully logged in"

    if device_id == '':
    devices = web_client.get_registered_devices()
    valid = [device['id'][2:] + " (" + device['model'] + ")" for device in devices
    if device['type'] == 'PHONE']
    print valid
    id_index = int(raw_input("Device ID: "))
    device_id = valid[id_index].split(' ', 1)[0]

    if device_id == '':
    devices = web_client.get_registered_devices()
    valid = [device['id'][2:] + " (" + device['model'] + ")" for device in devices if device['type'] == 'PHONE']
    print valid
    id_index = int(raw_input("Device ID: "))
    device_id = valid[id_index].split(' ', 1)[0]

    while True:
    song_name = raw_input("Song title: ")

    results = mobile_client.search_all_access(song_name, 1)
    @@ -49,6 +48,5 @@
    print "Now Playing " + song_name + " by " + song_artist
    p = vlc.MediaPlayer(stream_url)
    p.play()
    print p.get_state()
    else:
    print "Invalid login credintials"
  4. @TexasGamer TexasGamer revised this gist Feb 2, 2015. 1 changed file with 25 additions and 23 deletions.
    48 changes: 25 additions & 23 deletions playsong.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    from gmusicapi import Webclient
    from gmusicapi import Mobileclient
    import os
    import subprocess
    import vlc
    import time

    # Use Google account credintials. If two factor is enabled, use application specific password.
    email = '[email protected]'
    @@ -26,27 +26,29 @@

    # logged_in is True if login was successful
    if logged_in == True:
    print "Successfully logged in"
    while True:
    print "Successfully logged in"

    if device_id == '':
    devices = web_client.get_registered_devices()
    valid = [device['id'][2:] + " (" + device['model'] + ")" for device in devices
    if device['type'] == 'PHONE']
    print valid
    id_index = int(raw_input("Device ID: "))
    device_id = valid[id_index].split(' ', 1)[0]

    song_name = raw_input("Song title: ")

    results = mobile_client.search_all_access(song_name, 1)
    song = results['song_hits'][0]
    song_id = song['track']['nid']
    song_name = song['track']['title']
    song_artist = song['track']['artist']
    stream_url = mobile_client.get_stream_url(song_id, device_id)

    print "Now Playing " + song_name + " by " + song_artist
    subprocess.Popen(['open', '-a', "/Applications/VLC.app", stream_url])

    if device_id == '':
    devices = web_client.get_registered_devices()
    valid = [device['id'][2:] + " (" + device['model'] + ")" for device in devices
    if device['type'] == 'PHONE']
    print valid
    id_index = int(raw_input("Device ID: "))
    device_id = valid[id_index].split(' ', 1)[0]

    song_name = raw_input("Song title: ")

    results = mobile_client.search_all_access(song_name, 1)
    song = results['song_hits'][0]
    song_id = song['track']['nid']
    song_name = song['track']['title']
    song_artist = song['track']['artist']
    stream_url = mobile_client.get_stream_url(song_id, device_id)

    print "Now Playing " + song_name + " by " + song_artist
    p = vlc.MediaPlayer(stream_url)
    p.play()
    print p.get_state()
    else:
    print "Invalid login credintials"
  5. @TexasGamer TexasGamer created this gist Jan 30, 2015.
    52 changes: 52 additions & 0 deletions playsong.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    from gmusicapi import Webclient
    from gmusicapi import Mobileclient
    import os
    import subprocess

    # Use Google account credintials. If two factor is enabled, use application specific password.
    email = '[email protected]'
    password = 'password'

    # Device ID for API queries. Leave blank if unknown.
    device_id = ''

    if email == '':
    email = raw_input("Email: ")

    if password == '':
    password = raw_input("Password: ")

    web_client = Webclient()
    mobile_client = Mobileclient()

    print "Logging in..."

    logged_in = web_client.login(email, password)
    logged_in = mobile_client.login(email, password)

    # logged_in is True if login was successful
    if logged_in == True:
    print "Successfully logged in"

    if device_id == '':
    devices = web_client.get_registered_devices()
    valid = [device['id'][2:] + " (" + device['model'] + ")" for device in devices
    if device['type'] == 'PHONE']
    print valid
    id_index = int(raw_input("Device ID: "))
    device_id = valid[id_index].split(' ', 1)[0]

    song_name = raw_input("Song title: ")

    results = mobile_client.search_all_access(song_name, 1)
    song = results['song_hits'][0]
    song_id = song['track']['nid']
    song_name = song['track']['title']
    song_artist = song['track']['artist']
    stream_url = mobile_client.get_stream_url(song_id, device_id)

    print "Now Playing " + song_name + " by " + song_artist
    subprocess.Popen(['open', '-a', "/Applications/VLC.app", stream_url])

    else:
    print "Invalid login credintials"