BLeeEZ / amperfy

Amperfy is an iOS app to play songs from an Ampache or Subsonic server
GNU General Public License v3.0
380 stars 34 forks source link

Make caching respect transcoding options #144

Closed lucat1 closed 2 days ago

lucat1 commented 1 year ago

I'll start by saying that Amperfy has been my daily driver for music reproduction for a few months and it has been way better than any other (free) alternative I've tried. Now onto my pet peeve with it. Amperfy doesn't have any transcoding options which is totally fine by me, I can apply these server-side. I suspect that is because the download method is used to cache songs in the background or after having played them once, which again is a feature i thoroughly enjoy. The issue is that by subsonic specification this method doesn't allow for transcoding and what happens is that I end up filling my phone's storage with cached items. The thing is I don't want to clean the cache because having media cached is a huge comfort, so I'm reaching out. I believe the quickest (and possibly only) solution is to use the stream method also in the caching section, possibly making this an optional feature.

BLeeEZ commented 1 year ago

The internal streaming mechanism is completely encapsulated in Apples Foundation framework AVPlayer which Amperfy uses to play and stream audio files. I can't get the raw streamed output to cache it for later use. This is why the download API function is used. The only approach i can offer you is to use an other sever. As mentioned here https://github.com/BLeeEZ/amperfy/issues/145 in Ampache you can select server side transcoding which is used for download (here the Ampache download API function is used which supports transcoding) too.

lucat1 commented 1 year ago

I’m afraid that changing server is not really a solution, as the Ampache implementation is a drift from the subsonic specification rather than a feature: therefore no client functionality should work assuming this option is available to everyone. I am still convinced that a quick fix is possible: the stream and download endpoints both return an audio stream with the latter being seekable via the Range headers. This should be the only meaningful difference between the two and therefore I believe the url could just be swapped for caching and everything should still work (albeit at a slower download rate accounting for transcoding overhead). I’d kindly ask you to give it a shot and report back. I cannot try this as I don’t have a macOS system on hand.

Let me know how if this works out

naezeroth commented 1 year ago

I am also seeing this issue on my side. I run a Navidrome server and I see when caching it downloads the original quality file which for me is FLAC vs the transcoding I've set up on my server for the Amperfy client (MP3).

pluskal commented 1 year ago

Hi guys, was there any progress or hotfix on this? I am using Navidrome with transcoding to mp3, which, as you report, is not activated for download. I am unable to force Amperfy not to cache.

  1. I delete cache; Amperfy shows 0 cached songs
  2. Disable Auto cached play songs.
  3. Play some songs I played before, and they did not start
  4. I use resync library, which resets Amperfy and enables Auto cached play songs.

Is there a way to omit cache and listen online using transcoding on a server?

EDIT: It seems that setting TranscodingCacheSize=0 on Navidrome hotfixes it.

JOJ0 commented 1 year ago

I am also seeing this issue on my side. I run a Navidrome server and I see when caching it downloads the original quality file which for me is FLAC vs the transcoding I've set up on my server for the Amperfy client (MP3).

I can reproduce exactly this behaviour on my Navidrome server. My container logs tell me that amperfy doesn't respect the servers setting that the registered client "amperfy" should transcode.

Here @BLeeEZ tells a reason why this is technically impossible: https://github.com/BLeeEZ/amperfy/issues/144#issuecomment-1206217305

I'm not sure how other clients like substreamer or play:sub do it but with them it works, transcoding works with playing but also with downloading as expected on my Navidrome server. For example flac files are transcoded to mp3, no matter if streamed or initially made available offline. This is the current configuration of all players ever registered in the Navidrome UI:

Screenshot 2023-05-25 at 08 52 28

I know, too much information, just want to give some context of how those clients look like when they register with Navidrome. Especially substreamer is interesting since it registeres and shows up differently often - that might be a bug in that app but I thought it might give some clue about what components are actually used in the background (sometimes shows up as ApplecoreMedia/iOS, whatever that means....)

Update: Whoops I see there is opus audio configured for amperfy, well that was an experiment, it still only downloads orginal (raw) format, i.e. flac files when hitting the download button...

JOJ0 commented 1 year ago

Not sure if all that helps at all but anyway. This is what Navidrome logs when I download a playlist in substreamer. One is an mp3 file already, the other is a flac. I tells that it is "streaming", even though I don't listen, it is actually just downloading:

INFO[24900] Streaming file                                artist=Deepside bitRate=0 cached=false format=raw originalBitRate=128 originalFormat=mp3 requestId=deluan-navidrome-dev1/R4gIMA5FuF-001971 title="Jack on the Groove" transcoding=false user=admin username=admin
INFO[24900] Streaming file                                artist=Klute bitRate=320 cached=false format=mp3 originalBitRate=925 originalFormat=flac requestId=deluan-navidrome-dev1/R4gIMA5FuF-001973 title=Tubby transcoding=true user=admin username=admin

When I click on the actual play button on a file that is definitely not cached, the log looks similar:

INFO[25380] Now Playing                                   artist="DJ Hype" player="substreamer [substreamer/iOS]" requestId=deluan-navidrome-dev1/R4gIMA5FuF-002065 title="Stomp ya Feet" user=admin username=admin
INFO[25380] Streaming file                                artist="DJ Hype" bitRate=0 cached=false format=raw originalBitRate=160 originalFormat=mp3 requestId=deluan-navidrome-dev1/R4gIMA5FuF-002066 title="Stomp ya Feet" transcoding=false user=admin username=admin
INFO[25380] Streaming file                                artist="DJ Hype" bitRate=0 cached=false format=raw originalBitRate=160 originalFormat=mp3 requestId=deluan-navidrome-dev1/R4gIMA5FuF-002068 title="Stomp ya Feet" transcoding=false user=admin username=admin
INFO[25390] Streaming file                                artist="DJ Hype" bitRate=0 cached=false format=raw originalBitRate=160 originalFormat=mp3 requestId=deluan-navidrome-dev1/R4gIMA5FuF-002069 title="Stomp ya Feet" transcoding=false user=admin username=admin
ecker00 commented 4 months ago

Seems related to #192 Controlling what format is downloaded from Navidrome server would be very handy. Also nice when it's possible for different format settings for offline-download and streaming.

BLeeEZ commented 2 months ago

Transcoding is now implemented: Simulator Screenshot - iPhone 15 Pro Max - 2024-04-22 at 21 03 21

lucat1 commented 2 months ago

@BLeeEZ Grat! Thank you so much! Will this be soon available on testflight?

BLeeEZ commented 2 months ago

It will take some time to collect more features for v1.2.1.

lucat1 commented 2 months ago

I'd be glad to try it out when a beta version comes out testflight.

BLeeEZ commented 3 weeks ago

This feature can be tested in the newest beta v1.2.1 (2): https://github.com/BLeeEZ/amperfy/issues/25

BLeeEZ commented 1 week ago

Did you have time test the feature? Is it behaving as you expected?

lucat1 commented 1 week ago

Yes, I double checked with the Navidrome logs and Amperfy is indeed using the transcoding option, both when streaming as well as when downloading for caching. The issue is solved IMO!