예제 #1
0
def main():
    argparser = argparse.ArgumentParser(add_help=False)
    subparsers = argparser.add_subparsers()

    listsongs_p = subparsers.add_parser("ls")
    listsongs_p.add_argument("collection", nargs="?")
    listsongs_p.add_argument("-f", nargs="?", const="")
    listsongs_p.add_argument("--p", action="store_true")
    listsongs_p.add_argument("--np", action="store_true")
    listsongs_p.set_defaults(func=ls)

    show_p = subparsers.add_parser("show")
    show_p.add_argument("alias")
    show_p.add_argument("-f", nargs="?", const="")
    show_p.set_defaults(func=show)

    find_p = subparsers.add_parser("find")
    find_p.add_argument("pattern")
    find_p.set_defaults(func=find)

    addsongs_p = subparsers.add_parser("addsongs")
    addsongs_p.add_argument("alias")
    addsongs_p.add_argument("collection")
    addsongs_p.set_defaults(func=add_songs)

    removesongs_p = subparsers.add_parser("rmsongs")
    removesongs_p.add_argument("alias")
    removesongs_p.add_argument("collection")
    removesongs_p.set_defaults(func=remove_songs)

    check_p = subparsers.add_parser("check")
    check_p.set_defaults(func=check)

    edit_p = subparsers.add_parser("edit")
    edit_p.set_defaults(func=edit)

    if len(sys.argv) == 1:
        cmd = input_box("mpdc-collections", "Command for mpdc-collections:")
        if cmd is None or not cmd:
            sys.exit(0)
        if cmd.startswith("addsongs") or cmd.startswith("rmsongs"):
            lex = shlex.shlex(cmd, posix=True)
            lex.whitespace_split = True
            lex.commenters = ""
            cmd = [next(lex), next(lex), lex.instream.read()]
        else:
            cmd = cmd.split(" ", 1)
        args = argparser.parse_args(cmd)
    else:
        args = argparser.parse_args()

    args.func(args)

    if collectionsmanager.need_update:
        collectionsmanager.write_file()
        collectionsmanager.update_cache()
        cache.write("playlists", mpd.get_stored_playlists_info())
예제 #2
0
def lastfm_update_tracks(args):
    known_tracks = set(lastfm.tracks_tags)
    all_tracks = set(mpd.list_tracks())
    #unneeded_tracks = known_tracks - all_tracks
    #for track in unneeded_tracks:
        #del lastfm.tracks_tags[album]
    missing_tracks = all_tracks - known_tracks
    info('{} missing track(s)'.format(len(missing_tracks)))
    for track, artist in missing_tracks:
        print('Fetching {} / {}'.format(artist, track))
        lastfm.tracks_tags[(track, artist)] = lastfm.get_track_tags(track,
                                                      artist, update=True)
    cache.write('lastfm_tracks_tags', lastfm.tracks_tags)
예제 #3
0
파일: mpdc_database.py 프로젝트: nhrx/mpdc
def lastfm_update_artists(args):
    tags = lastfm.artists_tags
    artists = sorted(mpd.list_artists())
    extra_artists = [artist for artist in tags if artist not in artists]
    info('{} extra artist(s)'.format(len(extra_artists)))
    for artist in extra_artists:
        del tags[artist]
    if tags:
        missing_artists = [artist for artist in artists if artist not in tags]
    else:
        missing_artists = artists
    info('{} missing artist(s)'.format(len(missing_artists)))
    for artist in missing_artists:
        print('Fetching {}'.format(artist))
        tags[artist] = lastfm.get_artist_tags(artist, update=True)
    cache.write('artists_tags', tags)
예제 #4
0
파일: mpdc_database.py 프로젝트: nhrx/mpdc
def lastfm_update_albums(args):
    tags = lastfm.albums_tags
    albums = sorted(mpd.list_albums(), key=operator.itemgetter(1))
    extra_albums = [album for album in tags if album not in albums]
    info('{} extra album(s)'.format(len(extra_albums)))
    for album in extra_albums:
        del tags[album]
    if tags:
        missing_albums = [album for album in albums if album not in tags]
    else:
        missing_albums = albums
    info('{} missing album(s)'.format(len(missing_albums)))
    for album, artist in missing_albums:
        print('Fetching {} / {}'.format(artist, album))
        tags[(album, artist)] = lastfm.get_album_tags(album,
                                                      artist, update=True)
    cache.write('albums_tags', tags)
예제 #5
0
파일: mpdhelper.py 프로젝트: nhrx/mpdc
 def get_all_songs_tags(self, update=False):
     if self.all_songs_tags is not None and not update:
         pass
     elif cache.exists('songs_tags') and not update:
         self.all_songs_tags = cache.read('songs_tags')
     else:
         self.all_songs_tags = collections.OrderedDict()
         for song in self.mpdclient.listallinfo():
             if 'file' in song:
                 self.all_songs_tags[song['file']] = {
                     'artist': self.clear_tag(song.get('artist', '')),
                     'albumartist': self.clear_tag(song.get('albumartist',
                                                   song.get('artist', ''))),
                     'album': self.clear_tag(song.get('album', '')),
                     'title': self.clear_tag(song.get('title', '')),
                     'track': self.clear_tag(song.get('track', ''))
                 }
         cache.write('songs_tags', self.all_songs_tags)
     return self.all_songs_tags
예제 #6
0
 def update_cache(self):
     cache.write('collections', self.collections)
예제 #7
0
파일: mpdc_database.py 프로젝트: nhrx/mpdc
def update(args):
    mpd.update_cache()
    cache.write('playlists', mpd.get_stored_playlists_info())
    collectionsmanager.feed(force=True)
    collectionsmanager.update_cache()
예제 #8
0
 def update(self):
     if self.need_update:
         self.write_file()
         self.update_cache()
         cache.write('playlists', mpd.get_stored_playlists_info())