barbequesauce / Watcher3

Fork of nosmokingbandit/Watcher3 as the original seems inactive. PRs welcome, support is community based.
Other
69 stars 19 forks source link

Recently Finished section. #169

Closed GTunney closed 4 years ago

GTunney commented 4 years ago

Feature Request

Ive just recently switched from CouchPotato, I used email notifications in Couch to find out if a movie had been downloaded. With Watcher having no email ability it would be really handy if there was a recently finished section so you could quickly view your most recent downloaded / finished movies.

barbequesauce commented 4 years ago

An email plugin should be easy enough to write... https://github.com/barbequesauce/Watcher3/wiki/Plugins

twiz-git commented 4 years ago

I'm not at all familiar with python at all so I'm not sure if this will work, but I cobbled together some code based off the PushBullet notification plugin and a StackOverflow post. It is completely untested, but I hope it works or helps. I take no credit for the code, it was essentially all found online from the above sources.

email notify.py

# Watcher Plugin to send e-mail Notifications
# Trigger: Post-processing Finished

import sys
import json
import smtplib
from datetime import datetime
from email.message import EmailMessage
from email import utils

title = sys.argv[1]
new_file = sys.argv[6]
conf_json = sys.argv[11]
conf = json.loads(conf_json)

smtp_server = conf['smtp_server']
smtp_port = conf['smtp_port']
smtp_username = conf['smtp_username']
smtp_password = conf['smtp_password']
smtp_sendtoname = conf['smtp_sendtoname']

msg = EmailMessage()
msg.set_content('{} finished processing on {}:\n {}'.format(title, datetime.now().strftime("%a, %b %d, at %I:%M%p"), new_file))
msg['Subject'] = 'Watcher Finished Processing {}'.format(title)
msg['From'] = smtp_username
msg['To'] = smtp_sendtoname
msg['Date'] = utils.format_datetime(datetime.now())

try:
    if conf['smtp_usessl']:
        server = smtplib.SMTP_SSL(smtp_server, smtp_port)
    else:
        server = smtplib.SMTP(smtp_server, smtp_port)
        try:
            server.starttls()
        except SMTPNotSupportedError:
            pass
    server.login(smtp_username, smtp_password)
    server.send_message(msg)
    server.quit()

except Exception as e:
    print(str(e))
    sys.exit(1)

sys.exit(0)

email notify.conf

{
    "Config Version": 2,
    "smtp_server": {
        "value": "",
        "display": 0,
        "type": "string",
        "label": "SMTP Server"
    },
    "smtp_port": {
        "value": "",
        "display": 1,
        "type": "int",
        "label": "SMTP Port"
    },
    "smtp_username": {
        "value": "",
        "display": 2,
        "type": "string",
        "label": "Username"
    },
    "smtp_password": {
        "value": "",
        "display": 3,
        "type": "string",
        "label": "Password"
    },
    "smtp_usessl": {
        "value": false,
        "display": 4,
        "type": "bool",
        "label": "Use SSL"
    },
    "smtp_sendtoname": {
        "value": "",
        "display": 5,
        "type": "string",
        "label": "Send To"
    }
}
scambra commented 4 years ago

Watcher plugins repository already have plugins to notify with pushbullet and join services.

GTunney commented 4 years ago

Watcher plugins repository already have plugins to notify with pushbullet and join services.

Both pushbullet and join are paid for services that require a subscription, email would be a simple free alternative.

twiz-git commented 4 years ago

Both pushbullet and join are paid for services that require a subscription, email would be a simple free alternative.

Pushbullet is free, with paid features. But chat and notification (as well as other features) are free to use. Did/could you try out the plugin files i submitted above? I would test them myself, but dont actually use watcher at the moment.

scambra commented 4 years ago

Have you tried with code from @twiz-ahk? I have edited that comment, it had some errors in python code and config file. Use SSL must be enabled for SSL ports (465), not for STARTTLS ports as 25 or 587.

scambra commented 4 years ago

Maybe plugin could have email address for recipient, so it can be send to different email than smtp username. It uses smtp username as from, most mail providers use email address as username but maybe a setting for From could be added too.

GTunney commented 4 years ago

I did try but it failed.

