bexem / PlexCache

Automate Plex media management: Efficiently transfer media from the On Deck/Watchlist to the cache, and seamlessly move watched media back to their respective locations.
58 stars 7 forks source link

Setup.py "no such file exists in directory" #12

Closed thedogmaniac closed 1 year ago

thedogmaniac commented 1 year ago

After I downloaded the plexapi and requests files with python, the cmd window says that the files dont exist. After checking manually in the folder, the files indeed don't exist.

bexem commented 1 year ago

"plexapi" and "requests" are libraries, they are not files that get downloaded in your folder that's why you can't find them. When installed via the "pip" command as explained in the instructions, any python software that requires them will be able to use them.

So theoretichally, you should be able to just run the setup.py (also plexcache.py).

thedogmaniac commented 1 year ago

Sorry, I'm not yet proficient with Python.So yeah, I downloaded the libraries through Python in my Command Window, but where is the directory that the script is located in? Because that's where I am stuck at the moment. I checked the directory that Python told me the "files" had downloaded to, but in that directory, running plexcache.py doesnt work.

Or what would the Syntax be with an example for a location in Windows?

Thanks in advance and sorry for the inconvenience. 

bexem commented 1 year ago

No problem at all! I'm here to help. When you download and install Python libraries using pip, they are stored in a specific directory that Python can access. This is usually within your Python installation folder. However, the plexcache.py script you are trying to run should be located in a different directory.

First, make sure you have downloaded the plexcache.py script and saved it in a folder of your choice. For example, you can create a folder named "PlexCache" on your desktop and save the script there.

To run the script, you will need to navigate to that folder using the command prompt. For example, if you saved it in a folder named "PlexCache" on your desktop, the command would look like this: cd C:\Users\YourUsername\Desktop\PlexCache Make sure to replace "YourUsername" with your actual username on your computer.

Once you are in the correct directory, you can run the script by typing: python plexcache.py

If you still encounter issues or have any questions, feel free to ask.

thedogmaniac commented 1 year ago

That worked partly, thanks! I forgot that I needed to download the files as a Zip from github. I just downloaded the libraries and that was it. That's why I couldn't find the files :D. Now I have the problem, after running the Setup.py, when I try to run the plexcache.py, it says "Script Folder not writable, fix variable accordingly". After looking at the code for the plexcache.py, I checked that everything was correct, the folder writing and reading permissions, that it wasn't in a folder on drive C which wasn't writable etc. So how do I fix this? Thanks in advance!

bexem commented 1 year ago

This error message indicates that the script is unable to write files to the specified directory due to insufficient permissions. Try to run the script as an administrator. To do this, press the Windows key, search for "cmd", right-click on the Command Prompt and select "Run as administrator". Then, navigate to the script's directory and run the script.

An alternative is to change folder permissions: Right-click on the folder in File Explorer, select "Properties", go to the "Security" tab, and click on "Edit". In the "Permissions" window, select your user account and make sure the "Allow" checkbox for "Full control" is checked. Click "Apply" and then "OK" to save the changes. (I'm kinda going by memory, so some names might have changed)

thedogmaniac commented 1 year ago

Well that's what I did. TLDR:

How do I set up the Permissions for Chronos Docker to write to mnt/system?

Admin CMD, checked Permissions for the folders, everything is Set-up correctly. And this is only on my Windows Desktop to test everything, I want to use it on Unraid. When I paste the code to my Chronos Docker, the same Output happens with Variable fix.... But for Unraid I wouldn't know how to set-up the permissions correctly. Maybe instead of trying to get it to work on my Desktop, maybe you could help me set it up on my Unraid Server?

bexem commented 1 year ago

So in windows, if you want to lunch the setup.py you might need to edit one thing in the script itself: script_folder = "./" Set it to script_folder = "." (If it works, I will update the script, I did not consider Windows different folder syntax) Or you can put directly the windows folder path, but if you have already done that, it should have already worked.

For unraid part instead: I assume you have set the script_folder="yourfolder/" in plexcache.py to the folder you want to use on unraid? For example script_folder="/mnt/user/system/PlexCache/"

Also, have you set the chronos container to have access to /mnt? (Add another Path, Port, Variable, Label or Device) Screenshot

thedogmaniac commented 1 year ago

In Unraid I set the Docker to have access to /mnt with the extra path yes. On windows I changed the script folder location to "D:\PlexCache" and the plexcache.py now starts. I'm now only getting an:

"Error connecting to the Plex server: HTTPSConnectionPool(host='plex.server.domain', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x0000023230BBDBA0>: Failed to resolve 'plex.server.domain' ([Errno 11001] getaddrinfo failed)"))"

On Unraid I have set the Script Folder loc. to "mnt/user/system/PlexCache/"

bexem commented 1 year ago

Did you change for privacy host='plex.server.domain' or is the actual message? If the latter, then your settings.json is not set properly somehow, as it needs to point to your plex server.

thedogmaniac commented 1 year ago

