Giter Club home page Giter Club logo

Comments (42)

bexem avatar bexem commented on June 15, 2024 2

So I've fixed a couple of things and also added a total execution time to the script.
The only minor issue is that to get some useful information in the unraid web interface I need to use a field that it gets then duplicated when sending it via the Agents (in my case Discord)
image

But otherwise it works.
I will likely continue to work on it tomorrow (well... today)

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

I can add that, I will keep you posted!

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024 1

Yep, that did the trick. Now it works flawlessly! Thank you very much!

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

Unfortunately is how unraid handles the formatting when forwarding the notification to discord.
One alternative is to have each result as unique message, but then it would not be a summary anymore.

So I have now modified in a way that it's more coherent, have a look at the new script (be aware of your settings).

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

Apologies! It has been working fine so far but only now I noticed this mistake and actually started giving me the same error. It should be fixed now.

Regarding the onDeck media error, it seems to be an error with the token.
Try and re-run it, see if it still has the error, please send me the log. (Keep an eye for sensitive info)

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

Great! Please let me know of any errors or anything you would like to be implemented ☺️

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

Can the unraid ui notification Finished moving files with 0 errors. changed from a warning to a notice?

Done, just changed it, it was never meant to be a warning to be fair!

20 hours later still no errors. Looks like everything working ok. Does your script involve any measures to verify the file transfers complete without any file corruption?

I'm glad it is working fine!
The script doesn't implement any measure to verify the files, yet. It is a good idea and I will very likely add it.

I'm currently working on a rewrite of the whole script, separating each part so it will be easier to work on it, and one day might also expand the compatibility to jellyfin.

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

I'm closing this because it has been implemented and no errors have been encountered so far. ☺️

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024 1

pip install requests and plexapi fixed it. Thanks again. Next time new issue?

from plexcache.

bexem avatar bexem commented on June 15, 2024 1

Probably some plugin or unraid update must have removed the necessary modules...something I will need to keep in mind...

pip install requests and plexapi fixed it. Thanks again. Next time new issue?

Yes please, I was wondering where was your message at first because when I went on 'issues' there was only one open, but I did receive an email notification of your message πŸ˜…

from plexcache.

bexem avatar bexem commented on June 15, 2024

How are you running the script? Directly on unraid or are you using Chronos?

I did read your message earlier and I've been trying to integrate the functionality as I like the idea! Problem is I'm having issues using the notify command from Chronos, but if the script is run directly on unraid then it's a different deal and should be ready, it just needs to be tested.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Unraid through user scripts on a daily basis. I would gladly test it.

from plexcache.

bexem avatar bexem commented on June 15, 2024

Check the updated one, it should work, let me know.
https://github.com/bexem/PlexCache/blob/main/plexcache.py

Have a look at the variables inside, you will notice

notification = "unraid" # Unraid, Webhook or Both
unraid_level = "warning"  # Set the desired logging level for the notifications. Leave empty for notifications only on ERROR. (Options: debug, info, warning, error, critical)
webhook_level = ""  # Set the desired logging level for the notifications. Leave empty for notifications only on ERROR. (Options: debug, info, warning, error, critical)

webhook_url = ""  # Your webhook URL, leave empty for no notifications.
webhook_headers = {} # Leave empty for Discord, otherwise edit it accordingly. (Slack example: "Content-Type": "application/json" "Authorization": "Bearer YOUR_SLACK_TOKEN" })

Let me know if it works for you

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Notification works great. But, notification_level "info" just throws out every cached item. Can there be a flag for like a summary? Like the script outputs?

Total size of media files to be moved to array: 3.37 GB
Free space on the array: 38.62 TB
Moving media to array...
Moving media files to array...
Finished moving files with 0 errors.
Editing file paths...
Total size of media files to be moved to cache: 12.67 GB
Free space on the cache: 801.39 GB
Moving media to cache...
Moving media files to cache...
Finished moving files with 0 errors.
Thank you for using bexem's script: 

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Another thing: this is what the notification looks like:

2023-07-21_235001

from plexcache.

bexem avatar bexem commented on June 15, 2024

Done both (theoretically). https://github.com/bexem/PlexCache/blob/main/plexcache.py
The summary is still bare-bone but it's there.

Please let me know for any issues or further improvements.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Discord notifications work very well.

2023-07-22_074304

Unraid WebUI notifications still the same. They should just reflect the status of the script anyway. Like worked with 0 Errors or something like that, right?

from plexcache.

bexem avatar bexem commented on June 15, 2024

I'm not doing "It works on my end" because I want to understand why it doesn't on yours and fix it, but this how it show on my unraid (6.12.3)
image

Try on a unraid terminal to execute this?
/usr/local/emhttp/webGui/scripts/notify -e "Test" -s "Test2" -m "Test3" -d "Test4" -i normal

The script basically runs the exact same command:
notify_cmd = f'{self.notify_cmd_base} -e "PlexCache: Summary" -s "{record.name}" -m "{record.msg}" -d "{record.msg}" -i "{icon}"'

with "notify_cmd_base":
self.notify_cmd_base = "/usr/local/emhttp/webGui/scripts/notify"

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

the Webui:

2023-07-22_075739

discord

2023-07-22_075752

do you ever sleep? πŸ˜„