WARNING [2020-09-24 11:07:02,011] core.plugins.execute.267: email.py - Execution failed. Exit code 1.
INFO [2020-09-24 11:07:02,011] core.plugins.execute.263: email.py - b"ModuleNotFoundError: No module named 'email.message'; 'email' is not a package"
INFO [2020-09-24 11:07:02,011] core.plugins.execute.263: email.py - b' from email.message import EmailMessage'
INFO [2020-09-24 11:07:02,010] core.plugins.execute.263: email.py - b' File "/share/CACHEDEV1_DATA/.qpkg/Watcher3/watcher/plugins/finished/email.py", line 8, in <module>'
INFO [2020-09-24 11:07:02,010] core.plugins.execute.263: email.py - b' import email.utils'
INFO [2020-09-24 11:07:02,010] core.plugins.execute.263: email.py - b' File "/share/CACHEDEV1_DATA/.qpkg/Watcher3/lib/python3.7/smtplib.py", line 47, in <module>'
INFO [2020-09-24 11:07:02,010] core.plugins.execute.263: email.py - b' import smtplib'
INFO [2020-09-24 11:07:02,010] core.plugins.execute.263: email.py - b' File "/share/CACHEDEV1_DATA/.qpkg/Watcher3/watcher/plugins/finished/email.py", line 6, in <module>'
INFO [2020-09-24 11:07:02,009] core.plugins.execute.263: email.py - b'Traceback (most recent call last):'
DEBUG [2020-09-24 11:07:01,856] core.plugins.execute.250: Executing plugin email.py as ['/share/CACHEDEV1_DATA/.qpkg/Watcher3/bin/python3', '/share/CACHEDEV1_DATA/.qpkg/Watcher3/watcher/plugins/finished/email.py', 'Hard Kill', '2020', 'tt11656172', 'WebDL-1080P', 'None', '/share/Download/Movies/Hard.Kill.1080p.WEB-DL.DD5.1.H.264-EVO-xpost/Hard.Kill.1080p.WEB-DL.DD5.1.H.264-EVO-xpost.mkv', '/share/Multimedia/Videos/Movies/Hard Kill (2020)/Hard Kill (2020).mkv', 'SABnzbd_nzo_s8giqaf2', '2020-09-24', 'Default', '{"smtp_server": "removed", "smtp_port": 465, "smtp_username": "removed", "smtp_sendtoname": "removed", "smtp_password": "removed", "smtp_usessl": true}'].
scambra commented 4 years ago

Don't name plugin as email.py, it prevents finding email package. Rename them to "email notify.py" and "email notify.conf"

GTunney commented 4 years ago

Different error now after renaming.

INFO [2020-09-24 13:11:07,224] core.ajax.get_log_text.569: Dumping log file log.txt to text.
WARNING [2020-09-24 13:10:58,526] core.plugins.execute.267: email notify.py - Execution failed. Exit code 1.
INFO [2020-09-24 13:10:58,526] core.plugins.execute.263: email notify.py - b"NameError: name 'smtp_sendtoname' is not defined"
INFO [2020-09-24 13:10:58,526] core.plugins.execute.263: email notify.py - b" msg['To'] = smtp_sendtoname"
INFO [2020-09-24 13:10:58,525] core.plugins.execute.263: email notify.py - b' File "/share/CACHEDEV1_DATA/.qpkg/Watcher3/watcher/plugins/finished/email notify.py", line 25, in <module>'
INFO [2020-09-24 13:10:58,525] core.plugins.execute.263: email notify.py - b'Traceback (most recent call last):'
DEBUG [2020-09-24 13:10:58,281] core.plugins.execute.250: Executing plugin email notify.py as ['/share/CACHEDEV1_DATA/.qpkg/Watcher3/bin/python3', '/share/CACHEDEV1_DATA/.qpkg/Watcher3/watcher/plugins/finished/email notify.py', 'Ava', '2020', 'tt8784956', 'BluRay-1080P', 'None', '/share/Download/Movies/Ava.(2020).(1080p.BDRip.x265.10bit.DTS-HD.MA.5.1.-.r0b0t).[TAoE].mkv-xpost/abc.xyz.8e4429d7db6412.mkv', '/share/Multimedia/Videos/Movies/Ava (2020)/Ava (2020).mkv', 'SABnzbd_nzo_zekvis61', '2020-09-24', 'Default', '{"smtp_server": "xxxxxx", "smtp_port": 465, "smtp_username": "xxxxxx", "smtp_sendtoname": "xxxxx@icloud.com", "smtp_password": "xxxxxx", "smtp_usessl": true}'].
scambra commented 4 years ago

Line 25 is wrong, it must be msg['To'] = smtp_username

I have fixed it in comment, I have reviewed email notify.py in comment and now it's same content as my file, it should work now.

twiz-git commented 4 years ago

I had changed the line to support sending to a different email, and added an entry to the 'email notify.conf' file.

But forgot to change the display property.

GTunney commented 4 years ago

Ok thats worked and has fired the email off but has sent to the smtp_username as per line 25.

Is there no way or any point in having the smtp_sendtoname if it doesn't work?

If not i'll just put a forward on to my main mail account.

twiz-git commented 4 years ago

Is there no way or any point in having the smtp_sendtoname if it doesn't work?

I think i fixed it... i had forgotten to get the value from the conf. Stupid mistake lol

scambra commented 4 years ago

I have copied last code from @twiz-ahk comment and uploaded to watcherplugins repository

GTunney commented 4 years ago

Yup thats all working now, good work chaps.

scambra commented 4 years ago

Also, I added sorting by finished date, so you can set to descending order and see latest downloaded movies.