def do_i_hate_this(cls, task, action_patterns): """Process group of patterns (warn or skip) and returns True if task is hated and not whitelisted. """ if action_patterns: for query_string in action_patterns: query = None if task.is_album: query = get_query(query_string, Album) else: query = get_query(query_string, Item) if any(query.match(item) for item in task.imported_items()): return True return False
def _items_for_query(lib, playlist, album=False): """Get the matching items for a playlist's configured queries. `album` indicates whether to process the item-level query or the album-level query (if any). """ key = 'album_query' if album else 'query' if key not in playlist: return [] # Parse quer(ies). If it's a list, join the queries with OR. query_strings = playlist[key] if not isinstance(query_strings, (list, tuple)): query_strings = [query_strings] model = library.Album if album else library.Item query = dbcore.OrQuery( [library.get_query(q, model) for q in query_strings] ) # Execute query, depending on type. if album: result = [] for album in lib.albums(query): result.extend(album.items()) return result else: return lib.items(query)
def mbsync_singletons(lib, query, move, pretend, write): """Synchronize matching singleton items. """ singletons_query = library.get_query(query, library.Item) singletons_query.subqueries.append( dbcore.query.BooleanQuery('singleton', True) ) for s in lib.items(singletons_query): if not s.mb_trackid: log.info(u'Skipping singleton {0}: has no mb_trackid' .format(s.title)) continue old_data = dict(s) # Get the MusicBrainz recording info. track_info = hooks.track_for_mbid(s.mb_trackid) if not track_info: log.info(u'Recording ID not found: {0}'.format(s.mb_trackid)) continue # Apply. with lib.transaction(): autotag.apply_item_metadata(s, track_info) _print_and_apply_changes(lib, s, old_data, move, pretend, write)
def parse_args(args, opts): # TODO use options instead of interspersed keywords subject = None table = 'items' count = DEFAULT_COUNT order = DEFAULT_ORDER subvals = [] if len(args) >= 1: if args[0].isdigit(): count = int(args[0]) args = args[1:] if len(args) >= 1: subject, args = SUBJECTS.get(args[0]), args[1:] template = TEMPLATES.get(subject) if len(args) >= 2 and args[0] == "by": args = args[1:] by, args = args[0], args[1:] order = ORDERS.get(by) template = TEMPLATES.get(by) if len(args) >= 2 and args[0] == "in": args = args[1:] table2, subvals2 = library.get_query(args).statement() table = '(' + table2 + ')' subvals += subvals2 if not subject or not order or not count: raise ui.UserError(u'invalid arguments') return { 'subject': subject, 'table': table, 'order': order, 'count': count, 'template': template, 'subvals': subvals }
def update_playlists(lib): ui.print_("Updating smart playlists...") playlists = config['smartplaylist']['playlists'].get(list) playlist_dir = config['smartplaylist']['playlist_dir'].as_filename() relative_to = config['smartplaylist']['relative_to'].get() if relative_to: relative_to = normpath(relative_to) for playlist in playlists: items = lib.items(library.get_query(playlist['query'], library.Item)) m3us = {} basename = playlist['name'].encode('utf8') # As we allow tags in the m3u names, we'll need to iterate through # the items and generate the correct m3u file names. for item in items: m3u_name = item.evaluate_template(basename, True) if not (m3u_name in m3us): m3us[m3u_name] = [] if relative_to: m3us[m3u_name].append(os.path.relpath(item.path, relative_to)) else: m3us[m3u_name].append(item.path) # Now iterate through the m3us that we need to generate for m3u in m3us: m3u_path = normpath(os.path.join(playlist_dir, m3u)) with open(syspath(m3u_path), 'w') as f: for path in m3us[m3u]: f.write(path + '\n') ui.print_("... Done")
def mbsync_singletons(lib, query, move, pretend, write): """Synchronize matching singleton items. """ singletons_query = library.get_query(query, library.Item) singletons_query.subqueries.append(library.SingletonQuery(True)) for s in lib.items(singletons_query): if not s.mb_trackid: log.info(u'Skipping singleton {0}: has no mb_trackid'.format( s.title)) continue old_data = dict(s) # Get the MusicBrainz recording info. track_info = hooks.track_for_mbid(s.mb_trackid) if not track_info: log.info(u'Recording ID not found: {0}'.format(s.mb_trackid)) continue # Apply. with lib.transaction(): autotag.apply_item_metadata(s, track_info) _print_and_apply_changes(lib, s, old_data, move, pretend, write)
def update_playlists(lib): ui.print_("Updating smart playlists...") playlists = config['smartplaylist']['playlists'].get(list) playlist_dir = config['smartplaylist']['playlist_dir'].as_filename() relative_to = config['smartplaylist']['relative_to'].get() if relative_to: relative_to = normpath(relative_to) for playlist in playlists: # Parse the query. If it's a list, join the queries with OR. query_strings = playlist['query'] if not isinstance(query_strings, (list, tuple)): query_strings = [query_strings] items = lib.items(dbcore.OrQuery( [library.get_query(q, library.Item) for q in query_strings] )) m3us = {} basename = playlist['name'].encode('utf8') # As we allow tags in the m3u names, we'll need to iterate through # the items and generate the correct m3u file names. for item in items: m3u_name = item.evaluate_template(basename, True) if not (m3u_name in m3us): m3us[m3u_name] = [] item_path = item.path if relative_to: item_path = os.path.relpath(item.path, relative_to) m3us[m3u_name].append(item_path) # Now iterate through the m3us that we need to generate for m3u in m3us: m3u_path = normpath(os.path.join(playlist_dir, m3u)) with open(syspath(m3u_path), 'w') as f: for path in m3us[m3u]: f.write(path + '\n') ui.print_("... Done")