from plexcache.

bexem avatar bexem commented on June 15, 2024

I only work nights, I keep the schedule also during my days off. Although I'm about to go. 😴

So it works fine in your end too, but not when run by the script? That is just so odd, they are the same commands, I will need to investigate.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Ok, let me now if you want anything else tested. Good night!

from plexcache.

bexem avatar bexem commented on June 15, 2024

I can't say if it is fixed because I can't seem to be able to replicate the same behaviour, but I've changed a couple of things, let me know if it's any better.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

I tested the script with the unraid console and it works there. However, no notifications are sent. Neither to discord nor to Unraid UI. Furthermore, I get the following error when I run the script (I assume it's still this one: https://github.com/bexem/PlexCache/blob/main/plexcache.py) via Unraid User Scripts:

Script location: /tmp/user.scripts/tmpScripts/Plex Cache/script
Note/tmp/user.scripts/tmpScripts/Plex Cache/script: line 2: import: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 3: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 4: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 5: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 6: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 7: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 8: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 9: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 10: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 12: syntax error near unexpected token `"*** PlexCache ***"'
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 12: `print("*** PlexCache ***")'

from plexcache.

bexem avatar bexem commented on June 15, 2024

I tested the script with the unraid console and it works there. However, no notifications are sent. Neither to discord nor to Unraid UI. Furthermore, I get the following error when I run the script (I assume it's still this one: https://github.com/bexem/PlexCache/blob/main/plexcache.py) via Unraid User Scripts:

Script location: /tmp/user.scripts/tmpScripts/Plex Cache/script
Note/tmp/user.scripts/tmpScripts/Plex Cache/script: line 2: import: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 3: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 4: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 5: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 6: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 7: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 8: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 9: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 10: from: command not found
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 12: syntax error near unexpected token `"*** PlexCache ***"'
/tmp/user.scripts/tmpScripts/Plex Cache/script: line 12: `print("*** PlexCache ***")'

How are you trying to execute it in Unraid user Scripts?

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

add the script as user script and press the run script button.

from plexcache.

bexem avatar bexem commented on June 15, 2024

Uhm no, you need to execute the python scrpt from a script in user script.
See https://github.com/bexem/PlexCache/wiki/UserScripts#option-2-user-scripts-plugin

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Oh, yeah, ofc, that makes so much more sense...

from plexcache.

bexem avatar bexem commented on June 15, 2024

Yeah I know...As far as I know, user script can only run bash/sh scripts, but my project is done with python, so it needs to run through User Script rather than by User Script πŸ˜…

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

ok that makes more sense of course. However, the notifications still don't work. Neither Discord nor WebUI

from plexcache.

bexem avatar bexem commented on June 15, 2024

Can you show me how you have the script set?
image

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

uhh...oh..i have to confess... i haven't set webhooks up.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Ok. Now it's working. WebUi works great. But Discords notifications gets send twice.

2023-07-24_012247

from plexcache.

bexem avatar bexem commented on June 15, 2024

Set
Notification = "unraid"
or
Notification = "system"

The webhook is useful if you are running it on a system that doesn't use the same 'notify' service or for example, in Chronos as it cannot easily access and run the host executables.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

maybe a tiny little detail, but could the discord summary be formatted so each entry gets its own line?

this looks so clean and neat

2023-07-24_013749

this, not so much

2023-07-24_013833

I know its nitpicking....😁

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

It's beautiful! Thank you so much!

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Hi, me again. I really thought everything would be perfect with your script. Unfortunately, I get the following error messages via email:

Event: PlexCache
Subject: CRITICAL
Description: Error checking free space and moving media files to the array: name 'summary_message' is not defined
Importance: alert

Event: PlexCache
Subject: ERROR
Description: Error: Failed to Fetch one-of-my-users-username onDeck media. Error: (401) unauthorized; http://plex.ip.adress/ <html><head><script>window.location = window.location.href.match(/(^.+\/)[^\/]*$/)[1] + 'web/index.html';</script><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
Importance: alert

and last but not least:

Event: PlexCache
Subject: ERROR
Description: Failed to get access token for %s
Importance: alert

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

No Apologies needed! You doing great work. The script works so far without any errors. I ran it several times without any errors and will report back if any errors occur.

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

20 hours later still no errors. Looks like everything working ok. Does your script involve any measures to verify the file transfers complete without any file corruption?

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Can the unraid ui notification Finished moving files with 0 errors. changed from a warning to a notice?

from plexcache.

ezek1el avatar ezek1el commented on June 15, 2024

Hello, I wasn't sure if I should create a new ticket or just attach my problem here... I was wondering why I didn't get any more notifications and ran the script via console today. I get the following error:

File "/mnt/user/appdata/plexcache/plexcache.py", line 1, in
import os, json, logging, glob, socket, platform, shutil, ntpath, posixpath, re, requests, subprocess, time
ModuleNotFoundError: No module named 'requests'

from plexcache.

bexem avatar bexem commented on June 15, 2024

Have you tried installing the module again?
pip install requests

from plexcache.

bexem avatar bexem commented on June 15, 2024

A reboot apparently removes the modules. Keep it in mind.
I will probably will add a script to run a system reboot to install the necessary modules in the instruction, until a better solution comes up in my mind!

from plexcache.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.