def find_new_tracks(args, label='music', weight=1.5): """Finds new tracks by known artists, downloads and adds them.""" tracks = get_new_tracks(args, label=label, weight=weight) if is_verbose(): print 'New tracks: %u.' % len(tracks) added = 0 artist_names = [] for track in tracks: if is_verbose(): print "Track:", track logging.info((u'[%u/%u] fetching "%s" by %s' % (added + 1, len(tracks), track['title'], track['artist'])).encode("utf-8")) try: if track['artist'] not in artist_names: artist_names.append(track['artist']) filename = ardj.util.fetch(str(track['url']), suffix=track.get('suffix')) if not is_dry_run(): add_file(str(filename), add_labels=track.get('tags', ['tagme', 'music']), artist=track["artist"], title=track["title"], dlink=track['url']) added += 1 except KeyboardInterrupt: raise except Exception, e: logging.error((u"Could not download \"%s\" by %s: %s" % (track['title'], track['artist'], e)).encode("utf-8"))
try: if track['artist'] not in artist_names: artist_names.append(track['artist']) filename = ardj.util.fetch(str(track['url']), suffix=track.get('suffix')) if not is_dry_run(): add_file(str(filename), add_labels=track.get('tags', ['tagme', 'music']), artist=track["artist"], title=track["title"], dlink=track['url']) added += 1 except KeyboardInterrupt: raise except Exception, e: logging.error((u"Could not download \"%s\" by %s: %s" % (track['title'], track['artist'], e)).encode("utf-8")) if added: logging.info('Total catch: %u tracks.' % added) if not is_dry_run(): ardj.jabber.chat_say('Downloaded %u new tracks by %s.' % (added, ardj.util.shortlist(sorted(artist_names)))) db = ardj.database.Open() db.mark_recent_music() db.mark_orphans() mark_long() return added def schedule_download(artist, owner=None): """Schedules an artist for downloading from Last.fm or Jamendo.""" count = ardj.database.fetchone('SELECT COUNT (*) FROM tracks WHERE weight > 0 AND artist = ? COLLATE unicode', (artist, )) if count[0]: return u'Песни этого исполнителя уже есть. Новые песни загружаются автоматически в фоновом режиме.'