It is the actual message, I thought so, but how do I find out the address for my plex server?

bexem commented 1 year ago

Is the IP you have assigned to your plex server container if you are running it on unraid. In that case you would need to add :32400 to your IP address. So it will look like: http://192.168.44.4:32400 But in this case I strongly suggest to run the setup.py script on windows (making tha tlittle edit to the variable) so that it parses all the right info and set the settings.json file properly.

thedogmaniac commented 1 year ago

Did all that, now it's giving me an 401 unauthorized error...

bexem commented 1 year ago

So I suppose you also have the token set in the settings?

thedogmaniac commented 1 year ago

Damn.... I'm forgetting all the important first stuff. I am so sorry if I am wasting your time with this... I'll check on that.

thedogmaniac commented 1 year ago

It worked on Windows. The script executed correctly. Now I only need to fix it with Unraid.

bexem commented 1 year ago

No it's fine, honestly. It's just by the sound of it you haven't actually run the setup.py, because it asks you everything needed making sure it works before writing the settings.yaml You can also edit it manually but in your case I think the setup.py will actually make your life easier.

Update: That is great! So you just need to be sure that the script_folder is set properly, in your case to script_folder="/mnt/user/system/PlexCache/" (Careful with the slashes and making sure the folder exists and the settings.json is in there)

thedogmaniac commented 1 year ago

It worked. I had to create the folder in the system folder on my Server. Now how do I use Cron to create a trigger for the script? That's the last part of my equation.

bexem commented 1 year ago

https://ibb.co/WfX7htV https://ibb.co/YbCthpf https://ibb.co/ZY1Gg4t

Use this website to get the right syntax for cron: https://crontab.guru/

thedogmaniac commented 1 year ago

Ah so it triggers the script at specific times set by cron, which then transfers the Watchlist Media to the cache? At that specified time? And when I watched it, at the next Interval, the script runs, places the files back on the array and gets the next files? Or does it only copy the files?

thedogmaniac commented 1 year ago

And it is normal that the Cron Trigger doesn't show up in the trigger list?

bexem commented 1 year ago

Yes, you can make it run also every X amount of time as well (like hourly for example) not just at a specified time. If configured (again, in settings.json) to move the files back to the array, it will move the watched files back to the array from the cache. And it will also move the ondeck media from the array to the cache.

I guess yes if I intend your question correctly: https://ibb.co/Qn4K8dP

thedogmaniac commented 1 year ago

Now it shows up. I forgot to add spaces between the numbers. So everything is now working correctly I hope, am now just testing that it really moves the files in my Watchlist to the cache. After that everything should be working correctly and I should lastly fix the stupid scraper from Plex for specific Anime on my server.... I'll let you know if everything works correctly!

Okay so it doesn't move anything from my Array to the Cache. It says there is nothing to move even though I have a Show on my watchlist. Probably the "real source" in the settings.json I presume? Because it's set to mnt/user and my media location is /mnt/user/media/"Anime" for example.

And I'm tired, it's getting late, so I'll respond tommorrow!

bexem commented 1 year ago

Yes you should set real_source to /mnt/user/media/ And while you are testing, set the "watchlist_cache_expiry" to 0, so that I keep the cache watchlist file always updated, optimal in case of testing.

Let me know, happy to help :) Good night!

thedogmaniac commented 1 year ago

Hey there, I'm back! My Question lies with the Plex_source What should I put there? My biggest problem lies with the settings.json, I don't get some lines, what to put there etc. Maybe you could explain the settings.json? Thanks!

bexem commented 1 year ago

I will explain it but honestly, the setup would have made your life so much easier, that's why I've written it in the first place:

`{
    "PLEX_URL": "https://plex.server.domain",
    "PLEX_TOKEN": "ThisIsAFantasticToken",
    "plex_source": "/media/", 
# The root this mapped in your plex container which contains the libraries listed below, see picture.
    "plex_library_folders": [
        "movies",
        "anime",
        "tvseries"
    ], 
# The libraries/folders contained in the root folder above.
    "valid_sections": [
        1,
        4,
        2
    ], 
# This are the sections, aka libraries you want the script to fetch, to get the number just click on any of the libraries on your plex (like anime for example) and then look at the url, see second picture.
    "number_episodes": 10, 
# How manuy episodes do you want to fetch from the ondeck?
    "users_toggle": true, 
# Do you want to fetch ondeck media for other users?
    "skip_users": [], 
# Skip specific users
    "watchlist_toggle": false, 
# Do you want the watchlist media fetching?
    "watchlist_episodes": 5, 
# How many watchlist media?
    "watchlist_cache_expiry": 48, 
# The scripts create a file that caches the watchlist media (great when you have loads in there), this is the validity time, it's expressed in hours, passed that time, it will refetch everything from scratch.
    "days_to_monitor": 183, 
# Maximum age in days of the fetched media, starts from when you added to onDeck
    "watched_move": true, 
# Do you want to move watched media back to the array?
    "watched_cache_expiry": 336, 
# Same thins as the watchlist cache.
    "cache_dir": "/mnt/cache/", 
# Path of your cache, in your case might be /mnt/cache/media/
    "real_source": "/mnt/user/", 
# Path to your root folder containing the media, in your case /mnt/user/media/
    "nas_library_folders": [
        "movies",
        "anime",
        "tvseries"
    ], 
# This is basically like the plex source/libraries, in my case I use the exact same name, but other people might not.
    "unraid": true, 
# Are you on unraid? 
    "max_concurrent_moves_array": 2, 
# The scripts moves stuff in paralless, how many concurrent moves do you want? This is from cache to array.
    "max_concurrent_moves_cache": 5, 
# Same as above but from array to cache.
    "skip": true, 
# If someone is watching something on plex, do you want to interrupt the script entirely or just skip the playing media?
    "debug": true, 
# Debug option, when enabled it doesn't move files, it will only print in the output of the file (and log)
    "firststart": true 
# It checks if is the first time you run the script/setup, asking you edit the settings.
}`

