Ejemplo n.º 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('-m', action='store_true')
    listsongs_p.add_argument('-p', action='store')
    listsongs_p.set_defaults(func=ls)

    show_p = subparsers.add_parser('show')
    show_p.add_argument('alias')
    show_p.add_argument('-m', action='store_true')
    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)

    removesongs_p = subparsers.add_parser('check')
    removesongs_p.set_defaults(func=check)

    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()
        write_cache('playlists', mpd.get_stored_playlists_info())
Ejemplo n.º 2
0
def lastfm_update_albums(args):
    albums_tags = lastfm.albums_tags
    missing_albums = sorted(mpd.list_albums(), key=itemgetter(1))
    if albums_tags:
        missing_albums = [album for album in missing_albums
                          if album not in albums_tags]
    info('Will fetch datas for %s missing album(s)' % len(missing_albums))
    for album, artist in missing_albums:
        print('Fetching %s / %s' % (artist, album))
        tags = lastfm.get_album_tags(album, artist, update=True)
        if tags is not None:
            albums_tags[(album, artist)] = tags
    write_cache('albums_tags', albums_tags)
Ejemplo n.º 3
0
def lastfm_update_artists(args):
    artists_tags = lastfm.artists_tags
    missing_artists = sorted(mpd.list_artists())
    if artists_tags:
        missing_artists = [artist for artist in missing_artists
                           if artist not in artists_tags]
    info('Will fetch datas for %s missing artist(s)' % len(missing_artists))
    for artist in missing_artists:
        print('Fetching %s' % artist)
        tags = lastfm.get_artist_tags(artist, update=True)
        if tags is not None:
            artists_tags[artist] = tags
    write_cache('artists_tags', artists_tags)
Ejemplo n.º 4
0
 def get_all_songs_tags(self, update=False):
     if self.all_songs_tags is not None and not update:
         pass
     elif is_cached('songs_tags') and not update:
         self.all_songs_tags = read_cache('songs_tags')
     else:
         self.all_songs_tags = OrderedDict()
         for song in self.mpdclient.listallinfo():
             if 'file' in song:
                 self.all_songs_tags[song['file']] = {
                     'artist': song.get('artist', ''),
                     'album': song.get('album', ''),
                     'title': song.get('title', ''),
                     'track': song.get('track', '')
                 }
         write_cache('songs_tags', self.all_songs_tags)
     return self.all_songs_tags
Ejemplo n.º 5
0
 def update_cache(self):
     write_cache('collections', self.collections)
Ejemplo n.º 6
0
try:
    open(config['mpdc']['collections'], 'r')
except IOError:
    warning('The collections file [%s] doesn\'t seem readable' %
            config['mpdc']['collections'])
    sys.exit(0)

from mpdc.libs.collectionsmanager import CollectionsManager
collectionsmanager = CollectionsManager(config['mpdc']['collections'])

update_collections = False

if (not is_cached('playlists') or read_cache('playlists') !=
    mpd.get_stored_playlists_info()):
    write_cache('playlists', mpd.get_stored_playlists_info())
    update_collections = True

if (update_collections or not is_cached('collections')
    or cache_last_modified('collections') <
    os.path.getmtime(config['mpdc']['collections'])):
    collectionsmanager.feed(force=True)
    collectionsmanager.update_cache()
else:
    collectionsmanager.feed()

collections = collectionsmanager.collections


# --------------------------------
# Lastfm initialization
Ejemplo n.º 7
0
def update(args):
    mpd.update_cache()
    write_cache('playlists', mpd.get_stored_playlists_info())
    collectionsmanager.feed(force=True)
    collectionsmanager.update_cache()