MatthiasLienhard / flowkey_dl

helper to create sheet music from flowkey songs
MIT License
70 stars 15 forks source link

Error after change in flowkey URL structure #30

Closed UriBarkan closed 9 months ago

UriBarkan commented 10 months ago

Hi Matthias,

First, thanks for the great work you are doing. It helps a lot to improve the learning experience while using the app.

Apparently FK changed the URL format again. I ran the following command in terminal: flowkey-dl-cli https://cdn.flowkey.com/rendered-sheets/mbwqgRR6Tt55akPKz/eb306a50/0@2x.png

(It's the "Everybody wants to rule the world" by Tears for Fears. Please judge me for my musical taste some other time:)

And got the following error:

downloaded 0 patches form https://cdn.flowkey.com/sheets/mbwqgRR6Tt55akPKz/300/{}.png Traceback (most recent call last): File "/home/user/venv/bin/flowkey-dl-cli", line 8, in sys.exit(main()) ^^^^^^ File "/home/user/venv/lib/python3.11/site-packages/flowkey_dl/flowkey_dlcli.py", line 31, in main image, , _ = flowkey_dl(args.baseurl) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/venv/lib/python3.11/site-packages/flowkey_dl/flowkey_dl.py", line 45, in flowkey_dl return np.hstack(imgs), None, None ^^^^^^^^^^^^^^^ File "<__array_function__ internals>", line 200, in hstack File "/home/user/venv/lib/python3.11/site-packages/numpy/core/shape_base.py", line 370, in hstack return _nx.concatenate(arrs, 1, dtype=dtype, casting=casting) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<__array_function__ internals>", line 200, in concatenate ValueError: need at least one array to concatenate

I think the problem is with strip_url and make_url functions. The pages are now turned with the index in bold in the last part 0@2x.png.

UriBarkan commented 10 months ago

Indeed, changing those two functions fix the problem:

def strip_url(url):
    parts = url.split("/")
    if len(parts) > 4:
        return parts[4] + "/" + parts[5]
    return ""

def make_url(hashstring, dpi=300):
    if dpi != 300:
        dpi = 150
    return f"https://cdn.flowkey.com/rendered-sheets/{hashstring}/" + "{}@2x.png"
MatthiasLienhard commented 10 months ago

Thank you for the suggestion. I currently do not have a subscription, so I cannot test your code. The free songs seem to use the old scheme. Could you please make a pull request?

MatthiasLienhard commented 9 months ago

OK, this should be fixed in 0.1.6, which is on PyPI now.