Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanner does not work with python3 on linux #505

Open
lowcarbdev opened this issue Dec 29, 2024 · 3 comments · Fixed by #506
Open

Scanner does not work with python3 on linux #505

lowcarbdev opened this issue Dec 29, 2024 · 3 comments · Fixed by #506

Comments

@lowcarbdev
Copy link
Contributor

The latest ASS does not work correctly on python3.

Platform

Operating system and version: Ubuntu 22.04 (jammy)
Plex version: 1.41.3.9314-a0bfb8370

Expected Behavior

After installing in the correct directory with the correct permissions, I should be able to select ASS as the scanner and create a new library.

Current Behavior

After installing into the correct directory with the correct permissions, plex is unable to use ASS as a scanner. It appears in the list, but I see the error message Your changes were not saved. upon trying to save the library.

Steps to Reproduce

  1. Install plex on Ubuntu 22.04 using the latest official plex deb
  2. Download ASS and copy the script to /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Scanners/Series/Absolute\ Series\ Scanner.py
  3. chown to plex:plex and chmod 775
  4. Note that ASS appears in the list but cannot be saved when creating a new library

Additional information

The problem is that the current ASS does not compile with python3. This is easily verifiable:

ubuntu@plex:~$ curl -O -L https://raw.githubusercontent.com/ZeroQI/Absolute-Series-Scanner/refs/heads/master/Scanners/Series/Absolute%20Series%20Scanner.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  110k  100  110k    0     0   352k      0 --:--:-- --:--:-- --:--:--  352k
ubuntu@plex:~$ python3 -m py_compile Absolute%20Series%20Scanner.py
  File "Absolute%20Series%20Scanner.py", line 86
    SOURCE_IDS             = cic(ur'[\[\{]((?P<source>(anidb(|[2-4])|tvdb(|[2-6])|tmdb|tsdb|imdb|mal|youtube(|[2-3])))-(?P<id>[^\[\]]*)|(?P<yt>(PL[^\[\]]{16}|PL[^\[\]]{32}|(UU|FL|LP|RD|UC|HC)[^\[\]]{22})))[\]\}]')
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax

To fix, replace regex strings starting with ur' with r'. The ur prefix is not allowed in python3 although u and r by themselves are ok. Once I did this in my local copy, ASS works as expected.

lowcarbdev added a commit to lowcarbdev/Absolute-Series-Scanner that referenced this issue Dec 30, 2024
@TransparentBeing
Copy link

TransparentBeing commented Jan 5, 2025

This change breaks all python2 installations. i.e. this has broke https://hub.docker.com/r/linuxserver/plex on version 1.41.3.9314

Please consider revert this PR.


Also, how did you run this script with python3? Which python version did you use? I might missed it but when did Plex started supporting python3?

Also, this script is full of py2 tricks, string syntax is not the only thing would break with py3. I'd be really surprised if you actually got this to work with a py3 installation.


@ZeroQI may want to take a look

@lowcarbdev
Copy link
Contributor Author

lowcarbdev commented Jan 6, 2025

@TransparentBeing Thanks for the report, this can be reverted if it has broken python2.

Regarding python3, I am running plex on an Ubuntu 22.04 (jammy) system that does not have python2 installed. I can't speak to when or if plex added explicit support, but the script appears to work for my use case (all I want is for plex to extract episode name metadata from filenames and that's what I'm getting).

To test python3 compatibility, I used the py_compile module to invoke bytecode compilation without running the script as shown above. I also ran 2to3 on the script and its almost exclusively removing the u prefix from strings, aka u"string" to "string". Technically u is optional in python3 so that's not an issue. There is existing python2/python3 handling in the script, so I figured python3 was already supported. What specifically do you think should break on python3 besides what I already fixed?

@ZeroQI ZeroQI reopened this Jan 6, 2025
@TransparentBeing
Copy link

AFAIK plex bundles it's own python (or at least for some server installations), so it may not matter if you have python2 installed via the package manager or not. It's highly likely you're running python2 under the hood unless you can find python3 specific error messages in logs. Please note this is just my speculation, as plex doesn't publish documentations. I suggest double checking logs in order to pin point why ASS did not work for you before this PR.

As for how things is not broken for you after this PR, removing u from regex will not break all case, as how u is suppose to work, it will only break in situations where unicode in involved.

I took a quick look at the script, it is just very far from compatible with python3. Just a few examples things WILL break with py3:

  • the usage of unicode type
  • compare None with bool types
  • code assumes zip filter, etc returns list type (they return iterators in py3)

Provided plex has been attempting to deprecate plugins support (like in this announcement for shield), I think it may not worth the effort migrating to python3 until the future of plugins support is clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants