summaryrefslogtreecommitdiffstats
path: root/clerk_helper
diff options
context:
space:
mode:
authorRasmus Steinke <rasi@xssn.at>2015-04-29 00:47:23 +0200
committerRasmus Steinke <rasi@xssn.at>2015-04-29 00:47:23 +0200
commit25b12fab62d2a861438b67b247d1324f782afdf1 (patch)
tree838dca113baa021e8df097a3535f85924c6b2efa /clerk_helper
parent8637f513ca09678914b2da02e33ee1dfe5a4e7af (diff)
downloadperl-app-clerk-25b12fab62d2a861438b67b247d1324f782afdf1.tar.gz
perl-app-clerk-25b12fab62d2a861438b67b247d1324f782afdf1.tar.xz
import ratings from existing sticker database
Diffstat (limited to 'clerk_helper')
-rwxr-xr-xclerk_helper106
1 files changed, 41 insertions, 65 deletions
diff --git a/clerk_helper b/clerk_helper
index 719b7ee..335d3e1 100755
--- a/clerk_helper
+++ b/clerk_helper
@@ -287,6 +287,41 @@ def cleanRatings(args):
save_fastlistTrack(os.getenv('HOME')+'/.config/clerk/trackratings.json', prunedlist)
+def importTrackRatings(args):
+ client.clear()
+ list = client.sticker_find('song', "", 'rating')
+ rated_tracks = []
+ for i in list:
+ rating_temp = i['sticker']
+ rating = rating_temp.split('=')[1]
+ for x in client.find('file', i['file']):
+ artist = x['artist']
+ album = x['album']
+ track = x['track']
+ title = x['title']
+ entry = {'artist': artist, 'album': album, 'track': track, 'title': title, 'rating': rating}
+ rated_tracks.append(entry)
+ with open(os.getenv('HOME')+'/.config/clerk/trackratings.json', 'w') as ratingfile:
+ json.dump(rated_tracks, ratingfile)
+
+def importAlbumRatings(args):
+ client.clear()
+ list = client.sticker_find('song', "", 'albumrating')
+ rated_tracks = []
+ for i in list:
+ rating_temp = i['sticker']
+ rating = rating_temp.split('=')[1]
+ for x in client.find('file', i['file']):
+ artist = x['albumartist']
+ album = x['album']
+ date = x['date']
+ entry = {'albumartist': artist, 'album': album, 'date': date, 'rating': rating}
+ rated_tracks.append(entry)
+ with open(os.getenv('HOME')+'/.config/clerk/albumratings.json', 'w') as ratingfile:
+ json.dump(rated_tracks, ratingfile)
+
+
+
def readComments(args):
args = vars(args)
@@ -299,71 +334,6 @@ def prioSong(args):
client.prio(255, line)
-def restoreTrackRating(args):
- client.clear()
- matches = []
- for root, dirnames, filenames in os.walk(config['global']['music_path']):
- for filename in fnmatch.filter(filenames, 'track.ratings'):
- matches.append(os.path.join(root, filename))
- for song in matches:
- ratingfile = open(song, 'r')
- for line in ratingfile:
- tag = []
- tags = line.split(os.environ['separator'])
- for x in tags:
- if isinstance(x, list):
- tag.append(x[0].rstrip('\n'))
- else:
- tag.append(x)
- rating = tag[0]
- artist = tag[1]
- # track = tag[2]
- title = tag[3]
- date = tag[4]
- album = tag[5].rstrip('\n')
- filename = tag[6].rstrip('\n')
- if os.path.isfile(config['global']['music_path']+"/"+filename):
- client.sticker_set('song', filename, 'rating', rating)
- print("Imported song "+title+" with rating of "+rating)
- else:
- client.searchadd('artist', artist, 'album', album, 'title', title, 'date', date)
- for song in client.playlistinfo():
- if song['title'] in line and song['date'] in line and song['album'] in line:
- client.sticker_set('song', song['file'], 'rating', rating)
- print("Imported song "+song['title']+" with rating of "+rating)
-
-def restoreAlbumRating(args):
- matches = []
- for root, dirnames, filenames in os.walk(config['global']['music_path']):
- for filename in fnmatch.filter(filenames, 'album.rating'):
- matches.append(os.path.join(root, filename))
- for song in matches:
- ratingfile = open(song, 'r')
- for line in ratingfile:
- tag = []
- tags = line.split(os.environ['separator'])
- for x in tags:
- if isinstance(x, list):
- tag.append(x[0].rstrip('\n'))
- else:
- tag.append(x)
- rating = tag[0]
- artist = tag[1]
- # track = tag[2]
- title = tag[3]
- date = tag[4]
- album = tag[5].rstrip('\n')
- filename = tag[6].rstrip('\n')
- if os.path.isfile(config['global']['music_path']+"/"+filename):
- client.sticker_set('song', filename, 'albumrating', rating)
- print("Imported album "+album+" with rating of "+rating)
- else:
- client.searchadd('albumartist', artist, 'album', album, 'title', title, 'date', date)
- for song in client.playlistinfo():
- if song['title'] in line and song['date'] in line and song['album'] in line:
- client.sticker_set('song', song['file'], 'albumrating', rating)
- print("Imported album "+song['album']+" with rating of "+rating)
-
def savetoPlaylist(args):
for line in sys.stdin:
if line.strip():
@@ -414,6 +384,12 @@ parser_ratetrack.set_defaults(call=rateTrack)
parser_cleanratings = subparsers.add_parser('cleanratings', help="Clean up Ratings file.")
parser_cleanratings.set_defaults(call=cleanRatings)
+parser_importtrackratings = subparsers.add_parser('importtrackratings', help="Import track ratings from mpd stickers")
+parser_importtrackratings.set_defaults(call=importTrackRatings)
+
+parser_importalbumratings = subparsers.add_parser('importalbumratings', help="Import album ratings from mpd stickers")
+parser_importalbumratings.set_defaults(call=importAlbumRatings)
+
# parse arguments (thanks jat)
args = parser.parse_args()