def _add_rm_multi_tags(self, add, context, exaile): '''Add or remove tags from multiple tracks''' tracks = context['selected-tracks'] dialog = gt_widgets.GroupTaggerAddRemoveDialog(add, tracks, exaile) if add: dialog.tagger.set_categories([], get_group_categories()) else: groups = set() for track in tracks: groups |= get_track_groups(track) dialog.tagger.add_groups(groups) # TODO: something more dynamic dialog.set_size_request(250, 500) retval = dialog.run() groups = {} if retval == Gtk.ResponseType.APPLY: groups = set(dialog.get_active()) dialog.destroy() if len(groups) > 0: for track in tracks: existing = get_track_groups(track) if add: set_track_groups(track, existing | groups) else: set_track_groups(track, existing - groups)
def run(self): total = float(len(self.import_collection)) # to import, all essential fields should be identical! fields = [ '__length', 'artist', 'album', 'title', 'genre', 'tracknumber' ] logger.info("Finding matches for %s imported tracks" % len(self.import_collection)) exact_dups = 0 no_change = 0 # determine which tracks in this collection match existing # tracks in the exaile collection. grab the groups from them for i, track in enumerate(self.import_collection): # search for a matching track # -> currently exaile doesn't index tracks, and linear searches # for the track instead. Oh well. matchers = map(lambda t: TracksMatcher(track.get_tag_search(t)), fields) matched_tracks = [ r.track for r in search_tracks(self.user_collection, matchers) ] # if there are matches, add the data to the track data for matched_track in matched_tracks: # ignore exact duplicates if track is matched_track: exact_dups += 1 continue old_group_str = ' '.join(get_track_groups(matched_track)) newgroups = get_track_groups(track) new_group_str = ' '.join(newgroups) if old_group_str == new_group_str: no_change += 1 continue self.track_data.append( (old_group_str, new_group_str, matched_track, newgroups)) glib.idle_add(self.emit, 'progress-update', int(((i + 1) / total) * 100)) if self.do_stop: return logger.info( "Match information: %s exact dups, %s no change, %s differing tracks" % (exact_dups, no_change, len(self.track_data))) glib.idle_add(self.emit, 'done')
def track_import_thread(import_collection, user_collection, track_data): ''' Reads grouping information from tracks in a collection, and matches them with tracks contained in a separate collection. ''' total = float(len(import_collection)) # to import, all essential fields should be identical! fields = ['__length', 'artist', 'album', 'title', 'genre', 'tracknumber'] logger.info("Finding matches for %s imported tracks", len(import_collection)) exact_dups = 0 no_change = 0 # determine which tracks in this collection match existing # tracks in the exaile collection. grab the groups from them for i, track in enumerate(import_collection): # search for a matching track # -> currently exaile doesn't index tracks, and linear searches # for the track instead. Oh well. matchers = map(lambda t: TracksMatcher(track.get_tag_search(t)), fields) matched_tracks = [ r.track for r in search_tracks(user_collection, matchers) ] # if there are matches, add the data to the track data for matched_track in matched_tracks: # ignore exact duplicates if track is matched_track: exact_dups += 1 continue old_group_str = ' '.join(get_track_groups(matched_track)) newgroups = get_track_groups(track) new_group_str = ' '.join(newgroups) if old_group_str == new_group_str: no_change += 1 continue track_data.append( (old_group_str, new_group_str, matched_track, newgroups)) yield (i, total) logger.info( "Match information: %s exact dups, %s no change, %s differing tracks", exact_dups, no_change, len(track_data), )
def track_import_thread(import_collection, user_collection, track_data): ''' Reads grouping information from tracks in a collection, and matches them with tracks contained in a separate collection. ''' total = float(len(import_collection)) # to import, all essential fields should be identical! fields = ['__length', 'artist', 'album', 'title', 'genre', 'tracknumber'] logger.info("Finding matches for %s imported tracks", len(import_collection)) exact_dups = 0 no_change = 0 # determine which tracks in this collection match existing # tracks in the exaile collection. grab the groups from them for i, track in enumerate(import_collection): # search for a matching track # -> currently exaile doesn't index tracks, and linear searches # for the track instead. Oh well. matchers = map(lambda t: TracksMatcher(track.get_tag_search(t)), fields) matched_tracks = [r.track for r in search_tracks(user_collection, matchers)] # if there are matches, add the data to the track data for matched_track in matched_tracks: # ignore exact duplicates if track is matched_track: exact_dups += 1 continue old_group_str = ' '.join(get_track_groups(matched_track)) newgroups = get_track_groups(track) new_group_str = ' '.join(newgroups) if old_group_str == new_group_str: no_change += 1 continue track_data.append((old_group_str, new_group_str, matched_track, newgroups)) yield (i, total) logger.info( "Match information: %s exact dups, %s no change, %s differing tracks", exact_dups, no_change, len(track_data), )
def run(self): total = float(len(self.import_collection)) # to import, all essential fields should be identical! fields = ['__length', 'artist', 'album', 'title', 'genre', 'tracknumber'] logger.info("Finding matches for %s imported tracks" % len(self.import_collection)) exact_dups = 0 no_change = 0 # determine which tracks in this collection match existing # tracks in the exaile collection. grab the groups from them for i, track in enumerate(self.import_collection): # search for a matching track # -> currently exaile doesn't index tracks, and linear searches # for the track instead. Oh well. matchers = map(lambda t: TracksMatcher(track.get_tag_search(t)), fields) matched_tracks = [r.track for r in search_tracks(self.user_collection, matchers)] # if there are matches, add the data to the track data for matched_track in matched_tracks: # ignore exact duplicates if track is matched_track: exact_dups += 1 continue old_group_str = ' '.join(get_track_groups(matched_track)) newgroups = get_track_groups(track) new_group_str = ' '.join(newgroups) if old_group_str == new_group_str: no_change += 1 continue self.track_data.append((old_group_str, new_group_str, matched_track, newgroups)) glib.idle_add(self.emit, 'progress-update', int(((i+1)/total)*100)) if self.do_stop: return logger.info("Match information: %s exact dups, %s no change, %s differing tracks" % (exact_dups, no_change, len(self.track_data))) glib.idle_add(self.emit, 'done')
def on_playlist_context_select_custom_menu( self, menu, display_name, playlist_view, context, exaile ): '''Called when 'select tracks with similar tags (custom)' is selected''' tracks = context['selected-tracks'] groups = set() for track in tracks: groups |= get_track_groups(track) if len(groups) > 0: create_custom_search_playlist(groups, exaile) else: dialogs.error(None, _('No categorization tags found in selected tracks'))
def run(self): total = float(len(self.data)) for i, (curtrack, newgroups) in enumerate(self.data): if self.replace: set_track_groups(curtrack, newgroups) else: curgroups = get_track_groups(curtrack) | newgroups set_track_groups(curtrack, curgroups) glib.idle_add(self.emit, 'progress-update', int(((i+1)/total)*100)) if self.do_stop: return glib.idle_add(self.emit, 'done')
def set_display_track(self, track, force_update=False): '''Updates the display with the tags/info for a particular track''' if self.track == track and not force_update: return self.track = track # get the groups as a set track_groups = get_track_groups(track) # set them self.panel.tagger.view.show_click_column() self.panel.tagger.set_categories(track_groups, get_group_categories()) self.panel.tagger.set_track_info(track)
def track_update_thread(trackdata, replace): ''' Sets new groups on a set of tracks ''' total = len(trackdata) for i, (curtrack, newgroups) in enumerate(trackdata): if replace: set_track_groups(curtrack, newgroups) else: curgroups = get_track_groups(curtrack) | newgroups set_track_groups(curtrack, curgroups) yield (i, total)
def run(self): total = float(len(self.data)) for i, (curtrack, newgroups) in enumerate(self.data): if self.replace: set_track_groups(curtrack, newgroups) else: curgroups = get_track_groups(curtrack) | newgroups set_track_groups(curtrack, curgroups) glib.idle_add(self.emit, 'progress-update', int(((i + 1) / total) * 100)) if self.do_stop: return glib.idle_add(self.emit, 'done')
def export_tags(exaile): ''' Exports all tags to a user specified JSON file ''' uri = dialogs.save( parent=exaile.gui.main.window, output_fname='tags.json', output_setting='plugin/grouptagger/export_dir', title=_('Export tags to JSON'), extensions={'.json': 'grouptagger JSON export'}, ) if uri is not None: # collect the data trackdata = {} for strack in search.search_tracks_from_string(exaile.collection, ''): track = strack.track tags = list(sorted(get_track_groups(track))) if tags: trackdata[track.get_loc_for_io()] = tags data = { '_meta': { 'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'exporter': 'Exaile/%s' % exaile.get_version(), 'version': 1, }, 'tracks': trackdata, } # save it with GioFileOutputStream(Gio.File.new_for_uri(uri), 'w') as fp: json.dump(data, fp, sort_keys=True, indent=4, separators=(',', ': ')) logger.info("Exported tags of %s tracks to %s", len(trackdata), uri)