acenko / FLACCue

FLAC with cuesheet support for Plex.
MIT License
54 stars 3 forks source link

need help to get this working #6

Closed Vertgear closed 3 years ago

Vertgear commented 3 years ago

Hello, I'm a complete greenhorn in the linux world, and I can't get this to work on my Synology, the spk file doesn't work for me. Thanks

acenko commented 3 years ago

At a guess, this is probably related to the dependencies. The spk file only installs the minimal code that runs the FUSE filesystem and doesn't automatically install the system level dependencies or Plex files. This all happened on my system as part of the development process and so it never occurred to me to look into automating this for the SPK. This would be worthwhile but I won't have the time to figure it out in the near future.

If you haven't already, you'll need to install "Python3" from the base Synology package library. You should also install "ffmpeg", which may require you to enable the SynoCommunity package repository.

Once those are done, you'll also need to install a few extra packages for Python. To do so, you'll need to enable ssh (or telnet) access to your Synology (see the Terminal & SNMP section of the Control Panel) and login in as an admin-capable user (if you're connecting from a Windows machine, you can use Putty for ssh--Mac and Linux systems should already have the ssh command available). You'll then need to run the following commands to install the needed Python packages:

  1. Change to the root user. Be very careful here as the root user has full permissions and the ability to break the OS: sudo -i
  2. Install pip: curl -k https://bootstrap.pypa.io/get-pip.py | python3
  3. Go to the directory pip is installed to: cd /volume1/@appstore/py3k/usr/local/bin
  4. Now install the needed packages: ./pip install ffmpeg-python ./pip install mutagen ./pip install numpy

After that, you'll also still need to drop the Scanner files in to your Plex directory. On my system, these end up in the "/Plex/Library/Application Support/Plex Media Server/Scanners/Music" folder. You may need to go to the Control Panel and edit the Shared Folder settings to enable your user to see the Plex folder.

Hope that helps get you started.

Vertgear commented 3 years ago

Hi thanks, for the reply. I have seemingly did everything you have listed, but the package still won't start, I'll try to provide meaningful screenshots below.

image

image I already have use those commands before, so that's why it says it's installed already

image

acenko commented 3 years ago

From those screenshots, it appears the package installs. A few other things to check:

  1. If you run ls /usr/bin/ | grep FLACCue, does anything show up?
  2. While logged in through ssh, do you see a flaccue folder listed when you run the ls / command?
  3. Assuming the folder exists, do you see anything in it if you run the ls /flaccue/ command? If files show up in there, the FLACCue service is running.
  4. If you try to create a Music library in Plex, do you see the FLAC Cue Scanner as an option under the Advanced settings Scanner field? If so, create a Music library with this Scanner and see if the files show up correctly.

If point 1 fails, somehow the initialization script didn't make the correct linkage for running the code. You'll need to find out where the package is installed and create a symlink. On my machine, it gets installed at /volume1/@appstore/FLACCue/usr/bin/FLACCue and so I would run ln -sf /volume1/\@appstore/FLACCue/usr/bin/FLACCue /usr/bin/ as the root user (sudo -i). The "\" before the @ symbol escapes it for the Linux prompt.

If point 2 fails, somehow the initialization scripts didn't create the necessary folder for the process. You'll need to create this manually as the root user (sudo -i):

mkdir /flaccue
chown plex:users /flaccue
chmod a+rwX /flaccue

If you do either of the above, try "Run" for the package in the Package Manager before going to point 3. Rebooting might also help but shouldn't be necessary.

If point 3 fails, run ps x -u plex and look for a line that includes python3 /bin/FLACCue / /flaccue/. If that's not running, try launching it manually. First try this as root and see if you get any errors (you should open a second ssh connection to check the /flaccue folder). If that works, use ctrl-c to exit and try running sudo --user=plex FLACCue / /flaccue/ and see if you get any errors.

If all of the above works and point 4 still fails, debugging becomes more complicated--this means everything up to the Plex layer is working and we'd need to figure out why Plex is not liking the setup. Let me know if you end up here and we can figure out some other things to try.

Hope that helps!

Vertgear commented 3 years ago

Point 1,2,3 failed, so I ran sudo -i ln -sf /volume1/\@appstore/FLACCue/usr/bin/FLACCue /usr/bin/ then ran

mkdir /flaccue
chown plex:users /flaccue
chmod a+rwX /flaccue

after that, the package started, and I could scan the library in plex using "FLAC Cue Scanner", and indeed it returned an album in split tracks, that was before in a single file, so whew, that finally works, thanks!

But after starting the scan, the plex activity for scanning pretty much got stuck. Had to restart my NAS because of it. image

Also, will the "FLAC Cue Scanner" also work on a library that has mixed music, both single flac file+cue, and normal flac tracks?

acenko commented 3 years ago

Yeah, it appears Synology took away root privileges for package installation in DSM 7. Good thing from a security standpoint but means my install scripts no longer work. Luckily the workaround isn't too complex right now.

With regards to the stuck scanning, it tends to be a resource intensive process. Scanning my library with the cue scanner actually took several days. I didn't spend too much time investigating as the scanning tends to be a one time issue, but any time Plex accesses a track from within a cue sheet I am decoding the whole track and caching it in memory on the server (freeing the memory after the track hasn't been accessed for 60 seconds). I'm not sure if this might be what you were seeing, but my code is a relatively crude solution to a problem that, as far as I could tell, requires a fix internal to Plex for an elegant option. If you continue to see this issue, try running the scan overnight and see if it makes more progress.

