MatthiasLienhard / flowkey_dl

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

patch N looks strange, ignoring: {patch} #22

Closed mircoianese closed 1 year ago

mircoianese commented 1 year ago

Hello,

I'm having issues with the script on both Ubuntu WSL (Windows) and Mac OS (M1). When trying to download the sheet I'm getting: (note that links are obfuscated)

flowkey-dl-cli https://flowkeycdn.com/sheets/XXXX/300/0.png

/Users/mirco/Library/Python/3.9/lib/python/site-packages/PIL/Image.py:992: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images
  warnings.warn(
loaded patch 0 with shape (344, 1024, 3)
patch 0 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 1 with shape (344, 1024, 3)
patch 1 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 2 with shape (344, 1024, 3)
patch 2 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 3 with shape (344, 1024, 3)
patch 3 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 4 with shape (344, 1024, 3)
patch 4 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 5 with shape (344, 1024, 3)
patch 5 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 6 with shape (344, 1024, 3)
patch 6 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 7 with shape (344, 1024, 3)
patch 7 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 8 with shape (344, 1024, 3)
patch 8 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 9 with shape (344, 1024, 3)
patch 9 looks strange, ignoring: {patch} 
shape: {patch.shape}
loaded patch 10 with shape (344, 341, 3)
patch 10 looks strange, ignoring: {patch} 
shape: {patch.shape}
downloaded 0 patches form https://flowkeycdn.com/sheets/XXXX/300/{}.png
Traceback (most recent call last):
  File "/Users/mirco/Library/Python/3.9/bin/flowkey-dl-cli", line 8, in <module>
    sys.exit(main())
  File "/Users/mirco/Library/Python/3.9/lib/python/site-packages/flowkey_dl/flowkey_dl_cli.py", line 31, in main
    image, _, _ = flowkey_dl(args.baseurl)
  File "/Users/mirco/Library/Python/3.9/lib/python/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 "/Users/mirco/Library/Python/3.9/lib/python/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

Thanks

mircoianese commented 1 year ago

Not sure if it's the correct solution, but after some troubleshooting I got it working by replacing this line:

patch = next(iter(imageio.get_reader(r.content, ".png")))

with:

patch = imageio.imread(r.content, format='png', pilmode="RGBA")

Not doing a pull request since I'm not sure about the solution (and why it works)

MatthiasLienhard commented 1 year ago

Just to be sure, does this happen on any sheet, or one particular only?

vvanwetten commented 1 year ago

Not sure if it's the correct solution, but after some troubleshooting I got it working by replacing this line:

patch = next(iter(imageio.get_reader(r.content, ".png")))

with:

patch = imageio.imread(r.content, format='png', pilmode="RGBA")

Not doing a pull request since I'm not sure about the solution (and why it works)

I have the same issue. It happens with every song I try. The fix you mentioned (THANK YOU!) also works for me, and my (very) limited python skills.

Deuto commented 1 year ago

Just to be sure, does this happen on any sheet, or one particular only?

I had the same issue. Fix works! As far as i can tell, the original code results in pure white images with just three channels.

MatthiasLienhard commented 1 year ago

OK it is probably related to the imageio backend, however I did not do exhaustive testing, as the fix you suggested works for me, and is also much more elegant. I included it and also put it on pyPI. Thanks a lot.