Clean project.
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
||||
# Delete songs from Google Music that you deleted from iTunes
|
||||
# Delete unwanted songs from Google Music
|
||||
|
||||
Google Music Manager can automatically upload songs from your local iTunes library to Google Music. When you delete songs from you iTunes library, however, they remain to exist in you Google Music library. This script automates the tedious process of deleting songs from Google Music manually.
|
||||
Google Music Manager can automatically upload songs from your local iTunes library to Google Music. When you delete songs from you iTunes library, however, they remain to exist in you Google Music library. Two scripts automate the tedious process of deleting those (and duplicated) songs from Google Music manually.
|
||||
|
||||
## Installation
|
||||
This script relies on [pyItunes][1] and [Unofficial-Google-Music-API][2]. Installation of these dependencies is easy using pip:
|
||||
@@ -19,7 +19,11 @@ Generate an application specific password for your google account: https://secur
|
||||
|
||||
Just alter the values in broken brackets and run the script:
|
||||
```
|
||||
python delete.py
|
||||
python itunes.py
|
||||
```
|
||||
or
|
||||
```
|
||||
python duplicates.py
|
||||
```
|
||||
|
||||
[1]: https://github.com/liamks/pyitunes
|
||||
|
||||
55
duplicates.py
Normal file
55
duplicates.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/python
|
||||
# Copyright (c) 2014 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gmusicapi import Mobileclient
|
||||
|
||||
# Login
|
||||
api = Mobileclient()
|
||||
api.login('<account>', '<password>', Mobileclient.FROM_MAC_ADDRESS)
|
||||
|
||||
# Google Music songs
|
||||
print 'Getting all songs ...'
|
||||
all_songs = api.get_all_songs()
|
||||
new_songs = {}
|
||||
old_songs = {}
|
||||
|
||||
# Find duplicates
|
||||
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):
|
||||
# Display songs
|
||||
print 'Duplicate songs'
|
||||
delete = []
|
||||
for key in sorted(old_songs.keys()):
|
||||
delete.append(old_songs[key]['id'])
|
||||
print ' ' + key.encode('utf-8')
|
||||
|
||||
# Delete songs
|
||||
if raw_input( 'Delete duplicate songs? (y, n): ') is 'y':
|
||||
print 'Deleting songs...'
|
||||
api.delete_songs(delete)
|
||||
else:
|
||||
print 'No duplicate songs'
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/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"
|
||||
@@ -13,21 +13,34 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyItunes import *
|
||||
from gmusicapi import Mobileclient
|
||||
|
||||
# iTunes songs
|
||||
l = Library("<full path to iTunes Music Library.xml>")
|
||||
l = Library('<full path to iTunes Music Library.xml>')
|
||||
songs = [(song.artist, song.name) for id,song in l.songs.items()]
|
||||
|
||||
# Google Music songs
|
||||
api = Mobileclient()
|
||||
api.login('<account>', '<password>')
|
||||
api.login('<account>', '<password>', Mobileclient.FROM_MAC_ADDRESS)
|
||||
library = api.get_all_songs()
|
||||
|
||||
# Find songs to delete
|
||||
delete = filter(lambda song: (song['artist'], song['title']) not in songs, library)
|
||||
delete = [song['id'] for song in delete]
|
||||
|
||||
# Delete songs
|
||||
api.delete_songs(delete)
|
||||
if len(delete):
|
||||
# Display songs
|
||||
print "Duplicate songs"
|
||||
old_song_ids = []
|
||||
for key in sorted(delete):
|
||||
key = '%s: %d-%02d %s' % (song.get('album'), song.get('discNumber'), song.get('trackNumber'), song.get('title'))
|
||||
print " " + key.encode('utf-8')
|
||||
|
||||
# Delete songs
|
||||
if raw_input( "Delete duplicate songs? (y, n): ") is 'y':
|
||||
print "Deleting songs..."
|
||||
api.delete_songs(delete)
|
||||
else:
|
||||
print 'No deleted songs'
|
||||
Reference in New Issue
Block a user