Exemplo n.º 1
0
def get_artist(lastfmcache: LastfmCache, artist: str):
    artist = LastfmCache.api_urldecode(artist)
    try:
        return jsonpickle.encode(lastfmcache.get_artist(artist),
                                 unpicklable=False)
    except LastfmCache.ArtistNotFoundError:
        return "Artist not found: '{0}'".format(artist), 404
Exemplo n.º 2
0
def init_lastfmcache(config: ConfigParser):
    lastfmcache = LastfmCache(config['lastfm']['api_key'],
                              config['lastfm']['shared_secret'])
    lastfmcache.enable_mysql_cache(config['mysql']['host'],
                                   config['mysql']['username'],
                                   config['mysql']['password'],
                                   config['mysql']['db'])
    return lastfmcache
Exemplo n.º 3
0
def get_release(lastfmcache: LastfmCache, artist: str, release: str):
    artist = LastfmCache.api_urldecode(artist)
    release = LastfmCache.api_urldecode(release)
    try:
        return jsonpickle.encode(lastfmcache.get_release(artist, release),
                                 unpicklable=False)
    except LastfmCache.ReleaseNotFoundError:
        return "Release not found: '{0}' by '{1}'".format(artist, release), 404
Exemplo n.º 4
0
def main():
    args = parse_args()

    src_folder = os.path.abspath(args.path)
    if not os.path.isdir(src_folder):
        raise ValueError("Invalid source folder: {0}".format(src_folder))

    dest_folder = None
    if args.move_fixed:
        dest_folder = os.path.abspath(src_folder)
    elif args.move_fixed_to:
        dest_folder = os.path.abspath(args.move_fixed_to)
        if not os.path.isdir(dest_folder):
            raise ValueError(
                "Invalid destination folder: {0}".format(dest_folder))

    invalid_folder = None
    if args.move_invalid:
        if args.move_invalid not in [v.value for v in ViolationType]:
            raise ValueError(
                "Invalid violation type '{0}', must be one of {1}".format(
                    args.move_invalid,
                    ", ".join([v.value for v in ViolationType])))
        if not args.move_invalid_to:
            raise ValueError(
                "--move-invalid must be accompanied by --move-invalid-to")
        invalid_folder = os.path.abspath(args.move_invalid_to)
        if not os.path.isdir(invalid_folder):
            raise ValueError(
                "Destination folder for invalid releases does not exist")

    duplicate_folder = None
    if args.move_duplicate_to:
        duplicate_folder = os.path.abspath(args.move_duplicate_to)
        if not os.path.isdir(duplicate_folder):
            raise ValueError(
                "Invalid duplicates folder: {0}".format(duplicate_folder))

    # guess group_by_category, if it was not set, using the contents of the destination folder
    if not args.group_by_category:
        args.group_by_category = guess_group_by_category(
            src_folder, dest_folder)

    if args.mode == "releases":
        list_releases(get_release_dirs(src_folder))

    elif args.mode in ["validate", "fix"]:
        lastfm = LastfmCache(lastfmcache_api_url=get_lastfmcache_api_url())
        lastfm.enable_file_cache(86400 * 365 * 5)

        validator = ReleaseValidator(lastfm)
        validator.disable_lastfm_track_title_validation()

        if args.expunge_comments_with_substring:
            validator.add_forbidden_comment_substring(
                args.expunge_comments_with_substring)

        if args.mode == "validate":
            validate_releases(validator, get_release_dirs(src_folder), args)

        elif args.mode == "fix":
            assemble_discs(get_release_dirs(src_folder), True)
            fix_releases(validator, get_release_dirs(src_folder), args,
                         dest_folder, invalid_folder, duplicate_folder)
Exemplo n.º 5
0
def crop_center(pil_img, crop_width, crop_height):
    img_width, img_height = pil_img.size
    return pil_img.crop(((img_width - crop_width) // 2,
                         (img_height - crop_height) // 2,
                         (img_width + crop_width) // 2,
                         (img_height + crop_height) // 2))

def crop_max_square(pil_img):
    return crop_center(pil_img, min(pil_img.size), min(pil_img.size))

with open("config.json", "r+") as f:
    config = json.load(f)

network = pylast.LastFMNetwork(api_key=config['apikey'], api_secret=config['secret'], username=config['username'], password_hash=pylast.md5(config['password']))
cache = LastfmCache(config['apikey'], config['secret'])
cache.enable_file_cache()


try:
    artists = network.get_authenticated_user().get_top_artists(limit=6, period=pylast.PERIOD_7DAYS)
except Exception as e:
    print(e)

artist_dict = {}

for a in artists:
    artist = cache.get_artist(a.item.name)
    artist_dict.update({ a.item.name : artist.cover_image })

for k, v in artist_dict.items():