Primeiramente gostaria de salientar que não sou o autor principal do conteúdo deste artigo. A minha intenção é de mostrar o que outros autores tem realizado (referenciando links para o conteúdo original) neste blog até como um guia pessoal para uso próprio e ainda compartilhar minhas anotações e pequenas modificações que realizo no conteúdo, desejando que possa ajudar mais alguém em algum lugar.
First and foremost, I take no credit for any of this post’s content. I am really just taking what others have done (which I have links to bellow) and am putting it on my blog for a personal reference and hopefully the small changes that I made to their guides will help someone somewhere.
link: https://gist.github.com/sebvance/060da84f55b13837b310#file-deletegmusicdupes-python35-py link: https://github.com/maxkirchoff/google-music-dupe-killer/blob/master/kill_dupes #!/usr/bin/env python3 from gmusicapi import Mobileclient import csv api = Mobileclient() # get an app password at https://security.google.com/settings/security/apppasswords logged_in = api.login('username', 'password', Mobileclient.FROM_MAC_ADDRESS) new_songs = {} old_songs = {} if logged_in: print('Getting all songs from Google ...') all_songs = api.get_all_songs() print('Getting all songs to music.csv ...') with open('musics.csv', 'w', newline='') as musicfile: trackwriter = csv.writer(musicfile, delimiter=',',quotechar='"', quoting=csv.QUOTE_ALL) trackwriter.writerow(['song_id', 'creationTimestamp', 'recentTimestamp', 'artist', 'album', 'discnum', 'tracknum', 'title', 'estimatedSize', 'durationMillis', 'playCount', 'deleted', 'dupkey']) for song in all_songs: dupkey = "%s - %s - %s" % ( song.get('artist').lower(), song.get('album').lower(), song.get('title').lower() ) timestamp = song.get('recentTimestamp') songid = song.get('id') trackwriter.writerow([songid, "'" + song.get('creationTimestamp'), "'" + timestamp, song.get('artist'), song.get('album'), song.get('discNumber'), song.get('trackNumber'), song.get('title'), song.get('estimatedSize'), song.get('durationMillis'), song.get('playCount'), song.get('deleted'), dupkey]) if dupkey in new_songs: if new_songs[dupkey]['timestamp'] < timestamp: old_songs[dupkey] = new_songs[dupkey] new_songs[dupkey] = { 'id': songid, 'timestamp': timestamp} else: old_songs[dupkey] = { 'id': songid, 'timestamp': timestamp} else: new_songs[dupkey] = { 'id': songid, 'timestamp': timestamp} print('Getting duplicated songs to music_dup.csv ...') with open('musics_dup.csv', 'w', newline='') as dupfile: trackwriter = csv.writer(dupfile, delimiter=',',quotechar='"', quoting=csv.QUOTE_ALL) trackwriter.writerow(['song_id', 'creationTimestamp', 'recentTimestamp', 'artist', 'album', 'discnum', 'tracknum', 'title', 'estimatedSize', 'durationMillis', 'playCount', 'deleted', 'dupkey']) for key in sorted( old_songs.keys() ): songid = old_songs[key]['id'] for track in all_songs: if track.get('id') == songid: song = track break dupkey = "%s - %s - %s" % ( song.get('artist').lower(), song.get('album').lower(), song.get('title').lower() ) trackwriter.writerow([songid, "'" + song.get('creationTimestamp'), "'" + song.get('recentTimestamp'), song.get('artist'), song.get('album'), song.get('discNumber'), song.get('trackNumber'), song.get('title'), song.get('estimatedSize'), song.get('durationMillis'), song.get('playCount'), song.get('deleted'), dupkey]) if len( old_songs ): print('Duplicated 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 ...') api.delete_songs( old_song_ids ) else: print('Finally. No duplicate songs.') #! /bin/bash initialfolder="/srv/media/Music/"; echo "Copying to Google Music. songs located at ${initialfolder} ..." function intosubdir() { local depth="${1}" local dir="${2}" if [[ ! " ${partial[@]} " =~ " ${dir} " ]]; then if [[ -d "${dir}" ]]; then # if is a folder for subdir in "${dir}"*/; do if [[ ! " ${partial[@]} " =~ " ${subdir} " ]]; then echo -n "Folder : ${subdir} ==> " case "${subdir%%/}" in "${dir}*") echo "has no subfolder ... " echo "gmupload -l -m -R ${dir%%/}" gmupload -l -m -R "${dir%%/}" ;; *) if [[ -d "${subdir%%/}" ]]; then # if is a folder if [ $depth -le 1 ] then echo "folder will be uploaded ... " echo "gmupload -l -m ${subdir%%/}" gmupload -l -m "${subdir%%/}" || true else echo "going into depth $[$depth-1]" intosubdir $[$depth-1] "${subdir}" fi else # if is a file echo "file will be uploaded ... " echo "gmupload -l -m ${subdir%%/}" gmupload -l -m "${subdir%%/}" || true fi ;; esac echo ${subdir/\*\/} >> /var/tmp/music.partial else echo "Folder : ${subdir} found at /var/tmp/music.partial, skipping ..." fi done echo ${dir/\*\/} >> /var/tmp/music.partial fi else echo "Folder : ${dir} found at /var/tmp/music.partial, skipping ..." fi } unset IFS declare -a partial if [ -f /var/tmp/music.partial ]; then echo "File partial found!" readarray -t partial < /var/tmp/music.partial fi intosubdir 7 "${initialfolder}" if [ -f /var/tmp/music.partial ]; then echo "Removing partial file ..." rm -f /var/tmp/music.partial fi #return exit 0 |