As far as mixed libraries, you shouldn't see issues. My part of the scanner effectively works by finding any .cue files, modifying the Plex entries for all tracks listed in .cue files (sending them to the FLACCue Python code with the appropriate start and end times for the track), and then removing any files referenced by the .cue file from the scan. Any files not mentioned in a .cue file (or only mentioned in a .cue file that fails to fully parse) are parsed by the standard Plex Music scanner (sadly, I couldn't find any way to use the premium scanner here). In the version in this repository, the full disc files are still accessible as disc 9999 in the album, although I personally disabled this at home so only the individual tracks show up (commenting out line 90 in flaccuelib.py--having both was nice on systems without gapless playback support but I found it slightly more annoying to have albums play twice). Also, while named "FLAC", this code should work for any type of music file ffmpeg understands referenced by a .cue file. While most of the album/artist information is pulled from the .cue header, multi disc album support is handled by including "Disc #" at the end of the .cue filename (e.g. "Pink Floyd - Pulse Disc 1.cue").

Let me know if you have any other questions.

Vertgear commented 3 years ago

I see, I will try to leave the scanning overnight and see what then.

Thanks for the tip about disc 9999, I will definitely use it as well.

Just one last question, when adding a new library to plex, which path do I choose? the new flaccue directory, so in my case /flaccue/volume2/HDD_NAS/Music ? and the Scanner is supposed to be "FLAC Cue Scanner" and not "flaccuelib", correct?

acenko commented 3 years ago

The scanner should be FLAC Cue Scanner.

In theory, you should be able to point to either folder structure but I recommend pointing Plex to the original directory (i.e., without the /flaccue/ at the start). This will cause any non-cue tracks to avoid any interactions with my code and keep .cue tracks from going through my code twice--this shouldn't have any effect in theory, but there is no expected benefit and the potential for unintended "features". Basically, my code mirrors the original file system (although as read-only) and should only introduce any changes for files named very specifically by my scanner code (basically, the .flac file with .flaccuesplit. and a start and stop time embedded in the "file" name).

Vertgear commented 3 years ago

After ~10hours, this is all it scanned, doesn't seem right. image

The album on the right is a are normal flac files, the album on the left is a Flac+Cue, but still being shows as a single track image

I'll attach the cue file of that album, idk, maybe there is something wrong there? COOL&CREATE - アゲアゲスパーク! .cue.txt

acenko commented 3 years ago

At a guess, this may be related to the Japanese characters. @nick4fake might understand this better, as he already submitted a fix for allowing UTF-8 in filenames, but the first thing to try would be a cue/flac combination only using Latin characters to isolate the failure. Do you have any cue/flac pairs using only Latin characters you could try this with? If you could put one or two of them in a separate folder and create a temporary Plex library pointing to that folder, we could see if the problem is with the package installation or just specific files. Or possibly copying and modifying the filename and cue sheet.

Vertgear commented 3 years ago

Ok, yeah, it works without a hiccup on a FLAC+CUE that doesn't contain Japanese characters.

acenko commented 3 years ago

If you change line 148 in flaccuelib.py (the first line of code in the read_cue function) to with open(file, 'r', encoding='utf8') as f: it might allow you to load the cue files into your library. Sadly, it doesn't seem to preserve the Japanese text. I'm not finding any documentation on easily loading the text correctly with a quick search--if we can the cue loaded correctly, the rest will hopefully fall in place. It shouldn't be a hard problem but I sadly don't have time to search for long right now.