Skip to content

Instantly share code, notes, and snippets.

@TKIPisalegacycipher
Forked from sckzw/README.md
Last active June 12, 2020 16:22
Show Gist options
  • Select an option

  • Save TKIPisalegacycipher/060da84f55b13837b310 to your computer and use it in GitHub Desktop.

Select an option

Save TKIPisalegacycipher/060da84f55b13837b310 to your computer and use it in GitHub Desktop.

Revisions

  1. TKIPisalegacycipher revised this gist Nov 22, 2016. 2 changed files with 60 additions and 48 deletions.
    60 changes: 60 additions & 0 deletions DeleteGmusicDupes-Python35.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/usr/bin/env python

    # created by shuichinet https://gist.github.com/shuichinet
    # forked from https://gist.github.com/shuichinet/8159878 21 Nov 2015
    # using minor edits by fcrimins https://www.reddit.com/user/fcrimins from https://www.reddit.com/r/google/comments/2xzgyv/remove_duplicate_songs_from_google_play_music/csh6mrh
    # also using clever edits by Morgan Gothard https://medium.com/@mgothard
    # updated for Python 3.5 by John M. Kuchta https://medium.com/@sebvance 22 Nov 2016 (hey I was busy)
    # compiled by John M. Kuchta https://medium.com/@sebvance
    # thanks to shuichinet, fcrimins and Mr. Gothard for their work

    from gmusicapi import Mobileclient
    from getpass import getpass

    client = Mobileclient()
    logged_in = client.login(input('Username:'), getpass(), Mobileclient.FROM_MAC_ADDRESS)

    print('Getting all songs ...')
    all_songs = client.get_all_songs()
    new_songs = {}
    old_songs = {}

    for song in all_songs:
    song_id = song.get('id')
    timestamp = song.get('recentTimestamp')

    if song.get('discNumber') is None:
    discnum = 0
    else:
    discnum = song.get('discNumber')

    if song.get('trackNumber') is None:
    tracknum = 0
    else:
    tracknum = song.get('trackNumber')

    key = "%s: %d-%02d %s" % ( song.get('album'), discnum, tracknum, song.get('title') )

    if key in new_songs:
    if new_songs[key]['timestamp'] < timestamp:
    old_songs[key] = new_songs[key]
    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }
    else:
    old_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    if len( old_songs ):
    print('Duplicate songs')

    old_song_ids = []

    for key in sorted( old_songs.keys() ):
    old_song_ids.append( old_songs[key]['id'] )
    print(' ' + str(key.encode('utf-8')))

    if input('Delete duplicate songs? (y, n): ') is 'y':
    print('Deleting songs ...')
    client.delete_songs( old_song_ids )
    else:
    print('Finally. No duplicate songs.')
    48 changes: 0 additions & 48 deletions DeleteGmusicDupes.py
    Original file line number Diff line number Diff line change
    @@ -1,48 +0,0 @@
    #!/usr/bin/env python

    # created by shuichinet https://gist.github.com/shuichinet
    # forked from https://gist.github.com/shuichinet/8159878 21 Nov 2015
    # using minor edits by fcrimins https://www.reddit.com/user/fcrimins from https://www.reddit.com/r/google/comments/2xzgyv/remove_duplicate_songs_from_google_play_music/csh6mrh
    # compiled by John M. Kuchta https://medium.com/@sebvance
    # thanks to shuichinet and fcrimins for their work

    from gmusicapi import Mobileclient
    from getpass import getpass

    client = Mobileclient()
    client.login( raw_input( "Username: " ), getpass(), Mobileclient.FROM_MAC_ADDRESS )

    print "Getting all songs ..."
    all_songs = client.get_all_songs()
    new_songs = {}
    old_songs = {}

    for song in all_songs:
    song_id = song.get('id')
    timestamp = song.get('recentTimestamp')

    key = "%s: %d-%02d %s" % ( song.get('album'), song.get('discNumber'), song.get('trackNumber'), song.get('title') )

    if key in new_songs:
    if new_songs[key]['timestamp'] < timestamp:
    old_songs[key] = new_songs[key]
    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }
    else:
    old_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    if len( old_songs ):
    print "Duplicate songs"

    old_song_ids = []

    for key in sorted( old_songs.keys() ):
    old_song_ids.append( old_songs[key]['id'] )
    print " " + key.encode('utf-8')

    if raw_input( "Delete duplicate songs? (y, n): ") is 'y':
    print "Deleting songs ..."
    client.delete_songs( old_song_ids )
    else:
    print "No duplicate songs"
  2. TKIPisalegacycipher renamed this gist Nov 22, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. TKIPisalegacycipher revised this gist Nov 22, 2015. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions gpm_cleaner.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,16 @@
    #!/usr/bin/env python

    # created by shuichinet https://gist.github.com/shuichinet
    # forked from https://gist.github.com/shuichinet/8159878 21 Nov 2015
    # using minor edits by fcrimins https://www.reddit.com/user/fcrimins from https://www.reddit.com/r/google/comments/2xzgyv/remove_duplicate_songs_from_google_play_music/csh6mrh
    # compiled by John M. Kuchta https://medium.com/@sebvance
    # thanks to shuichinet and fcrimins for their work

    from gmusicapi import Mobileclient
    from getpass import getpass

    client = Mobileclient()
    client.login( raw_input( "Username: " ), getpass() )
    client.login( raw_input( "Username: " ), getpass(), Mobileclient.FROM_MAC_ADDRESS )

    print "Getting all songs ..."
    all_songs = client.get_all_songs()
    @@ -39,4 +45,4 @@
    print "Deleting songs ..."
    client.delete_songs( old_song_ids )
    else:
    print "No duplicate songs"
    print "No duplicate songs"
  4. shuichi revised this gist Oct 19, 2014. 1 changed file with 2 additions and 9 deletions.
    11 changes: 2 additions & 9 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,4 @@
    Python script to delete duplicate tracks from Google Play Music library.
    Please retry until "No duplicate songs".
    Please retry until "No duplicate songs" message is displayed.
    Use this script at your own risk.
    gmusicapi is required.
    https://github.com/simon-weber/Unofficial-Google-Music-API

    Google Play Musicのライブラリから重複したトラックを削除するスクリプトです。
    重複ファイルは2つまでしか認識できないので、3つ以上重複している場合は繰り返し実行してください。
    自己責任での使用をお願いします。
    実行にはgmusicapiが必要です。
    https://github.com/simon-weber/Unofficial-Google-Music-API
    [gmusicapi](https://github.com/simon-weber/Unofficial-Google-Music-API "gmusicapi") is required.
  5. shuichi revised this gist Dec 28, 2013. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    Python script to delete duplicate tracks from Google Play Music library.
    Please retry until "No duplicate songs".
    Use this script at your own risk.
    gmusicapi is required.
    https://github.com/simon-weber/Unofficial-Google-Music-API

    Google Play Musicのライブラリから重複したトラックを削除するスクリプトです。
    重複ファイルは2つまでしか認識できないので、3つ以上重複している場合は繰り返し実行してください。
    自己責任での使用をお願いします。
    実行にはgmusicapiが必要です。
    https://github.com/simon-weber/Unofficial-Google-Music-API
  6. shuichi created this gist Dec 28, 2013.
    42 changes: 42 additions & 0 deletions gpm_cleaner.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/usr/bin/env python

    from gmusicapi import Mobileclient
    from getpass import getpass

    client = Mobileclient()
    client.login( raw_input( "Username: " ), getpass() )

    print "Getting all songs ..."
    all_songs = client.get_all_songs()
    new_songs = {}
    old_songs = {}

    for song in all_songs:
    song_id = song.get('id')
    timestamp = song.get('recentTimestamp')

    key = "%s: %d-%02d %s" % ( song.get('album'), song.get('discNumber'), song.get('trackNumber'), song.get('title') )

    if key in new_songs:
    if new_songs[key]['timestamp'] < timestamp:
    old_songs[key] = new_songs[key]
    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }
    else:
    old_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    new_songs[key] = { 'id': song_id, 'timestamp': timestamp }

    if len( old_songs ):
    print "Duplicate songs"

    old_song_ids = []

    for key in sorted( old_songs.keys() ):
    old_song_ids.append( old_songs[key]['id'] )
    print " " + key.encode('utf-8')

    if raw_input( "Delete duplicate songs? (y, n): ") is 'y':
    print "Deleting songs ..."
    client.delete_songs( old_song_ids )
    else:
    print "No duplicate songs"