Plex_source Sections/Libraries

thedogmaniac commented 1 year ago

Thanks!

I tried the setup, but as soon as I start it, it just finishes and that's it. There was nothing I could change in the cmd Window. I reset everything and now it works. That's why I hadn't set up everything correctly. I'll try the Setup.py now, seeing that its working, will let you know. Thanks anyway for the explained settings.json!

bexem commented 1 year ago

Thanks!

I tried the setup, but as soon as I start it, it just finishes and that's it. There was nothing I could change in the cmd Window. I reset everything and now it works. That's why I hadn't set up everything correctly. I'll try the Setup.py now, seeing that its working, will let you know. Thanks anyway for the explained settings.json!

No problem! I should spin up a VM with Windows I guess and fully test the setup in there, I didn't because python should be OS agnostic...but I ain't that lucky apparently! Let me know if you encounter any issues (and if not, so I can close the case), I'll be happy to help!

thedogmaniac commented 1 year ago

After using the setup.py and starting the plexcache.py, it just says that some things are missing in the settings.json. Used the setup.py multiple times, even with default values to test. Nothing works. It's as if it's getting worse by the day haha.

Update: Manually added the missing variables, that did the trick. Still a bit confused with the locations, because it still doesn't find anything to move, but I'll try further!

Where did you edit those Paths as shown in the Plex_Source screenshot? What Container is it?

bexem commented 1 year ago

That is odd, as I said I need to fully test it on windows, it works just fine on my linux and macos machines...

The container is Plex (linuxserver/plex - directly from the unraid app store)

thedogmaniac commented 1 year ago

I got further!

"Error: [Errno 2] No such file or directory: '/mnt/user/media/media/Anime/"

It put media 2 times in there, so I need to find out where I put the doubled value or where I need to change it.

UPDATE:

I got it to finally work.

bexem commented 1 year ago

Amazing! Trial and error always works! Is it finally fully working for you?

thedogmaniac commented 1 year ago

Yes it is! It's copying files and changing the file path. Just need to work out everything else, because I am primarily using Plex on Windows with a link to the server. But with this I could try to use plex on unraid. I have low specs but this is all in preparation for when I have new components in the server.

bexem commented 1 year ago

Plex doesn't really need that much power, if you are doing transcoding you "need" a GPU, an intel integrated GPU would work more than fine. I have the latter but I still rather avoid transcoding at all cost.

Let me know if I can stil be of any help!

thedogmaniac commented 1 year ago

Will do! It moved something that wasn't on my watchlist and also not on another users watchlist. And in Plex the Location of the File is still the old one. So need to check a few things, if it's okay with you I'd like to keep this Issue Open and if I get everything to work I'll let you know and you can close it?

bexem commented 1 year ago

Yes that's absolutely fine, I don't have any urge to close it, I shall do it only when I know it's all working fine for you :)

thedogmaniac commented 1 year ago

It will take some time, I am refreshing my whole library. So it's fine if I need a few days to let you know?

bexem commented 1 year ago

Yes, don't worry about it, take the time you need!

UPDATE: I've improved the setup script windows compatibility but it actually worked okay from the get go, it was not getting the plex_source correctly though!

thedogmaniac commented 1 year ago

Hey there,

so it seems to work for me now. Thanks for all your help! Just needed some time to update everything and optimize my server a bit. I'm still getting used to the paths thing in Unraid, overall the Docker thing is confusing me. But I'll learn it! So thanks again for your hard work on this program, it's amazing to see the things that people can create with code! I am still in an apprenticeship for programming, so I'm still not fluent in code. Java is pretty good, but I can always improve!

You can close the issue now!

bexem commented 1 year ago

I'm happy to know it works now! Don't hesitate to report any issue and/or suggestion in the future.

Sometimes docker still confuses me but it's a powerful tool! On unraid it farly easy to set up containers. But remember, everyone started at some point :)

Happy homelabbing!