def update_songs_metadata(xml_target, songs_and_meta, args):
    """ Use metadata to update the information on the target database."""
    for song in xml_target.get_all_songs():
        key = xml_target.get_aat(song)
        if key in songs_and_meta:
            new_rating = songs_and_meta[key]['rating']
            old_rating = xml_target.get_rating(song)
            if old_rating is not None:
                old_rating.text = new_rating
            else:
                xml_target.add_rating(song, new_rating)
            new_playcount = songs_and_meta[key]['playcount']
            old_playcount = xml_target.get_playcount(song)
            if old_playcount is not None:
                if args.reset_playcounts or old_playcount.text is None:
                    old_playcount.text = new_playcount
                else:
                    old_playcount.text = str(int(old_playcount.text) + int(
                        new_playcount))
            else:
                xml_target.add_playcount(song, new_playcount)
