Compare commits

...

95 Commits

Author SHA1 Message Date
JonnyWong16
4944ce1ca0 v2.1.20 2018-09-05 08:55:20 -07:00
JonnyWong16
f04873446a v2.1.20-beta 2018-09-02 18:06:45 -07:00
JonnyWong16
505b6b616e Add session_id parameter to get_activity API command 2018-09-02 11:27:34 -07:00
JonnyWong16
87dd43d699 Merge pull request #1305 from samwiseg00/fix/systemd_init
Change init script group value to be compatible with CentOS
2018-09-02 11:21:18 -07:00
samwiseg00
a48ebef9ae Change init script group value 2018-08-31 13:27:15 -04:00
JonnyWong16
e40483525b Redirect root to http_root 2018-08-27 21:41:11 -07:00
JonnyWong16
ebc563fd26 Remove unused pnotify css from login page 2018-08-27 21:39:40 -07:00
JonnyWong16
5bb3e189fe Update API docs 2018-08-27 21:27:09 -07:00
JonnyWong16
ed08df5224 Try getting missing parent_rating_key from parent_thumb first 2018-08-27 21:06:52 -07:00
JonnyWong16
ae2584b6f6 Helper function for splitting script args 2018-08-27 20:56:32 -07:00
JonnyWong16
f0e2355231 Log folder/file location on startup 2018-08-27 16:05:39 -07:00
JonnyWong16
878c48b491 Fix video and audio not showing on activity cards after refresh 2018-08-26 15:36:21 -07:00
JonnyWong16
ecfbb4de9b Fetch missing parent rating key when season is hidden 2018-08-24 22:02:21 -07:00
JonnyWong16
731af75c54 Merge pull request #1304 from samwiseg00/feature/add_env
Add TAUTULLI_PUBLIC_URL to environment variables
2018-08-24 08:07:21 -07:00
samwiseg00
9817da6012 Add TAUTULLI_PUBLIC_URL to environment variables 2018-08-24 02:59:34 -04:00
JonnyWong16
dd3f75f154 Add return_hash to pms_image_proxy API 2018-08-23 19:12:22 -07:00
JonnyWong16
1eee03fa8f Merge pull request #1303 from samwiseg00/feature/add_timestamp
Add UTC timestamp to notification params + OCD + Change discord timestamp function
2018-08-22 18:35:20 -07:00
samwiseg00
02af6c4e6c Change discord timestamp function to metadata params 2018-08-22 00:22:01 -04:00
samwiseg00
b8a9c4f5b7 Add UTC ISO time to notification handler 2018-08-22 00:21:49 -04:00
samwiseg00
0b227dc69e PEP8 functions in helpers 2018-08-22 00:18:54 -04:00
JonnyWong16
8228018dd0 Add sending notification log message 2018-08-20 14:49:00 -07:00
JonnyWong16
5c3086a049 Chnage get_notify_text_preview to POST 2018-08-19 15:08:27 -07:00
JonnyWong16
4f397b032e v2.1.19-beta 2018-08-19 08:38:39 -07:00
JonnyWong16
3a05b8ec69 Fix switching tray icon on update check 2018-08-18 15:35:25 -07:00
JonnyWong16
84ef02aa03 Add update check to Windows tray icon 2018-08-18 15:30:59 -07:00
JonnyWong16
5d82ed9415 Update newsletter config note 2018-08-18 15:06:49 -07:00
JonnyWong16
524183c2cb Fix spaces in newsletter (Resolves #1302) 2018-08-17 21:08:27 -07:00
JonnyWong16
53b361d410 Allow override for PYTHONPATH in scripts 2018-08-15 20:17:48 -07:00
JonnyWong16
30c7c6592e Merge pull request #1301 from samwiseg00/refactor-oauth-login
Refactor OAuth Login
2018-08-15 20:06:07 -07:00
JonnyWong16
88b0b888a1 Merge pull request #1300 from samwiseg00/fix-db-backup
Fix API creating a backup every sql query
2018-08-15 20:05:48 -07:00
samwiseg00
c2dcd98939 Verify that we are checking for a server 2018-08-15 21:48:25 -04:00
samwiseg00
56e9845b2c Change method for determining server list for OAuth 2018-08-15 21:48:13 -04:00
samwiseg00
6b94292c7e Fix API creating a backup every sql query 2018-08-15 16:31:31 -04:00
JonnyWong16
13dac9c1ea Refactor update check 2018-08-14 19:23:20 -07:00
JonnyWong16
4f4a66f7e7 Restart after chaging system tray setting 2018-08-14 00:14:03 -07:00
JonnyWong16
1bd7cf4d4c Close system tray icon on shutdown 2018-08-13 23:57:26 -07:00
JonnyWong16
b1ec49341e Add Windows system tray icon 2018-08-13 19:53:15 -07:00
JonnyWong16
aeccc2db71 Fix incorrect HTTP_ROOT when launching browser 2018-08-13 18:54:12 -07:00
JonnyWong16
6be5397a2d Decode script args before formatting 2018-08-13 09:34:31 -07:00
JonnyWong16
427201a4ce Add recently added XML shortcut 2018-08-12 14:32:45 -07:00
JonnyWong16
5736e12bc3 Format Webhook data strings only 2018-08-12 10:54:39 -07:00
JonnyWong16
4648e3df5f Add webhook notification agent 2018-08-12 10:31:27 -07:00
JonnyWong16
9dbb681f22 Add donate button to Tautulli updated modal 2018-08-11 09:50:59 -07:00
JonnyWong16
658260f1f6 Add x264 to hardware encoders 2018-08-10 22:44:45 -07:00
JonnyWong16
f93e745f0b Fix retrieving email msg id 2018-07-29 20:34:35 -07:00
JonnyWong16
0821c14aae Add option for threaded newsletter emails 2018-07-29 10:28:34 -07:00
JonnyWong16
1b216a35d4 Remove Notify My Android 2018-07-28 11:01:52 -07:00
JonnyWong16
7b4eadb140 Update systemd script instructions 2018-07-28 09:35:23 -07:00
JonnyWong16
a8a676b794 v2.1.18 2018-07-27 13:53:45 -07:00
JonnyWong16
2f40850100 Fix search bar width (Fixes Tautulli/Tautulli-Issues#104) 2018-07-26 17:25:31 -07:00
JonnyWong16
f16560cb40 Fix activity progress bar showing incorrect 100% 2018-07-25 18:48:33 -07:00
JonnyWong16
ab92e48d2e Fix auto resizing textareas scrolling to the top on focus 2018-07-25 18:39:40 -07:00
JonnyWong16
ce2982d948 Skip formatting bad parameters in notification text 2018-07-25 16:23:01 -07:00
JonnyWong16
89d1a5782a v2.1.17-beta 2018-07-22 17:45:02 -07:00
JonnyWong16
97cf2ebe19 Make monitor websocket ping/pong an advanced config option 2018-07-22 17:39:21 -07:00
JonnyWong16
4ef36a464a Set datatables save state duration to indefinitely 2018-07-22 17:35:10 -07:00
JonnyWong16
54ec9ad7da Remove unused libs 2018-07-22 13:54:07 -07:00
JonnyWong16
bfdfdaaad1 Image alt text to Tautulli 2018-07-17 09:44:00 -07:00
JonnyWong16
5bd51b2a17 Don't join empty paths 2018-07-16 09:36:13 -07:00
JonnyWong16
35778cfe72 Use os.pathsep for PYTHONPATH 2018-07-16 09:02:17 -07:00
JonnyWong16
f81649c4d3 Update nullrefer to HTTPS 2018-07-10 15:46:01 -07:00
JonnyWong16
59162713e7 Fix ajax loader message refresh icon spacing 2018-07-10 08:51:55 -07:00
JonnyWong16
188b728dd0 Fix save settings loader 2018-07-10 08:50:56 -07:00
JonnyWong16
3446f5543d Check local server directly 2018-07-10 08:12:12 -07:00
JonnyWong16
ab5384cfdf Discover localhost server 2018-07-09 19:31:11 -07:00
JonnyWong16
e567134ee1 Use default selected stream for media info in notifications 2018-07-06 19:41:03 -07:00
JonnyWong16
98b5cb67ca v2.1.16-beta 2018-07-06 19:06:02 -07:00
JonnyWong16
26db7f1984 Update API docs with rating_image and audience_rating_image 2018-07-06 19:04:06 -07:00
JonnyWong16
e1afbd4eff Remove white text on accordion hover 2018-07-06 18:52:19 -07:00
JonnyWong16
f6090bcdf0 Fix accordion icon colours 2018-07-06 18:44:20 -07:00
JonnyWong16
0950ff7ecf Fix incorrect stream_duration parameter for playback start notifications 2018-07-06 18:43:57 -07:00
JonnyWong16
e766cb6093 Add critic_rating to notification parameters 2018-07-06 18:34:50 -07:00
JonnyWong16
8982ae83ac Percent helper round before trunc 2018-07-06 18:15:18 -07:00
JonnyWong16
2b395a7ad9 Fix API get_logs (Fixes Tautulli/Tautulli-Issues#100) 2018-07-05 18:50:04 -07:00
JonnyWong16
a9b5c91f84 Fix OAuth popup loader 2018-07-05 18:23:10 -07:00
JonnyWong16
c0b960bccf Refactor Plex OAuth code 2018-07-05 09:06:03 -07:00
JonnyWong16
8514cf1975 Reset pong count 2018-07-04 12:25:32 -07:00
JonnyWong16
c5e37badd8 Fix infinite websocket connection loop 2018-07-03 20:06:37 -07:00
JonnyWong16
c0f1079b4e Remove connection attempts from inital websocket connection 2018-07-03 19:58:58 -07:00
JonnyWong16
1da4b8ecb4 Add ping/pong to websocket 2018-07-03 18:10:52 -07:00
JonnyWong16
c2ba2b4e98 Add popup OAuth window to wizard and settings 2018-07-03 09:49:11 -07:00
JonnyWong16
d9ea781462 Center Discord chat popout window 2018-07-03 09:46:37 -07:00
JonnyWong16
5ee5ca7dbf Popup window for Plex OAuth 2018-07-03 09:46:12 -07:00
JonnyWong16
176392d837 Fix typo in newlsetter with single reminaing season 2018-07-02 16:16:05 -07:00
JonnyWong16
b65e6a39a0 Accordion for login methods on login page 2018-07-02 15:56:24 -07:00
JonnyWong16
5c7a3a12e9 Add OAuth to token refresh in settings 2018-07-02 12:28:34 -07:00
JonnyWong16
e7072edbd1 Add OAuth to setup wizard 2018-07-02 12:04:12 -07:00
JonnyWong16
2711597ffb Pass OAuth client headers to server 2018-07-02 11:20:25 -07:00
JonnyWong16
24458bd23c Log login method 2018-07-02 09:55:41 -07:00
JonnyWong16
3fd0708d21 Use client headers for OAuth 2018-07-02 09:55:28 -07:00
JonnyWong16
434cb89ba8 Correct client ID 2018-07-02 09:00:25 -07:00
JonnyWong16
745d398527 Improve Plex OAuth 2018-07-02 08:51:51 -07:00
JonnyWong16
16bfcade8c Log failed OAuth attempts 2018-07-02 00:45:47 -07:00
JonnyWong16
f69f5a79d9 Merge branch 'beta' into nightly 2018-07-01 23:40:03 -07:00
JonnyWong16
3bd1b03faf Add Plex OAuth to login page 2018-07-01 22:55:13 -07:00
59 changed files with 2103 additions and 3600 deletions

31
API.md
View File

@@ -1,9 +1,15 @@
# API Reference # API Reference
The API is still pretty new and needs some serious cleaning up on the backend but should be reasonably functional. There are no error codes yet.
## General structure ## General structure
The API endpoint is `http://ip:port + HTTP_ROOT + /api/v2?apikey=$apikey&cmd=$command` The API endpoint is
```
http://IP_ADDRESS:PORT + [/HTTP_ROOT] + /api/v2?apikey=$apikey&cmd=$command
```
Example:
```
http://localhost:8181/api/v2?apikey=66198313a092496b8a725867d2223b5f&cmd=get_metadata&rating_key=153037
```
Response example (default `json`) Response example (default `json`)
``` ```
@@ -354,7 +360,8 @@ Required parameters:
None None
Optional parameters: Optional parameters:
None session_key (int): Session key for the session info to return, OR
session_id (str): Session ID for the session info to return
Returns: Returns:
json: json:
@@ -373,6 +380,7 @@ Returns:
"art": "/library/metadata/1219/art/1503306930", "art": "/library/metadata/1219/art/1503306930",
"aspect_ratio": "1.78", "aspect_ratio": "1.78",
"audience_rating": "", "audience_rating": "",
"audience_rating_image": "rottentomatoes://image.rating.upright",
"audio_bitrate": "384", "audio_bitrate": "384",
"audio_bitrate_mode": "", "audio_bitrate_mode": "",
"audio_channel_layout": "5.1(side)", "audio_channel_layout": "5.1(side)",
@@ -449,6 +457,7 @@ Returns:
"progress_percent": "0", "progress_percent": "0",
"quality_profile": "Original", "quality_profile": "Original",
"rating": "7.8", "rating": "7.8",
"rating_image": "rottentomatoes://image.rating.ripe",
"rating_key": "153037", "rating_key": "153037",
"relay": 0, "relay": 0,
"section_id": "2", "section_id": "2",
@@ -1084,6 +1093,7 @@ Returns:
"added_at": "1461572396", "added_at": "1461572396",
"art": "/library/metadata/1219/art/1462175063", "art": "/library/metadata/1219/art/1462175063",
"audience_rating": "8", "audience_rating": "8",
"audience_rating_image": "rottentomatoes://image.rating.upright",
"banner": "/library/metadata/1219/banner/1462175063", "banner": "/library/metadata/1219/banner/1462175063",
"collections": [], "collections": [],
"content_rating": "TV-MA", "content_rating": "TV-MA",
@@ -1137,7 +1147,8 @@ Returns:
"video_language_code": "", "video_language_code": "",
"video_profile": "high", "video_profile": "high",
"video_ref_frames": "4", "video_ref_frames": "4",
"video_width": "1920" "video_width": "1920",
"selected": 0
}, },
{ {
"audio_bitrate": "384", "audio_bitrate": "384",
@@ -1150,7 +1161,8 @@ Returns:
"audio_profile": "", "audio_profile": "",
"audio_sample_rate": "48000", "audio_sample_rate": "48000",
"id": "511664", "id": "511664",
"type": "2" "type": "2",
"selected": 1
}, },
{ {
"id": "511953", "id": "511953",
@@ -1161,7 +1173,8 @@ Returns:
"subtitle_language": "English", "subtitle_language": "English",
"subtitle_language_code": "eng", "subtitle_language_code": "eng",
"subtitle_location": "external", "subtitle_location": "external",
"type": "3" "type": "3",
"selected": 1
} }
] ]
} }
@@ -1181,6 +1194,7 @@ Returns:
"parent_thumb": "/library/metadata/153036/thumb/1462175062", "parent_thumb": "/library/metadata/153036/thumb/1462175062",
"parent_title": "", "parent_title": "",
"rating": "7.8", "rating": "7.8",
"rating_image": "rottentomatoes://image.rating.ripe",
"rating_key": "153037", "rating_key": "153037",
"section_id": "2", "section_id": "2",
"sort_title": "Game of Thrones", "sort_title": "Game of Thrones",
@@ -2431,7 +2445,7 @@ Required parameters:
body (str): The body of the message body (str): The body of the message
Optional parameters: Optional parameters:
None script_args (str): The arguments for script notifications
Returns: Returns:
None None
@@ -2492,6 +2506,7 @@ Optional parameters:
img_format (str): png img_format (str): png
fallback (str): "poster", "cover", "art" fallback (str): "poster", "cover", "art"
refresh (bool): True or False whether to refresh the image cache refresh (bool): True or False whether to refresh the image cache
return_hash (bool): True or False to return the self-hosted image hash instead of the image
Returns: Returns:
None None

View File

@@ -1,5 +1,80 @@
# Changelog # Changelog
## v2.1.20 (2018-09-05)
* No changes.
## v2.1.20-beta (2018-09-02)
* Monitoring:
* Fix: Fetch messing season info when "Hide Seasons" is enabled for a show.
* Fix: Video and Audio details sometimes missing on activity cards.
* Notifications:
* New: Added UTC timestamp to notification parameters. (Thanks @samwiseg00)
* New: Added TAUTULLI_PUBLIC_URL to script environment variables. (Thanks @samwiseg00)
* UI:
* Change: Automatically redirect '/' to HTTP root if enabled.
* API:
* New: Added return_hash parameter to pms_image_proxy command.
* New: Added session_id parameter to get_activity command.
* Other:
* Change: Linux systemd startup script to use the "tautulli" group permission. (Thanks @samwiseg00)
## v2.1.19-beta (2018-08-19)
* Notifications:
* New: Added Webhook notification agent.
* Fix: Scripts failing due to unicode characters in substituted script arguments.
* Change: Ability to override PYTHONPATH for scripts.
* Remove: Notify My Android notification agent.
* Newsletters:
* New: Added option for threaded newsletter emails.
* Fix: Missing space in newsletter format.
* UI:
* New: Added Windows system tray icon.
* Fix: Plex OAuth not working with Plex remote access disabled. (Thanks @samwiseg00)
* API:
* Fix: SQL command creating a database backup every time. (Thanks @samwiseg00)
## v2.1.18 (2018-07-27)
* Monitoring:
* Fix: Progress bar on activity cards showing incorrect 100% when starting a stream.
* Notifications:
* Fix: Notification text boxes scrolling to top when inputting text.
* Change: Skip formatting invalid notification parameters instead of returning default text.
* UI:
* Fix: Padding around search bar causing the navigation bar to break on smaller screens.
## v2.1.17-beta (2018-07-22)
* Notifications:
* Change: Use default selected stream for media info in notifications.
* UI:
* New: Automatically discover localhost Plex servers in server selection dropdown.
* Change: Save Datatables state indefinitely.
## v2.1.16-beta (2018-07-06)
* Monitoring:
* Fix: Plex server not detected as down during sudden network loss.
* Notifications:
* Fix: Incorrect rounding of percentages in some cases.
* Fix: Incorrect stream duration value for playback start notifications.
* New: Added critic rating parameter for Rotten Tomatoes ratings.
* Newsletters:
* Fix: Typo in "seasons" when there is only one additional season.
* UI:
* New: Added ability to use Plex OAuth to login to Tautulli.
* API:
* Fix: Unicode characters causing get_logs command to return bad data.
* New: Added rating_image and audience_rating_image to get_activity and get_metadata commands.
## v2.1.15-beta (2018-07-01) ## v2.1.15-beta (2018-07-01)
* Monitoring: * Monitoring:

View File

@@ -204,10 +204,10 @@ def main():
# Force the http port if neccessary # Force the http port if neccessary
if args.port: if args.port:
http_port = args.port plexpy.HTTP_PORT = args.port
logger.info('Using forced web server port: %i', http_port) logger.info('Using forced web server port: %i', plexpy.HTTP_PORT)
else: else:
http_port = int(plexpy.CONFIG.HTTP_PORT) plexpy.HTTP_PORT = int(plexpy.CONFIG.HTTP_PORT)
# Check if pyOpenSSL is installed. It is required for certificate generation # Check if pyOpenSSL is installed. It is required for certificate generation
# and for CherryPy. # and for CherryPy.
@@ -221,7 +221,7 @@ def main():
# Try to start the server. Will exit here is address is already in use. # Try to start the server. Will exit here is address is already in use.
web_config = { web_config = {
'http_port': http_port, 'http_port': plexpy.HTTP_PORT,
'http_host': plexpy.CONFIG.HTTP_HOST, 'http_host': plexpy.CONFIG.HTTP_HOST,
'http_root': plexpy.CONFIG.HTTP_ROOT, 'http_root': plexpy.CONFIG.HTTP_ROOT,
'http_environment': plexpy.CONFIG.HTTP_ENVIRONMENT, 'http_environment': plexpy.CONFIG.HTTP_ENVIRONMENT,
@@ -238,8 +238,12 @@ def main():
# Open webbrowser # Open webbrowser
if plexpy.CONFIG.LAUNCH_BROWSER and not args.nolaunch and not plexpy.DEV: if plexpy.CONFIG.LAUNCH_BROWSER and not args.nolaunch and not plexpy.DEV:
plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, http_port, plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT,
plexpy.CONFIG.HTTP_ROOT) plexpy.HTTP_ROOT)
# Windows system tray icon
if os.name == 'nt' and plexpy.CONFIG.WIN_SYS_TRAY:
plexpy.win_system_tray()
# Wait endlessy for a signal to happen # Wait endlessy for a signal to happen
while True: while True:

View File

@@ -43,18 +43,18 @@
<div class="container"> <div class="container">
<div id="ajaxMsg" class="ajaxMsg"></div> <div id="ajaxMsg" class="ajaxMsg"></div>
% if _session['user_group'] == 'admin': % if _session['user_group'] == 'admin':
% if plexpy.CONFIG.CHECK_GITHUB and not plexpy.CURRENT_VERSION: % if plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE is None:
<div id="updatebar" style="display: none;"> <div id="updatebar" style="display: none;">
You are running an unknown version of Tautulli.<br /> You are running an unknown version of Tautulli.<br />
<a href="update">Update</a> or <a href="#" id="updateDismiss">Dismiss</a> <a href="update">Update</a> or <a href="#" id="updateDismiss">Dismiss</a>
</div> </div>
% elif plexpy.CONFIG.CHECK_GITHUB and plexpy.COMMITS_BEHIND > 0 and plexpy.common.BRANCH in ('master', 'beta') and plexpy.common.RELEASE != plexpy.LATEST_RELEASE: % elif plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE == 'release':
<div id="updatebar" style="display: none;"> <div id="updatebar" style="display: none;">
A <a href="${anon_url('https://github.com/%s/%s/releases/tag/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.LATEST_RELEASE))}" target="_blank"> A <a href="${anon_url('https://github.com/%s/%s/releases/tag/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.LATEST_RELEASE))}" target="_blank">
new release (${plexpy.LATEST_RELEASE})</a> of Tautulli is available!<br /> new release (${plexpy.LATEST_RELEASE})</a> of Tautulli is available!<br />
<a href="update">Update</a> or <a href="#" id="updateDismiss">Dismiss</a> <a href="update">Update</a> or <a href="#" id="updateDismiss">Dismiss</a>
</div> </div>
% elif plexpy.CONFIG.CHECK_GITHUB and plexpy.COMMITS_BEHIND > 0 and plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and plexpy.INSTALL_TYPE != 'win': % elif plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE == 'commit':
<div id="updatebar" style="display: none;"> <div id="updatebar" style="display: none;">
A <a href="${anon_url('https://github.com/%s/%s/compare/%s...%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CURRENT_VERSION, plexpy.LATEST_VERSION))}" target="_blank"> A <a href="${anon_url('https://github.com/%s/%s/compare/%s...%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CURRENT_VERSION, plexpy.LATEST_VERSION))}" target="_blank">
newer version</a> of Tautulli is available!<br /> newer version</a> of Tautulli is available!<br />
@@ -75,7 +75,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="home" title="Tautulli"> <a class="navbar-brand" href="home" title="Tautulli">
<img src="${http_root}images/logo-tautulli-45.png" height="45" alt="PlexPy"> <img src="${http_root}images/logo-tautulli-45.png" height="45" alt="Tautulli">
</a> </a>
</div> </div>
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse-1"> <div class="collapse navbar-collapse navbar-right" id="navbar-collapse-1">
@@ -140,7 +140,7 @@
<li><a href="#" data-target="#donate-modal" data-toggle="modal"><i class="fa fa-fw fa-heart"></i> Donate</a></li> <li><a href="#" data-target="#donate-modal" data-toggle="modal"><i class="fa fa-fw fa-heart"></i> Donate</a></li>
<li role="separator" class="divider"></li> <li role="separator" class="divider"></li>
% if plexpy.CONFIG.CHECK_GITHUB: % if plexpy.CONFIG.CHECK_GITHUB:
<li><a href="#" id="nav-update"><i class="fa fa-fw fa-arrow-circle-up"></i> Check for Updates</a></li> <li><a href="#" id="nav-update"><i class="fa fa-fw fa-arrow-alt-circle-up"></i> Check for Updates</a></li>
% endif % endif
<li><a href="#" id="nav-restart"><i class="fa fa-fw fa-refresh"></i> Restart</a></li> <li><a href="#" id="nav-restart"><i class="fa fa-fw fa-refresh"></i> Restart</a></li>
<li><a href="#" id="nav-shutdown"><i class="fa fa-fw fa-power-off"></i> Shutdown</a></li> <li><a href="#" id="nav-shutdown"><i class="fa fa-fw fa-power-off"></i> Shutdown</a></li>
@@ -291,6 +291,7 @@ ${next.modalIncludes()}
<script src="${http_root}js/bootstrap.min.js"></script> <script src="${http_root}js/bootstrap.min.js"></script>
<script src="${http_root}js/bootstrap-hover-dropdown.min.js"></script> <script src="${http_root}js/bootstrap-hover-dropdown.min.js"></script>
<script src="${http_root}js/pnotify.custom.min.js"></script> <script src="${http_root}js/pnotify.custom.min.js"></script>
<script src="${http_root}js/platform.min.js"></script>
<script src="${http_root}js/script.js${cache_param}"></script> <script src="${http_root}js/script.js${cache_param}"></script>
<script src="${http_root}js/jquery.qrcode.min.js"></script> <script src="${http_root}js/jquery.qrcode.min.js"></script>
<script src="${http_root}js/jquery.tripleclick.min.js"></script> <script src="${http_root}js/jquery.tripleclick.min.js"></script>
@@ -361,7 +362,7 @@ ${next.modalIncludes()}
$('#nav-update').click(function () { $('#nav-update').click(function () {
$(this).html('<i class="fa fa-fw fa-spin fa-refresh"></i> Checking'); $(this).html('<i class="fa fa-fw fa-spin fa-refresh"></i> Checking');
checkUpdate(function () { $('#nav-update').html('<i class="fa fa-fw fa-arrow-circle-up"></i> Check for Updates'); }); checkUpdate(function () { $('#nav-update').html('<i class="fa fa-fw fa-arrow-alt-circle-up"></i> Check for Updates'); });
}); });
$('#donation_type a.crypto-donation').on('shown.bs.tab', function () { $('#donation_type a.crypto-donation').on('shown.bs.tab', function () {

View File

@@ -22,11 +22,11 @@ DOCUMENTATION :: END
% if plexpy.CURRENT_VERSION: % if plexpy.CURRENT_VERSION:
<tr> <tr>
<td>Git Branch:</td> <td>Git Branch:</td>
<td><a class="no-highlight" href="${anon_url('https://github.com/%s/%s/tree/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH))}">${plexpy.CONFIG.GIT_BRANCH}</a></td> <td><a class="no-highlight" href="${anon_url('https://github.com/%s/%s/tree/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH))}" target="_blank">${plexpy.CONFIG.GIT_BRANCH}</a></td>
</tr> </tr>
<tr> <tr>
<td>Git Commit Hash:</td> <td>Git Commit Hash:</td>
<td><a class="no-highlight" href="${anon_url('https://github.com/%s/%s/commit/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CURRENT_VERSION))}">${plexpy.CURRENT_VERSION}</a></td> <td><a class="no-highlight" href="${anon_url('https://github.com/%s/%s/commit/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CURRENT_VERSION))}" target="_blank">${plexpy.CURRENT_VERSION}</a></td>
</tr> </tr>
% endif % endif
<tr> <tr>

View File

@@ -101,6 +101,9 @@ select.form-control {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.wizard-input-section p.welcome-message {
margin: 20px 0;
}
.wizard-input-section .selectize-control.form-control.selectize-pms-ip .selectize-input > div { .wizard-input-section .selectize-control.form-control.selectize-pms-ip .selectize-input > div {
max-width: 360px; max-width: 360px;
overflow: hidden; overflow: hidden;
@@ -2970,10 +2973,13 @@ a .home-platforms-list-cover-face:hover
-o-transition: all 0.3s ease; -o-transition: all 0.3s ease;
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.accordion li .link:hover { .accordion li .link:hover,
color: #fff; .accordion li .link:hover i.fa {
background: #2f2f2f; background: #2f2f2f;
} }
.accordion li .link i.fa {
color: #999;
}
.accordion li .link span.toggle-right { .accordion li .link span.toggle-right {
float: right; float: right;
padding-left: 10px; padding-left: 10px;
@@ -2987,7 +2993,8 @@ a .home-platforms-list-cover-face:hover
-o-transition: all 0.3s ease; -o-transition: all 0.3s ease;
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.accordion li.open .link { .accordion li.open .link,
.accordion li.open .link i.fa {
color: #f9be03; color: #f9be03;
} }
.accordion li.open .fa-chevron-down { .accordion li.open .fa-chevron-down {
@@ -3281,7 +3288,7 @@ pre::-webkit-scrollbar-thumb {
} }
} }
#search_form { #search_form {
width: 300px; width: 270px;
padding: 8px 15px; padding: 8px 15px;
} }
#search_form span.input-textbox { #search_form span.input-textbox {
@@ -3470,6 +3477,9 @@ a.no-highlight:hover {
max-width: 1170px; max-width: 1170px;
} }
} }
.login-body-container {
margin: 50px 0;
}
.login-container { .login-container {
margin-right: auto; margin-right: auto;
margin-left: auto; margin-left: auto;
@@ -3483,6 +3493,11 @@ a.no-highlight:hover {
margin: 0 auto 50px auto; margin: 0 auto 50px auto;
text-align: center; text-align: center;
} }
.login-container .login-method-header {
text-align: center;
font-weight: 600;
text-transform: uppercase;
}
.login-container .form-group { .login-container .form-group {
margin-bottom: 20px; margin-bottom: 20px;
} }
@@ -3503,8 +3518,9 @@ a.no-highlight:hover {
text-shadow: 0 -1px 1px rgba(0,0,0,.4),0 0 15px rgba(0,0,0,.2); text-shadow: 0 -1px 1px rgba(0,0,0,.4),0 0 15px rgba(0,0,0,.2);
} }
.login-container .remember-group { .login-container .remember-group {
float: left;
color: #999; color: #999;
display: inline-block;
margin-top: 7.5px;
} }
.login-container .remember-group .control-label { .login-container .remember-group .control-label {
display: inline; display: inline;
@@ -3512,6 +3528,33 @@ a.no-highlight:hover {
font-weight: 400; font-weight: 400;
cursor: pointer; cursor: pointer;
} }
.login-divider {
text-align: center;
border-bottom: 1px solid #555;
line-height: 0.1em;
margin: 50px auto;
max-width: 400px;
text-transform: uppercase;
}
.login-divider span {
background: #1f1f1f;
padding: 0 15px;
color: #999;
}
.login-button-plex {
text-align: center;
}
.login-button-plex .remember-group {
margin-top: 20px;
}
.login-button-plex button#sign-in-plex {
float: none;
}
.login-alert {
text-align: center;
padding: 8px;
display: none;
}
#admin-login-modal .form-group label { #admin-login-modal .form-group label {
font-weight: 400; font-weight: 400;
color: #999; color: #999;

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@@ -100,7 +100,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="home-padded-header padded-header"> <div class="home-padded-header padded-header">
<h3 class="pull-left">Recently Added</h3> <h3 class="pull-left"><span id="recently-added-xml">Recently Added</span></h3>
<ul class="nav nav-header nav-dashboard pull-right" style="margin-top: -3px;"> <ul class="nav nav-header nav-dashboard pull-right" style="margin-top: -3px;">
<li> <li>
<a href="#" id="recently-added-page-left" class="paginate btn-gray disabled" data-id="+1"><i class="fa fa-lg fa-chevron-left"></i></a> <a href="#" id="recently-added-page-left" class="paginate btn-gray disabled" data-id="+1"><i class="fa fa-lg fa-chevron-left"></i></a>
@@ -169,6 +169,7 @@
<div class="modal-body"> <div class="modal-body">
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-danger" data-target="#donate-modal" data-toggle="modal" style="float: left;"><i class="fa fa-fw fa-heart"></i> Donate</button>
<input type="button" class="btn btn-bright" data-dismiss="modal" value="Close"> <input type="button" class="btn btn-bright" data-dismiss="modal" value="Close">
</div> </div>
</div> </div>
@@ -438,7 +439,7 @@
$('#transcode_container-' + key).html(transcode_container); $('#transcode_container-' + key).html(transcode_container);
var video_decision = ''; var video_decision = '';
if (['movie', 'episode', 'clip'].indexOf(s.media_type) > -1 && s.video_decision !== '') { if (['movie', 'episode', 'clip'].indexOf(s.media_type) > -1 && s.stream_video_decision) {
var v_res= ''; var v_res= '';
switch (s.video_resolution.toLowerCase()) { switch (s.video_resolution.toLowerCase()) {
case 'sd': case 'sd':
@@ -476,7 +477,7 @@
$('#video_decision-' + key).html(video_decision); $('#video_decision-' + key).html(video_decision);
var audio_decision = ''; var audio_decision = '';
if (['movie', 'episode', 'clip', 'track'].indexOf(s.media_type) > -1 && s.audio_decision) { if (['movie', 'episode', 'clip', 'track'].indexOf(s.media_type) > -1 && s.stream_audio_decision) {
var a_codec = (s.audio_codec === 'truehd') ? 'TrueHD' : s.audio_codec.toUpperCase(); var a_codec = (s.audio_codec === 'truehd') ? 'TrueHD' : s.audio_codec.toUpperCase();
var sa_codec = (s.stream_audio_codec === 'truehd') ? 'TrueHD' : s.stream_audio_codec.toUpperCase(); var sa_codec = (s.stream_audio_codec === 'truehd') ? 'TrueHD' : s.stream_audio_codec.toUpperCase();
if (s.stream_audio_decision === 'transcode') { if (s.stream_audio_decision === 'transcode') {
@@ -617,7 +618,8 @@
if ($(this).data('state') === 'playing' && $(this).data('view_offset') >= 0) { if ($(this).data('state') === 'playing' && $(this).data('view_offset') >= 0) {
var view_offset = parseInt($(this).data('view_offset')); var view_offset = parseInt($(this).data('view_offset'));
var stream_duration = parseInt($(this).data('stream_duration')); var stream_duration = parseInt($(this).data('stream_duration'));
var progress_percent = Math.min(Math.floor(view_offset / stream_duration * 100) || 100, 100); var progress_percent = Math.floor(view_offset / stream_duration * 100);
progress_percent = (progress_percent >= 0) ? Math.min(progress_percent, 100) : 100;
$(this).width(progress_percent - 3 + '%').html(progress_percent + '%') $(this).width(progress_percent - 3 + '%').html(progress_percent + '%')
.attr('data-original-title', 'Stream Progress ' + progress_percent + '%') .attr('data-original-title', 'Stream Progress ' + progress_percent + '%')
.data('view_offset', Math.min(view_offset + 1000, stream_duration)); .data('view_offset', Math.min(view_offset + 1000, stream_duration));
@@ -845,6 +847,10 @@
}); });
$('#recently-added-count').tooltip({ container: 'body', placement: 'top', html: true }); $('#recently-added-count').tooltip({ container: 'body', placement: 'top', html: true });
$('#recently-added-xml').on('tripleclick', function () {
openPlexXML('/library/recentlyAdded', false, {'X-Plex-Container-Start': 0, 'X-Plex-Container-Size': recently_added_count});
});
</script> </script>
% endif % endif
% if _session['user_group'] == 'admin' and config['update_show_changelog']: % if _session['user_group'] == 'admin' and config['update_show_changelog']:

File diff suppressed because one or more lines are too long

View File

@@ -37,7 +37,7 @@ function showMsg(msg, loader, timeout, ms, error) {
} }
var message = $("<div class='msg'>" + msg + "</div>"); var message = $("<div class='msg'>" + msg + "</div>");
if (loader) { if (loader) {
message = $("<div class='msg'><i class='fa fa-refresh fa-spin'></i> " + msg + "</div>"); message = $("<div class='msg'><i class='fa fa-refresh fa-spin'></i>&nbsp; " + msg + "</div>");
feedback.css("padding", "14px 10px"); feedback.css("padding", "14px 10px");
} }
if (error) { if (error) {
@@ -73,9 +73,9 @@ function confirmAjaxCall(url, msg, data, loader_msg, callback) {
var result = $.parseJSON(xhr.responseText); var result = $.parseJSON(xhr.responseText);
var msg = result.message; var msg = result.message;
if (result.result == 'success') { if (result.result == 'success') {
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 5000); showMsg('<i class="fa fa-check"></i>&nbsp; ' + msg, false, true, 5000);
} else { } else {
showMsg('<i class="fa fa-times"></i> ' + msg, false, true, 5000, true); showMsg('<i class="fa fa-times"></i>&nbsp; ' + msg, false, true, 5000, true);
} }
if (typeof callback === "function") { if (typeof callback === "function") {
callback(result); callback(result);
@@ -103,7 +103,7 @@ function doAjaxCall(url, elem, reload, form, showMsg, callback) {
dataString = $(formID).serialize(); dataString = $(formID).serialize();
} }
// Loader Image // Loader Image
var loader = $("<i class='fa fa-refresh fa-spin ajaxLoader-" + url +"></i>"); var loader = $("<div class='msg ajaxLoader-" + url +"'><i class='fa fa-refresh fa-spin'></i>&nbsp; Saving...</div>");
// Data Success Message // Data Success Message
var dataSucces = $(elem).data('success'); var dataSucces = $(elem).data('success');
if (typeof dataSucces === "undefined") { if (typeof dataSucces === "undefined") {
@@ -117,8 +117,8 @@ function doAjaxCall(url, elem, reload, form, showMsg, callback) {
dataError = "There was an error"; dataError = "There was an error";
} }
// Get Success & Error message from inline data, else use standard message // Get Success & Error message from inline data, else use standard message
var succesMsg = $("<div class='msg'><i class='fa fa-check'></i> " + dataSucces + "</div>"); var succesMsg = $("<div class='msg'><i class='fa fa-check'></i>&nbsp; " + dataSucces + "</div>");
var errorMsg = $("<div class='msg'><i class='fa fa-exclamation-triangle'></i> " + dataError + "</div>"); var errorMsg = $("<div class='msg'><i class='fa fa-exclamation-triangle'></i>&nbsp; " + dataError + "</div>");
// Check if checkbox is selected // Check if checkbox is selected
if (form) { if (form) {
if ($('td#select input[type=checkbox]').length > 0 && !$('td#select input[type=checkbox]').is(':checked') || if ($('td#select input[type=checkbox]').length > 0 && !$('td#select input[type=checkbox]').is(':checked') ||
@@ -141,7 +141,7 @@ function doAjaxCall(url, elem, reload, form, showMsg, callback) {
$.ajax({ $.ajax({
url: url, url: url,
data: dataString, data: dataString,
type: 'post', type: 'POST',
beforeSend: function (jqXHR, settings) { beforeSend: function (jqXHR, settings) {
// Start loader etc. // Start loader etc.
feedback.prepend(loader); feedback.prepend(loader);
@@ -187,7 +187,7 @@ function doAjaxCall(url, elem, reload, form, showMsg, callback) {
}, },
complete: function (jqXHR, textStatus) { complete: function (jqXHR, textStatus) {
// Remove loaders and stuff, ajax request is complete! // Remove loaders and stuff, ajax request is complete!
feedback.remove('.ajaxLoader-' + url); $('.ajaxLoader-' + url).remove();
if (typeof callback === "function") { if (typeof callback === "function") {
callback(jqXHR); callback(jqXHR);
} }
@@ -351,21 +351,26 @@ function getCookie(cname) {
} }
return ""; return "";
} }
var Accordion = function (el, multiple) { var Accordion = function (el, multiple, close) {
this.el = el || {}; this.el = el || {};
this.multiple = multiple || false; this.multiple = multiple || false;
this.close = (close === undefined) ? true : close;
// Variables privadas // Variables privadas
var links = this.el.find('.link'); var links = this.el.find('.link');
// Evento // Evento
links.on('click', { links.on('click', {
el: this.el, el: this.el,
multiple: this.multiple multiple: this.multiple,
close: this.close
}, this.dropdown); }, this.dropdown);
}; };
Accordion.prototype.dropdown = function (e) { Accordion.prototype.dropdown = function (e) {
var $el = e.data.el; var $el = e.data.el;
$this = $(this); $this = $(this);
$next = $this.next(); $next = $this.next();
if (!e.data.close && $this.parent().hasClass('open')) {
return
}
$next.slideToggle(); $next.slideToggle();
$this.parent().toggleClass('open'); $this.parent().toggleClass('open');
if (!e.data.multiple) { if (!e.data.multiple) {
@@ -465,3 +470,168 @@ function openPlexXML(endpoint, plextv, params) {
window.open(xml_url, '_blank'); window.open(xml_url, '_blank');
}); });
} }
function PopupCenter(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
return newWindow;
}
if (!localStorage.getItem('Tautulli_ClientId')) {
localStorage.setItem('Tautulli_ClientId', uuidv4());
}
function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
var x_plex_headers = {
'Accept': 'application/json',
'X-Plex-Product': 'Tautulli',
'X-Plex-Version': 'Plex OAuth',
'X-Plex-Client-Identifier': localStorage.getItem('Tautulli_ClientId'),
'X-Plex-Platform': platform.name,
'X-Plex-Platform-Version': platform.version,
'X-Plex-Device': platform.os.toString(),
'X-Plex-Device-Name': platform.name
};
var plex_oauth_window = null;
const plex_oauth_loader = '<style>' +
'.login-loader-container {' +
'font-family: "Open Sans", Arial, sans-serif;' +
'position: absolute;' +
'top: 0;' +
'right: 0;' +
'bottom: 0;' +
'left: 0;' +
'}' +
'.login-loader-message {' +
'color: #282A2D;' +
'text-align: center;' +
'position: absolute;' +
'left: 50%;' +
'top: 25%;' +
'transform: translate(-50%, -50%);' +
'}' +
'.login-loader {' +
'border: 5px solid #ccc;' +
'-webkit-animation: spin 1s linear infinite;' +
'animation: spin 1s linear infinite;' +
'border-top: 5px solid #282A2D;' +
'border-radius: 50%;' +
'width: 50px;' +
'height: 50px;' +
'position: relative;' +
'left: calc(50% - 25px);' +
'}' +
'@keyframes spin {' +
'0% { transform: rotate(0deg); }' +
'100% { transform: rotate(360deg); }' +
'}' +
'</style>' +
'<div class="login-loader-container">' +
'<div class="login-loader-message">' +
'<div class="login-loader"></div>' +
'<br>' +
'Redirecting to the Plex login page...' +
'</div>' +
'</div>';
function closePlexOAuthWindow() {
if (plex_oauth_window) {
plex_oauth_window.close();
}
}
getPlexOAuthPin = function () {
var deferred = $.Deferred();
$.ajax({
url: 'https://plex.tv/api/v2/pins?strong=true',
type: 'POST',
headers: x_plex_headers,
success: function(data) {
plex_oauth_window.location = 'https://app.plex.tv/auth/#!?clientID=' + x_plex_headers['X-Plex-Client-Identifier'] + '&code=' + data.code;
deferred.resolve({pin: data.id, code: data.code});
},
error: function() {
closePlexOAuthWindow();
deferred.reject();
}
});
return deferred;
};
var polling = null;
function PlexOAuth(success, error, pre) {
if (typeof pre === "function") {
pre()
}
clearTimeout(polling);
closePlexOAuthWindow();
plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700);
$(plex_oauth_window.document.body).html(plex_oauth_loader);
getPlexOAuthPin().then(function (data) {
const pin = data.pin;
const code = data.code;
var keep_polling = true;
(function poll() {
polling = setTimeout(function () {
$.ajax({
url: 'https://plex.tv/api/v2/pins/' + pin,
type: 'GET',
headers: x_plex_headers,
success: function (data) {
if (data.authToken){
keep_polling = false;
closePlexOAuthWindow();
if (typeof success === "function") {
success(data.authToken)
}
}
},
error: function () {
keep_polling = false;
closePlexOAuthWindow();
if (typeof error === "function") {
error()
}
},
complete: function () {
if (keep_polling){
poll();
} else {
clearTimeout(polling);
}
},
timeout: 1000
});
}, 1000);
})();
}, function () {
closePlexOAuthWindow();
if (typeof error === "function") {
error()
}
});
}

View File

@@ -24,6 +24,7 @@ history_table_options = {
}, },
"pagingType": "full_numbers", "pagingType": "full_numbers",
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"processing": false, "processing": false,
"serverSide": true, "serverSide": true,
"pageLength": 25, "pageLength": 25,
@@ -289,7 +290,7 @@ history_table_options = {
' (filtered from ' + settings.json.total_duration + ' total)</span>'); ' (filtered from ' + settings.json.total_duration + ' total)</span>');
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0); showMsg(msg, false, false, 0);
$('[data-toggle="tooltip"]').tooltip('destroy'); $('[data-toggle="tooltip"]').tooltip('destroy');
$('[data-toggle="popover"]').popover('destroy'); $('[data-toggle="popover"]').popover('destroy');

View File

@@ -148,7 +148,7 @@ history_table_modal_options = {
}); });
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
} }

View File

@@ -17,6 +17,7 @@ libraries_list_table_options = {
"pageLength": 25, "pageLength": 25,
"order": [ 2, 'asc'], "order": [ 2, 'asc'],
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"pagingType": "full_numbers", "pagingType": "full_numbers",
"autoWidth": false, "autoWidth": false,
"scrollX": true, "scrollX": true,
@@ -238,7 +239,7 @@ libraries_list_table_options = {
} }
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
}, },
"rowCallback": function (row, rowData) { "rowCallback": function (row, rowData) {

View File

@@ -10,6 +10,7 @@ login_log_table_options = {
"loadingRecords": '<i class="fa fa-refresh fa-spin"></i> Loading items...</div>' "loadingRecords": '<i class="fa fa-refresh fa-spin"></i> Loading items...</div>'
}, },
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"pagingType": "full_numbers", "pagingType": "full_numbers",
"processing": false, "processing": false,
"serverSide": true, "serverSide": true,
@@ -110,7 +111,7 @@ login_log_table_options = {
}, },
"preDrawCallback": function (settings) { "preDrawCallback": function (settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
}; };

View File

@@ -6,6 +6,7 @@ var log_table_options = {
"order": [ 0, 'desc'], "order": [ 0, 'desc'],
"pageLength": 50, "pageLength": 50,
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"language": { "language": {
"search": "Search: ", "search": "Search: ",
"lengthMenu": "Show _MENU_ lines per page", "lengthMenu": "Show _MENU_ lines per page",
@@ -39,7 +40,7 @@ var log_table_options = {
$('#ajaxMsg').fadeOut(); $('#ajaxMsg').fadeOut();
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
} }

View File

@@ -25,6 +25,7 @@ media_info_table_options = {
}, },
"pagingType": "full_numbers", "pagingType": "full_numbers",
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"processing": false, "processing": false,
"serverSide": true, "serverSide": true,
"pageLength": 25, "pageLength": 25,
@@ -299,7 +300,7 @@ media_info_table_options = {
' (filtered from ' + humanFileSize(settings.json.total_file_size) + ')</span>'); ' (filtered from ' + humanFileSize(settings.json.total_file_size) + ')</span>');
}, },
"preDrawCallback": function (settings) { "preDrawCallback": function (settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
}, },
"rowCallback": function (row, rowData, rowIndex) { "rowCallback": function (row, rowData, rowIndex) {

View File

@@ -6,6 +6,7 @@ newsletter_log_table_options = {
"order": [ 0, 'desc'], "order": [ 0, 'desc'],
"pageLength": 50, "pageLength": 50,
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"language": { "language": {
"search":"Search: ", "search":"Search: ",
"lengthMenu": "Show _MENU_ lines per page", "lengthMenu": "Show _MENU_ lines per page",
@@ -140,7 +141,7 @@ newsletter_log_table_options = {
}); });
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
}; };

View File

@@ -6,6 +6,7 @@ notification_log_table_options = {
"order": [ 0, 'desc'], "order": [ 0, 'desc'],
"pageLength": 50, "pageLength": 50,
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"language": { "language": {
"search":"Search: ", "search":"Search: ",
"lengthMenu": "Show _MENU_ lines per page", "lengthMenu": "Show _MENU_ lines per page",
@@ -110,7 +111,7 @@ notification_log_table_options = {
}); });
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
}; };

View File

@@ -6,6 +6,7 @@ var plex_log_table_options = {
"order": [ 0, 'desc'], "order": [ 0, 'desc'],
"pageLength": 50, "pageLength": 50,
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"language": { "language": {
"search": "Search: ", "search": "Search: ",
"lengthMenu": "Show _MENU_ lines per page", "lengthMenu": "Show _MENU_ lines per page",
@@ -39,7 +40,7 @@ var plex_log_table_options = {
$('#ajaxMsg').fadeOut(); $('#ajaxMsg').fadeOut();
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
} }

View File

@@ -7,6 +7,7 @@ sync_table_options = {
"order": [ [ 0, 'desc'], [ 1, 'asc'], [2, 'asc'] ], "order": [ [ 0, 'desc'], [ 1, 'asc'], [2, 'asc'] ],
"pageLength": 25, "pageLength": 25,
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"language": { "language": {
"search": "Search: ", "search": "Search: ",
"lengthMenu": "Show _MENU_ lines per page", "lengthMenu": "Show _MENU_ lines per page",
@@ -147,7 +148,7 @@ sync_table_options = {
}, },
"preDrawCallback": function (settings) { "preDrawCallback": function (settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
}, },
"rowCallback": function (row, rowData, rowIndex) { "rowCallback": function (row, rowData, rowIndex) {

View File

@@ -10,6 +10,7 @@ user_ip_table_options = {
"loadingRecords": '<i class="fa fa-refresh fa-spin"></i> Loading items...</div>' "loadingRecords": '<i class="fa fa-refresh fa-spin"></i> Loading items...</div>'
}, },
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"pagingType": "full_numbers", "pagingType": "full_numbers",
"processing": false, "processing": false,
"serverSide": true, "serverSide": true,
@@ -141,7 +142,7 @@ user_ip_table_options = {
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
} }

View File

@@ -34,6 +34,7 @@ users_list_table_options = {
"pageLength": 25, "pageLength": 25,
"order": [ 2, 'asc'], "order": [ 2, 'asc'],
"stateSave": true, "stateSave": true,
"stateDuration": 0,
"pagingType": "full_numbers", "pagingType": "full_numbers",
"autoWidth": false, "autoWidth": false,
"scrollX": true, "scrollX": true,
@@ -240,7 +241,7 @@ users_list_table_options = {
} }
}, },
"preDrawCallback": function(settings) { "preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows..."; var msg = "<i class='fa fa-refresh fa-spin'></i>&nbsp; Fetching rows...";
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
}, },
"rowCallback": function (row, rowData) { "rowCallback": function (row, rowData) {

View File

@@ -1,4 +1,8 @@
<!doctype html> <%
import plexpy
plex_login = plexpy.CONFIG.HTTP_PLEX_ADMIN or plexpy.CONFIG.ALLOW_GUEST_ACCESS
%>
<!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -8,7 +12,6 @@
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">
<link href="${http_root}css/bootstrap3/bootstrap.css" rel="stylesheet"> <link href="${http_root}css/bootstrap3/bootstrap.css" rel="stylesheet">
<link href="${http_root}css/pnotify.custom.min.css" rel="stylesheet" />
<link href="${http_root}css/tautulli.css${cache_param}" rel="stylesheet"> <link href="${http_root}css/tautulli.css${cache_param}" rel="stylesheet">
<link href="${http_root}css/opensans.min.css" rel="stylesheet"> <link href="${http_root}css/opensans.min.css" rel="stylesheet">
<link href="${http_root}css/font-awesome.all.min.css" rel="stylesheet"> <link href="${http_root}css/font-awesome.all.min.css" rel="stylesheet">
@@ -32,41 +35,73 @@
<meta name="msapplication-config" content="${http_root}images/favicon/browserconfig.xml?v=2.0.5"> <meta name="msapplication-config" content="${http_root}images/favicon/browserconfig.xml?v=2.0.5">
</head> </head>
<body> <body style="margin: 0; overflow: auto;">
<div class="body-container"> <div class="login-body-container">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="login-container"> <div class="login-container">
<div class="login-logo"> <div class="login-logo">
<img src="${http_root}images/logo-tautulli-100.png" height="100" alt="PlexPy"> <img src="${http_root}images/logo-tautulli-100.png" height="100" alt="Tautulli">
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-6 col-sm-offset-3"> <div class="col-sm-6 col-sm-offset-3">
<form id="login-form"> <div id="sign-in-alert" class="alert alert-danger login-alert"></div>
<div id="incorrect-login" class="alert alert-danger" style="text-align: center; padding: 8px; display: none;"> </div>
Incorrect username or password. </div>
</div> <div class="row">
<div class="form-group"> <div class="col-sm-6 col-sm-offset-3">
<label for="username" class="control-label"> <ul id="login-methods" class="accordion list-unstyled">
Username % if plex_login:
</label> <li class="open">
<input type="text" id="username" name="username" class="form-control" autocorrect="off" autocapitalize="off" autofocus> <div class="link login-method-header">
</div> Sign In with Plex
<div class="form-group">
<label for="password" class="control-label">
Password
</label>
<input type="password" id="password" name="password" class="form-control">
</div>
<div class="form-footer">
<div class="remember-group">
<label class="control-label">
<input type="checkbox" id="remember_me" name="remember_me" title="for 30 days" value="1" checked="checked" /> Remember me
</label>
</div> </div>
<button id="sign-in" type="submit" class="btn btn-bright login-button"><i class="fa fa-sign-in"></i>&nbsp; Sign In</button> <ul class="submenu login-button-plex" style="display: block;">
</div> <li>
</form> <div>
<button id="sign-in-plex" class="btn btn-bright login-button"><i class="fa fa-sign-in"></i>&nbsp; Sign In</button>
</div>
<div class="remember-group">
<label class="control-label">
<input type="checkbox" id="remember_me_plex" name="remember_me_plex" title="for 30 days" value="1" checked="checked" /> Remember me
</label>
</div>
</li>
</ul>
</li>
% endif
<li class="${'open' if not plex_login else ''}">
<div class="link login-method-header">
Sign In with Tautulli
</div>
<ul class="submenu" style="${'display: block;' if not plex_login else ''}">
<li>
<form id="login-form">
<div class="form-group">
<label for="username" class="control-label">
Username
</label>
<input type="text" id="username" name="username" class="form-control" autocorrect="off" autocapitalize="off" autofocus>
</div>
<div class="form-group">
<label for="password" class="control-label">
Password
</label>
<input type="password" id="password" name="password" class="form-control">
</div>
<div class="form-group">
<span class="remember-group">
<label class="control-label">
<input type="checkbox" id="remember_me" name="remember_me" title="for 30 days" value="1" checked="checked" /> Remember me
</label>
</span>
<button id="sign-in" type="submit" class="btn btn-bright login-button"><i class="fa fa-sign-in"></i>&nbsp; Sign In</button>
</div>
</form>
</li>
</ul>
</li>
</ul>
</div> </div>
</div> </div>
</div> </div>
@@ -75,29 +110,76 @@
</div> </div>
<script src="${http_root}js/jquery-2.1.4.min.js"></script> <script src="${http_root}js/jquery-2.1.4.min.js"></script>
<script src="${http_root}js/platform.min.js"></script>
<script src="${http_root}js/script.js${cache_param}"></script>
<script> <script>
var login_accordion = new Accordion($('#login-methods'), false, false);
function OAuthSuccessCallback(authToken) {
signIn(true, authToken);
}
function OAuthErrorCallback() {
$('#sign-in-alert').text('Error communicating with Plex.tv.').show();
}
$('#sign-in-plex').click(function() {
PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback);
});
$('#login-form').submit(function(event) { $('#login-form').submit(function(event) {
event.preventDefault(); event.preventDefault();
$('#sign-in').prop('disabled', true).html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sign In'); signIn(false);
});
function signIn(plex, token) {
$('.login-container button').prop('disabled', true);
if (plex) {
$('#sign-in-plex').html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sign In');
} else {
$('#sign-in').html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sign In');
}
const username = plex ? null : $('#username').val();
const password = plex ? null : $('#password').val();
const remember_me = plex ? ($('#remember_me_plex').is(':checked') ? '1' : '0')
: ($('#remember_me').is(':checked') ? '1' : '0');
var data = {
username: username,
password: password,
token: token,
remember_me: remember_me
};
data = $.extend(data, x_plex_headers);
$.ajax({ $.ajax({
url: '${http_root}auth/signin', url: '${http_root}auth/signin',
type: 'POST', type: 'POST',
data: $(this).serialize(), data: data,
dataType: 'json', dataType: 'json',
statusCode: { statusCode: {
200: function() { 200: function() {
window.location = "${redirect_uri or http_root}"; window.location = "${redirect_uri or http_root}";
}, },
401: function() { 401: function() {
$('#incorrect-login').show(); if (plex) {
$('#username').focus(); $('#sign-in-alert').text('Invalid Plex Login.').show();
} else {
$('#sign-in-alert').text('Incorrect username or password.').show();
$('#username').focus();
}
} }
}, },
complete: function() { complete: function() {
$('#sign-in').prop('disabled', false).html('<i class="fa fa-sign-in"></i>&nbsp; Sign In'); $('.login-container button').prop('disabled', false);
if (plex) {
$('#sign-in-plex').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In');
} else {
$('#sign-in').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In');
}
} }
}); });
}); }
</script> </script>
</body> </body>
</html> </html>

View File

@@ -21,7 +21,7 @@
<div class="row"> <div class="row">
<div class="login-container"> <div class="login-container">
<div class="newsletter-logo"> <div class="newsletter-logo">
<img src="${http_root}images/newsletter/newsletter-header.png" height="100" alt="PlexPy"> <img src="${http_root}images/newsletter/newsletter-header.png" height="100" alt="Tautulli">
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-6 col-sm-offset-3"> <div class="col-sm-6 col-sm-offset-3">

View File

@@ -173,7 +173,11 @@
<input type="text" class="form-control" id="id_name" name="id_name" value="${newsletter['id_name']}" size="30"> <input type="text" class="form-control" id="id_name" name="id_name" value="${newsletter['id_name']}" size="30">
</div> </div>
</div> </div>
<p class="help-block">Optional: Enter a unique ID name to create a static URL to the last sent scheduled newsletter at <span class="inline-pre">${http_root}newsletter/id/&lt;id_name&gt;</span>. Only letters (a-z), numbers (0-9), underscores (_) and hyphens (-) are allowed. Leave blank to disable.</p> <p class="help-block">
Optional: Enter a unique ID name to create a static URL to the <em>last sent scheduled newsletter</em> at <span class="inline-pre">${http_root}newsletter/id/&lt;id_name&gt;</span>.
Only letters (a-z), numbers (0-9), underscores (_) and hyphens (-) are allowed. Leave blank to disable.<br>
Note: Test newsletters are not considered as scheduled newsletters.
</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="friendly_name">Description</label> <label for="friendly_name">Description</label>
@@ -218,6 +222,13 @@
<input type="hidden" id="newsletter_config_formatted" name="newsletter_config_formatted" value="${newsletter['config']['formatted']}"> <input type="hidden" id="newsletter_config_formatted" name="newsletter_config_formatted" value="${newsletter['config']['formatted']}">
</div> </div>
<div class="form-group" id="email_notifier_select"> <div class="form-group" id="email_notifier_select">
<div class="checkbox">
<label>
<input type="checkbox" id="newsletter_config_threaded_checkbox" data-id="newsletter_config_threaded" class="checkboxes" value="1" ${checked(newsletter['config']['threaded'])}> Enable Grouped Email Thread
</label>
<p class="help-block">Enable to group this newsletter together in a single Email thread. Disable to send a new Email for each newsletter.</p>
<input type="hidden" id="newsletter_config_threaded" name="newsletter_config_threaded" value="${newsletter['config']['threaded']}">
</div>
<label for="newsletter_email_notifier_id">Email Notification Agent</label> <label for="newsletter_email_notifier_id">Email Notification Agent</label>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
@@ -766,9 +777,12 @@
// auto resizing textarea for custom notification message body // auto resizing textarea for custom notification message body
$('textarea[data-autoresize]').each(function () { $('textarea[data-autoresize]').each(function () {
var modal_body = $(this).closest('.modal-body');
var offset = this.offsetHeight - this.clientHeight; var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function (el) { var resizeTextarea = function (el) {
var modal_offset = modal_body.scrollTop();
$(el).css('height', 'auto').css('height', el.scrollHeight + offset); $(el).css('height', 'auto').css('height', el.scrollHeight + offset);
modal_body.scrollTop(modal_offset);
}; };
$(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize'); $(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize');
}); });

View File

@@ -21,7 +21,13 @@
<li role="presentation" class="active"><a href="#tabs-notifier_config" aria-controls="tabs-notifier_config" role="tab" data-toggle="tab">Configuration</a></li> <li role="presentation" class="active"><a href="#tabs-notifier_config" aria-controls="tabs-notifier_config" role="tab" data-toggle="tab">Configuration</a></li>
<li role="presentation"><a href="#tabs-notify_triggers" aria-controls="tabs-notify_triggers" role="tab" data-toggle="tab">Triggers</a></li> <li role="presentation"><a href="#tabs-notify_triggers" aria-controls="tabs-notify_triggers" role="tab" data-toggle="tab">Triggers</a></li>
<li role="presentation"><a href="#tabs-notify_conditions" aria-controls="tabs-notify_conditions" role="tab" data-toggle="tab">Conditions</a></li> <li role="presentation"><a href="#tabs-notify_conditions" aria-controls="tabs-notify_conditions" role="tab" data-toggle="tab">Conditions</a></li>
<li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">${'Arguments' if notifier['agent_name'] == 'scripts' else 'Text'}</a></li> % if notifier['agent_name'] == 'scripts':
<li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">Arguments</a></li>
% elif notifier['agent_name'] == 'webhook':
<li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">Data</a></li>
% else:
<li role="presentation"><a href="#tabs-notify_text" aria-controls="tabs-notify_text" role="tab" data-toggle="tab">Text</a></li>
% endif
<li role="presentation"><a href="#tabs-test_notifications" aria-controls="tabs-test_notifications" role="tab" data-toggle="tab">Test Notifications</a></li> <li role="presentation"><a href="#tabs-test_notifications" aria-controls="tabs-test_notifications" role="tab" data-toggle="tab">Test Notifications</a></li>
</ul> </ul>
</div> </div>
@@ -184,6 +190,8 @@
<p class="help-block"> <p class="help-block">
% if notifier['agent_name'] == 'scripts': % if notifier['agent_name'] == 'scripts':
Set the custom arguments passed to the script for each type of notification. Set the custom arguments passed to the script for each type of notification.
% elif notifier['agent_name'] == 'webhook':
Set the custom JSON data sent to the webhook for each type of notification.
% else: % else:
Set the custom formatted text for each type of notification. Set the custom formatted text for each type of notification.
% endif % endif
@@ -225,6 +233,32 @@
</ul> </ul>
</li> </li>
% endfor % endfor
% elif notifier['agent_name'] == 'webhook':
% for action in available_notification_actions:
<li>
<div class="link">
<span class="toggle-left"><i class="fa ${action['icon']} fa-fw"></i></span>&nbsp;
${action['label']}
<span class="toggle-right"><i class="fa fa-chevron-down"></i></span>
</div>
<ul class="submenu">
<li>
<div class="form-group">
<label for="${action['name']}_body">JSON Data</label>
<textarea class="form-control" id="${action['name']}_body" name="${action['name']}_body" data-parsley-trigger="change" data-autoresize required>${notifier['notify_text'][action['name']]['body']}</textarea>
<p class="help-block">Set custom JSON data.</p>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-12">
<input type="button" class="btn btn-bright notifier-text-preview" data-action="${action['name']}" value="Preview JSON Data">
</div>
</div>
</div>
</li>
</ul>
</li>
% endfor
% else: % else:
% for action in available_notification_actions: % for action in available_notification_actions:
<li> <li>
@@ -291,6 +325,16 @@
</div> </div>
<p class="help-block">Set custom arguments passed to the script.</p> <p class="help-block">Set custom arguments passed to the script.</p>
</div> </div>
% elif notifier['agent_name'] == 'webhook':
<div class="form-group">
<label for="test_body">JSON Data</label>
<div class="row">
<div class="col-md-12">
<textarea class="form-control" id="test_body" name="test_body" data-autoresize></textarea>
</div>
</div>
<p class="help-block">Set custom JSON data sent to the webhook.</p>
</div>
% else: % else:
<div class="form-group"> <div class="form-group">
<label for="test_subject">Subject Line</label> <label for="test_subject">Subject Line</label>
@@ -305,7 +349,7 @@
<label for="test_body">Message Body</label> <label for="test_body">Message Body</label>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<input class="form-control" type="text" id="test_body" name="test_body" value="Test notification"> <textarea class="form-control" id="test_body" name="test_body" data-autoresize>Test Notification</textarea>
</div> </div>
</div> </div>
<p class="help-block">Set a custom body.</p> <p class="help-block">Set a custom body.</p>
@@ -735,6 +779,7 @@
$.ajax({ $.ajax({
url: 'get_notify_text_preview', url: 'get_notify_text_preview',
type: 'POST',
data: { data: {
notify_action: action, notify_action: action,
subject: subject, subject: subject,
@@ -811,9 +856,12 @@
// auto resizing textarea for custom notification message body // auto resizing textarea for custom notification message body
$('textarea[data-autoresize]').each(function () { $('textarea[data-autoresize]').each(function () {
var modal_body = $(this).closest('.modal-body');
var offset = this.offsetHeight - this.clientHeight; var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function (el) { var resizeTextarea = function (el) {
var modal_offset = modal_body.scrollTop();
$(el).css('height', 'auto').css('height', el.scrollHeight + offset); $(el).css('height', 'auto').css('height', el.scrollHeight + offset);
modal_body.scrollTop(modal_offset);
}; };
$(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize'); $(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize');
}); });

View File

@@ -9,7 +9,9 @@
% for item in text: % for item in text:
<div style="padding-bottom: 10px;"> <div style="padding-bottom: 10px;">
<h4>${item['media_type'].capitalize()}</h4> <h4>${item['media_type'].capitalize()}</h4>
% if agent != 'webhook':
<pre>${item['subject']}</pre> <pre>${item['subject']}</pre>
% endif
% if agent != 'scripts': % if agent != 'scripts':
<pre>${item['body']}</pre> <pre>${item['body']}</pre>
% endif % endif

View File

@@ -33,7 +33,7 @@
<button id="menu_link_show_advanced_settings" class="btn btn-dark"><i class="fa fa-wrench"></i> Show Advanced</button> <button id="menu_link_show_advanced_settings" class="btn btn-dark"><i class="fa fa-wrench"></i> Show Advanced</button>
% endif % endif
% if config['check_github']: % if config['check_github']:
<button id="menu_link_update_check" class="btn btn-dark"><i class="fa fa-arrow-circle-up"></i> Check for Updates</button> <button id="menu_link_update_check" class="btn btn-dark"><i class="fa fa-arrow-alt-circle-up"></i> Check for Updates</button>
% endif % endif
<button id="menu_link_restart" class="btn btn-dark"><i class="fa fa-refresh"></i> Restart</button> <button id="menu_link_restart" class="btn btn-dark"><i class="fa fa-refresh"></i> Restart</button>
<button id="menu_link_shutdown" class="btn btn-dark"><i class="fa fa-power-off"></i> Shutdown</button> <button id="menu_link_shutdown" class="btn btn-dark"><i class="fa fa-power-off"></i> Shutdown</button>
@@ -430,6 +430,14 @@
</div> </div>
<p class="help-block">Note: Web interface changes require a restart.</p> <p class="help-block">Note: Web interface changes require a restart.</p>
% if os.name == 'nt':
<div class="checkbox">
<label>
<input type="checkbox" class="http-settings" name="win_sys_tray" id="win_sys_tray" value="1" ${config['win_sys_tray']}> Enable System Tray Icon
</label>
<p class="help-block">Show Tautulli shortcut in the system tray.</p>
</div>
% endif
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="launch_browser" id="launch_browser" value="1" ${config['launch_browser']}> Launch Browser on Startup <input type="checkbox" name="launch_browser" id="launch_browser" value="1" ${config['launch_browser']}> Launch Browser on Startup
@@ -650,12 +658,20 @@
</div> </div>
<div class="form-group has-feedback" id="pms_ip_group"> <div class="form-group has-feedback" id="pms_ip_group">
<label for="pms_ip">Plex IP Address or Hostname</label> <label for="pms_ip_selectize">Plex IP Address or Hostname</label>
<div class="row"> <div class="row">
<div class="col-md-9" id="selectize-pms-ip-container"> <div class="col-md-9" id="selectize-pms-ip-container">
<div class="input-group"> <div class="input-group">
<select class="form-control pms-settings selectize-pms-ip" id="pms_ip" name="pms_ip" data-parsley-trigger="change" aria-describedby="server-verified" data-parsley-errors-container="#pms_ip_error" required> <select class="form-control pms-settings selectize-pms-ip" id="pms_ip_selectize" data-parsley-trigger="change" aria-describedby="server-verified" data-parsley-errors-container="#pms_ip_error" required>
<option value="${config['pms_ip']}" selected>${config['pms_ip']}</option> <option value="${config['pms_ip']}:${config['pms_port']}"
data-identifier="${config['pms_identifier']}"
data-ip="${config['pms_ip']}"
data-port="${config['pms_port']}"
data-local="${int(not int(config['pms_is_remote']))}"
data-ssl="${config['pms_ssl']}"
data-is_cloud="${config['pms_is_cloud']}"
data-label="${config['pms_name'] or 'Local'}"
selected>${config['pms_ip']}</option>
</select> </select>
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-form" type="button" id="verify_server_button">Verify Server</button> <button class="btn btn-form" type="button" id="verify_server_button">Verify Server</button>
@@ -738,6 +754,7 @@
</p> </p>
</div> </div>
<input type="hidden" id="pms_ip" name="pms_ip" value="${config['pms_ip']}">
<input type="hidden" id="pms_is_cloud" name="pms_is_cloud" value="${config['pms_is_cloud']}"> <input type="hidden" id="pms_is_cloud" name="pms_is_cloud" value="${config['pms_is_cloud']}">
<input type="checkbox" name="server_changed" id="server_changed" value="1" style="display: none;"> <input type="checkbox" name="server_changed" id="server_changed" value="1" style="display: none;">
@@ -842,21 +859,23 @@
<h3>Plex.tv Authentication</h3> <h3>Plex.tv Authentication</h3>
</div> </div>
<div class="form-group"> <div class="form-group has-feedback">
<label for="pms_token">Plex.tv Account Token</label> <label for="pms_token">Plex.tv Account Token</label>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" id="pms_token" name="pms_token" value="${config['pms_token']}" data-parsley-trigger="change" data-parsley-errors-container="#pms_token_error" required> <input type="text" class="form-control" id="pms_token" name="pms_token" value="${config['pms_token']}" data-parsley-trigger="change" data-parsley-errors-container="#pms_token_error" required>
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-form" type="button" data-toggle="modal" data-target="#pms-auth-modal">Fetch Token</button> <button id="sign-in-plex" class="btn btn-form" type="button">Fetch Token</button>
</span> </span>
</div> </div>
<span class="form-control-feedback" id="token_verify" aria-hidden="true" style="right: 80px;"></span>
</div> </div>
<div id="pms_token_error" class="alert alert-danger settings-alert" role="alert"></div> <div id="pms_token_error" class="alert alert-danger settings-alert" role="alert"></div>
</div> </div>
<p class="help-block">Token for Plex.tv authentication.</p> <p class="help-block">Token for Plex.tv authentication.</p>
</div> </div>
<input type="hidden" id="pms_uuid" name="pms_uuid" value="${config['pms_uuid']}">
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p> <p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
@@ -1366,49 +1385,6 @@
</div> </div>
</div> </div>
</div> </div>
<div id="pms-auth-modal" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="ip-info-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
<h4 class="modal-title">Fetch Plex.tv Token</h4>
</div>
<div class="modal-body" id="modal-text">
<div>
<p class="help-block">
This will attempt to fetch a new Plex.tv token for you. Tautulli does not store your username and password.
Note: This will not work on Internet Explorer 9 or lower.
</p>
<div class="form-group">
<label for="pms_username">Plex.tv Username</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="pms_username" name="pms_username" size="30">
</div>
</div>
<p class="help-block">Username for Plex.tv authentication.</p>
</div>
<div class="form-group">
<label for="pms_password">Plex.tv Password</label>
<div class="row">
<div class="col-md-6">
<input type="password" class="form-control" id="pms_password" name="pms_password" size="30">
</div>
</div>
<p class="help-block">Password for Plex.tv authentication.</p>
</div>
</div>
</div>
<div class="modal-footer">
<div style="float: left;">
<strong><span id="pms-token-status"></span></strong>
</div>
<input type="button" id="get-pms-auth-token" class="btn btn-bright" value="Fetch Token">
</div>
</div>
</div>
</div>
<div id="app-import-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="app-import-modal"></div> <div id="app-import-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="app-import-modal"></div>
<div id="add-notifier-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="add-notifier-modal"> <div id="add-notifier-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="add-notifier-modal">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
@@ -1961,7 +1937,7 @@ $(document).ready(function() {
$('#menu_link_update_check').click(function() { $('#menu_link_update_check').click(function() {
$(this).html('<i class="fa fa-spin fa-refresh"></i> Checking').prop('disabled', true); $(this).html('<i class="fa fa-spin fa-refresh"></i> Checking').prop('disabled', true);
checkUpdate(function () { checkUpdate(function () {
$('#menu_link_update_check').html('<i class="fa fa-arrow-circle-up"></i> Check for Updates') $('#menu_link_update_check').html('<i class="fa fa-arrow-alt-circle-up"></i> Check for Updates')
.prop('disabled', false); .prop('disabled', false);
}); });
}); });
@@ -2094,7 +2070,7 @@ $(document).ready(function() {
} }
}); });
var $select_pms = $('#pms_ip').selectize({ var $select_pms = $('#pms_ip_selectize').selectize({
createOnBlur: true, createOnBlur: true,
openOnFocus: true, openOnFocus: true,
maxItems: 1, maxItems: 1,
@@ -2105,13 +2081,19 @@ $(document).ready(function() {
dropdownParent: '#selectize-pms-ip-container', dropdownParent: '#selectize-pms-ip-container',
render: { render: {
item: function (item, escape) { item: function (item, escape) {
if (!item.label) {
$.extend(item,
$(this.revertSettings.$children)
.filter('[value=' + item.value + ']').data()
);
}
var label = item.label || item.value; var label = item.label || item.value;
var caption = item.label ? item.value : null; var caption = item.label ? item.ip : null;
return '<div data-ssl="' + item.httpsRequired + return '<div data-identifier="' + item.clientIdentifier +
'" data-local="' + item.local +
'" data-identifier="' + item.clientIdentifier +
'" data-ip="' + item.ip + '" data-ip="' + item.ip +
'" data-port="' + item.port + '" data-port="' + item.port +
'" data-local="' + item.local +
'" data-ssl="' + item.httpsRequired +
'" data-is_cloud="' + item.is_cloud + '" data-is_cloud="' + item.is_cloud +
'" data-label="' + item.label + '">' + '" data-label="' + item.label + '">' +
'<span class="item-text">' + escape(label) + '</span>' + '<span class="item-text">' + escape(label) + '</span>' +
@@ -2121,11 +2103,11 @@ $(document).ready(function() {
option: function (item, escape) { option: function (item, escape) {
var label = item.label || item.value; var label = item.label || item.value;
var caption = item.label ? item.value : null; var caption = item.label ? item.value : null;
return '<div data-ssl="' + item.httpsRequired + return '<div data-identifier="' + item.clientIdentifier +
'" data-local="' + item.local +
'" data-identifier="' + item.clientIdentifier +
'" data-ip="' + item.ip + '" data-ip="' + item.ip +
'" data-port="' + item.port + '" data-port="' + item.port +
'" data-local="' + item.local +
'" data-ssl="' + item.httpsRequired +
'" data-is_cloud="' + item.is_cloud + '" data-is_cloud="' + item.is_cloud +
'" data-label="' + item.label + '">' + '" data-label="' + item.label + '">' +
escape(label) + escape(label) +
@@ -2136,15 +2118,24 @@ $(document).ready(function() {
create: function(input) { create: function(input) {
return {label: '', value: input}; return {label: '', value: input};
}, },
onInitialize: function () {
var s = this;
this.revertSettings.$children.each(function () {
$.extend(s.options[this.value], $(this).data());
});
},
onChange: function (item) { onChange: function (item) {
var pms_ip_selected = this.getItem(item)[0]; var pms_ip_selected = this.getItem(item)[0];
var identifier = $(pms_ip_selected).data('identifier'); var identifier = $(pms_ip_selected).data('identifier');
var ip = $(pms_ip_selected).data('ip');
var port = $(pms_ip_selected).data('port'); var port = $(pms_ip_selected).data('port');
var local = $(pms_ip_selected).data('local'); var local = $(pms_ip_selected).data('local');
var ssl = $(pms_ip_selected).data('ssl'); var ssl = $(pms_ip_selected).data('ssl');
var is_cloud = $(pms_ip_selected).data('is_cloud'); var is_cloud = $(pms_ip_selected).data('is_cloud');
var value = $(pms_ip_selected).data('value');
$("#pms_identifier").val(identifier !== 'undefined' ? identifier : ''); $("#pms_identifier").val(identifier !== 'undefined' ? identifier : '');
$('#pms_ip').val(ip !== 'undefined' ? ip : value);
$('#pms_port').val(port !== 'undefined' ? port : 32400); $('#pms_port').val(port !== 'undefined' ? port : 32400);
$('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0)); $('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0));
$('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0); $('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0);
@@ -2169,9 +2160,10 @@ $(document).ready(function() {
}, },
success: function (result) { success: function (result) {
if (result) { if (result) {
var existing_value = $('#pms_ip').val(); var existing_ip = $('#pms_ip').val();
var existing_port = $('#pms_port').val();
result.forEach(function (item) { result.forEach(function (item) {
if (item.value === existing_value) { if (item.ip === existing_ip && item.port === existing_port) {
select_pms.updateOption(item.value, item); select_pms.updateOption(item.value, item);
} else { } else {
select_pms.addOption(item); select_pms.addOption(item);
@@ -2296,40 +2288,21 @@ $(document).ready(function() {
window.open(pms_web_url, '_blank'); window.open(pms_web_url, '_blank');
}); });
// Plex.tv auth token fetch function OAuthPreFunction() {
$("#get-pms-auth-token").click(function() { $("#token_verify").html('<i class="fa fa-refresh fa-spin"></i>').fadeIn('fast');
$("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i> Fetching token...'); }
var pms_username = $.trim($("#pms_username").val()); function OAuthSuccessCallback(authToken) {
var pms_password = $.trim($("#pms_password").val()); $("#pms_token").val(authToken);
if ((pms_username !== '') && (pms_password !== '')) { $("#pms_uuid").val(x_plex_headers['X-Plex-Client-Identifier']);
$.ajax({ $("#token_verify").html('<i class="fa fa-check"></i>').fadeIn('fast');
type: 'GET', getServerOptions(authToken);
url: 'get_plexpy_pms_token', }
data: { function OAuthErrorCallback() {
username: pms_username, $("#token_verify").html('<i class="fa fa-close"></i>').fadeIn('fast');
password: pms_password, }
force: true
}, $('#sign-in-plex').click(function() {
cache: false, PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback, OAuthPreFunction);
async: true,
complete: function(xhr, status) {
var result = $.parseJSON(xhr.responseText);
var msg = result.message;
if (result.result == 'success') {
var authToken = result.token;
$("#pms-token-status").html('<i class="fa fa-check"></i> ' + msg);
$("#pms_token").val(authToken);
$('#pms-auth-modal').modal('hide');
getServerOptions(authToken);
} else {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> ' + msg);
}
loadUpdateDistros();
}
});
} else {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Username and password required.');
}
}); });
// Load database import modal // Load database import modal

View File

@@ -60,7 +60,7 @@
$('#popout-iframe-button').click(function () { $('#popout-iframe-button').click(function () {
var iframe = $('#support-iframe'); var iframe = $('#support-iframe');
popout_chat = window.open(iframe.data('src'), 'Tautulli-Discord-Support', 'width=1280,height=720'); popout_chat = PopupCenter(iframe.data('src'), 'Tautulli-Discord-Support', 1280, 720);
iframe.attr('src', '').fadeOut(); iframe.attr('src', '').fadeOut();
$('.iframe-overlay').fadeIn(); $('.iframe-overlay').fadeIn();
}); });

View File

@@ -203,8 +203,8 @@ DOCUMENTATION :: END
$('#confirm-modal-update').modal(); $('#confirm-modal-update').modal();
$('#confirm-modal-update').one('click', '#confirm-update', function () { $('#confirm-modal-update').one('click', '#confirm-update', function () {
$(this).prop('disabled', true); $(this).prop('disabled', true);
var msg = '<i class="fa fa-refresh fa-spin"></i>&nbspUpdating database...' var msg = '<i class="fa fa-refresh fa-spin"></i>&nbsp; Updating database...';
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0);
$.ajax({ $.ajax({
url: 'update_metadata_details', url: 'update_metadata_details',

View File

@@ -52,51 +52,53 @@
<form> <form>
<div class="wizard-card" data-cardname="card1"> <div class="wizard-card" data-cardname="card1">
<div style="float: right;"> <div style="float: right;">
<img src="${http_root}images/logo-tautulli-45.png" height="45" alt="PlexPy"> <img src="${http_root}images/logo-tautulli-45.png" height="45" alt="Tautulli">
</div> </div>
<h3 style="line-height: 50px;">Welcome!</h3> <h3 style="line-height: 50px;">Welcome!</h3>
<br /> <div class="wizard-input-section">
<div> <p class="welcome-message">
Thanks for taking the time to try out Tautulli. Hope you find it useful. Thanks for taking the time to try out Tautulli. Hope you find it useful.
<br /><br /> </p>
Tautulli requires a permanent internet connection to ensure a reliable experience. <p class="welcome-message">
<br /><br /> Tautulli requires a permanent internet connection to ensure a reliable experience.
This wizard will help you get set up, to continue press Next. </p>
<p class="welcome-message">
This wizard will help you get set up, to continue press Next.
</p>
</div> </div>
</div> </div>
<div class="wizard-card" data-cardname="card2"> <div class="wizard-card" data-cardname="card2">
<h3>Plex Authentication</h3> <h3>Plex Authentication</h3>
<p class="help-block">Enter your Plex.tv username and password. Tautulli does not store your username or password.</p>
<div class="wizard-input-section"> <div class="wizard-input-section">
<label for="pms_username">Plex.tv Username</label> <p class="help-block">
<div class="row"> Tautulli requires a Plex.tv account. Click the button below to sign in on Plex.tv. You may need to allow popups in your browser.
<div class="col-xs-8"> </p>
<input type="text" class="form-control pms-auth" id="pms_username" placeholder="" required>
</div>
</div>
</div> </div>
<div class="wizard-input-section"> <input type="hidden" class="form-control" name="pms_token" id="pms_token" value="" data-validate="validatePMStoken">
<label for="pms_password">Plex.tv Password</label> <a class="btn btn-dark" id="sign-in-plex" href="#" role="button">Sign In with Plex</a>
<div class="row"> <span style="margin-left: 10px; display: none;" id="pms-token-status"></span>
<div class="col-xs-8">
<input type="password" class="form-control pms-auth" id="pms_password" placeholder="" required>
</div>
</div>
</div>
<input type="hidden" class="form-control pms-auth" name="pms_token" id="pms_token" value="" data-validate="validatePMStoken">
<a class="btn btn-dark" id="pms-authenticate" href="#" role="button">Authenticate</a><span style="margin-left: 10px; display: none;" id="pms-token-status"></span>
</div> </div>
<div class="wizard-card" data-cardname="card3"> <div class="wizard-card" data-cardname="card3">
<h3>Plex Media Server</h3> <h3>Plex Media Server</h3>
<p class="help-block">
Select your Plex Media Server from the dropdown menu or enter an IP address or hostname.
</p>
<div class="wizard-input-section"> <div class="wizard-input-section">
<label for="pms_ip">Plex IP or Hostname</label> <p class="help-block">
Select your Plex Media Server from the dropdown menu or enter an IP address or hostname.
</p>
</div>
<div class="wizard-input-section">
<label for="pms_ip_selectize">Plex IP Address or Hostname</label>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<select class="form-control pms-settings selectize-pms-ip" id="pms_ip" name="pms_ip"> <select class="form-control pms-settings selectize-pms-ip" id="pms_ip_selectize">
<option value="${config['pms_ip']}" selected>${config['pms_ip']}</option> <option value="${config['pms_ip']}:${config['pms_port']}"
data-identifier="${config['pms_identifier']}"
data-ip="${config['pms_ip']}"
data-port="${config['pms_port']}"
data-local="${int(not int(config['pms_is_remote']))}"
data-ssl="${config['pms_ssl']}"
data-is_cloud="${config['pms_is_cloud']}"
data-label="${config['pms_name'] or 'Local'}"
selected>${config['pms_ip']}</option>
</select> </select>
</div> </div>
</div> </div>
@@ -126,15 +128,20 @@
</div> </div>
</div> </div>
<input type="hidden" id="pms_valid" data-validate="validatePMSip" value=""> <input type="hidden" id="pms_valid" data-validate="validatePMSip" value="">
<input type="hidden" id="pms_ip" name="pms_ip" value="${config['pms_ip']}">
<input type="hidden" id="pms_is_cloud" name="pms_is_cloud" value="${config['pms_is_cloud']}"> <input type="hidden" id="pms_is_cloud" name="pms_is_cloud" value="${config['pms_is_cloud']}">
<input type="hidden" id="pms_identifier" name="pms_identifier" value="${config['pms_identifier']}"> <input type="hidden" id="pms_identifier" name="pms_identifier" value="${config['pms_identifier']}">
<a class="btn btn-dark" id="verify-plex-server" href="#" role="button">Verify</a><span style="margin-left: 10px; display: none;" id="pms-verify-status"></span> <a class="btn btn-dark" id="verify-plex-server" href="#" role="button">Verify</a>
<span style="margin-left: 10px; display: none;" id="pms-verify-status"></span>
</div> </div>
<div class="wizard-card" data-cardname="card4"> <div class="wizard-card" data-cardname="card4">
<h3>Activity Logging</h3> <h3>Activity Logging</h3>
<p class="help-block">Tautulli will keep a history of all streaming activity on your Plex server.</p> <div class="wizard-input-section">
<p class="help-block">
Tautulli will keep a history of all streaming activity on your Plex server.
</p>
</div>
<div class="wizard-input-section"> <div class="wizard-input-section">
<label for="logging_ignore_interval">Ignore Interval</label> <label for="logging_ignore_interval">Ignore Interval</label>
<div class="row"> <div class="row">
@@ -145,29 +152,38 @@
</div> </div>
<p class="help-block">The interval (in seconds) an item must be in a playing state before logging it. 0 to disable.</p> <p class="help-block">The interval (in seconds) an item must be in a playing state before logging it. 0 to disable.</p>
</div> </div>
<div class="wizard-input-section">
<p class="help-block"> <p class="help-block">
Additional options to disable history logging for certain libraries or users can be found by editing them Additional options to disable history logging for certain libraries or users can be found by editing them
on the <strong>Libraries</strong> or <strong>Users</strong> pages. on the <strong>Libraries</strong> or <strong>Users</strong> pages.
</p> </p>
</div>
</div> </div>
<div class="wizard-card" data-cardname="card4"> <div class="wizard-card" data-cardname="card4">
<h3>Notifications</h3> <h3>Notifications</h3>
<p class="help-block">Tautulli can send a wide variety of notifications to alert you of activity on your Plex server.</p> <div class="wizard-input-section">
<p class="help-block"> <p class="help-block">
To set up a notification agent, navigate to the <strong>Settings</strong> page Tautulli can send a wide variety of notifications to alert you of activity on your Plex server.
and to the <strong>Notification Agents</strong> tab after you have completed this setup wizard. </p>
</p> <p class="help-block">
To set up a notification agent, navigate to the <strong>Settings</strong> page
and to the <strong>Notification Agents</strong> tab after you have completed this setup wizard.
</p>
</div>
</div> </div>
<div class="wizard-card" data-cardname="card5"> <div class="wizard-card" data-cardname="card5">
<h3>Database Import</h3> <h3>Database Import</h3>
<p class="help-block">If you have an existing PlexWatch/Plexivity database, you can import the data into Tautulli.</p> <div class="wizard-input-section">
<p class="help-block"> <p class="help-block">
To import a database, navigate to the <strong>Settings</strong> page If you have an existing PlexWatch/Plexivity database, you can import the data into Tautulli.
and to the <strong>Import & Backups</strong> tab after you have completed this setup wizard. </p>
</p> <p class="help-block">
To import a database, navigate to the <strong>Settings</strong> page
and to the <strong>Import & Backups</strong> tab after you have completed this setup wizard.
</p>
</div>
<!-- Required fields but hidden --> <!-- Required fields but hidden -->
<div style="display: none;"> <div style="display: none;">
@@ -205,6 +221,7 @@
<script src="${http_root}js/jquery-2.1.4.min.js"></script> <script src="${http_root}js/jquery-2.1.4.min.js"></script>
<script src="${http_root}js/bootstrap.min.js"></script> <script src="${http_root}js/bootstrap.min.js"></script>
<script src="${http_root}js/selectize.min.js"></script> <script src="${http_root}js/selectize.min.js"></script>
<script src="${http_root}js/platform.min.js"></script>
<script src="${http_root}js/script.js${cache_param}"></script> <script src="${http_root}js/script.js${cache_param}"></script>
<script src="${http_root}js/bootstrap-wizard.min.js"></script> <script src="${http_root}js/bootstrap-wizard.min.js"></script>
<script> <script>
@@ -306,7 +323,7 @@ $(document).ready(function() {
} }
}); });
var $select_pms = $('#pms_ip').selectize({ var $select_pms = $('#pms_ip_selectize').selectize({
createOnBlur: true, createOnBlur: true,
openOnFocus: true, openOnFocus: true,
maxItems: 1, maxItems: 1,
@@ -316,13 +333,19 @@ $(document).ready(function() {
inputClass: 'form-control selectize-input', inputClass: 'form-control selectize-input',
render: { render: {
item: function (item, escape) { item: function (item, escape) {
if (!item.label) {
$.extend(item,
$(this.revertSettings.$children)
.filter('[value=' + item.value + ']').data()
);
}
var label = item.label || item.value; var label = item.label || item.value;
var caption = item.label ? item.value : null; var caption = item.label ? item.ip : null;
return '<div data-ssl="' + item.httpsRequired + return '<div data-identifier="' + item.clientIdentifier +
'" data-local="' + item.local +
'" data-identifier="' + item.clientIdentifier +
'" data-ip="' + item.ip + '" data-ip="' + item.ip +
'" data-port="' + item.port + '" data-port="' + item.port +
'" data-local="' + item.local +
'" data-ssl="' + item.httpsRequired +
'" data-is_cloud="' + item.is_cloud + '" data-is_cloud="' + item.is_cloud +
'" data-label="' + item.label + '">' + '" data-label="' + item.label + '">' +
'<span class="item-text">' + escape(label) + '</span>' + '<span class="item-text">' + escape(label) + '</span>' +
@@ -332,11 +355,11 @@ $(document).ready(function() {
option: function (item, escape) { option: function (item, escape) {
var label = item.label || item.value; var label = item.label || item.value;
var caption = item.label ? item.value : null; var caption = item.label ? item.value : null;
return '<div data-ssl="' + item.httpsRequired + return '<div data-identifier="' + item.clientIdentifier +
'" data-local="' + item.local +
'" data-identifier="' + item.clientIdentifier +
'" data-ip="' + item.ip + '" data-ip="' + item.ip +
'" data-port="' + item.port + '" data-port="' + item.port +
'" data-local="' + item.local +
'" data-ssl="' + item.httpsRequired +
'" data-is_cloud="' + item.is_cloud + '" data-is_cloud="' + item.is_cloud +
'" data-label="' + item.label + '">' + '" data-label="' + item.label + '">' +
escape(label) + escape(label) +
@@ -347,18 +370,27 @@ $(document).ready(function() {
create: function(input) { create: function(input) {
return {label: '', value: input}; return {label: '', value: input};
}, },
onInitialize: function () {
var s = this;
this.revertSettings.$children.each(function () {
$.extend(s.options[this.value], $(this).data());
});
},
onChange: function (item) { onChange: function (item) {
var pms_ip_selected = this.getItem(item)[0]; var pms_ip_selected = this.getItem(item)[0];
var identifier = $(pms_ip_selected).data('identifier'); var identifier = $(pms_ip_selected).data('identifier');
var ip = $(pms_ip_selected).data('ip');
var port = $(pms_ip_selected).data('port'); var port = $(pms_ip_selected).data('port');
var local = $(pms_ip_selected).data('local'); var local = $(pms_ip_selected).data('local');
var ssl = $(pms_ip_selected).data('ssl'); var ssl = $(pms_ip_selected).data('ssl');
var is_cloud = $(pms_ip_selected).data('is_cloud'); var is_cloud = $(pms_ip_selected).data('is_cloud');
var value = $(pms_ip_selected).data('value');
$("#pms_valid").val(identifier !== 'undefined' ? 'valid' : ''); $("#pms_valid").val(identifier !== 'undefined' ? 'valid' : '');
$("#pms-verify-status").html(identifier !== 'undefined' ? '<i class="fa fa-check"></i> Server found!' : '').fadeIn('fast'); $("#pms-verify-status").html(identifier !== 'undefined' ? '<i class="fa fa-check"></i>&nbsp; Server found!' : '').fadeIn('fast');
$("#pms_identifier").val(identifier !== 'undefined' ? identifier : ''); $("#pms_identifier").val(identifier !== 'undefined' ? identifier : '');
$('#pms_ip').val(ip !== 'undefined' ? ip : value);
$('#pms_port').val(port !== 'undefined' ? port : 32400); $('#pms_port').val(port !== 'undefined' ? port : 32400);
$('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0)); $('#pms_is_remote_checkbox').prop('checked', (local !== 'undefined' && local === 0));
$('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0); $('#pms_is_remote').val(local !== 'undefined' && local === 0 ? 1 : 0);
@@ -391,9 +423,10 @@ $(document).ready(function() {
}, },
success: function (result) { success: function (result) {
if (result) { if (result) {
var existing_value = $('#pms_ip').val(); var existing_ip = $('#pms_ip').val();
var existing_port = $('#pms_port').val();
result.forEach(function (item) { result.forEach(function (item) {
if (item.value === existing_value) { if (item.ip === existing_ip && item.port === existing_port) {
select_pms.updateOption(item.value, item); select_pms.updateOption(item.value, item);
} else { } else {
select_pms.addOption(item); select_pms.addOption(item);
@@ -414,7 +447,7 @@ $(document).ready(function() {
var pms_ssl = $("#pms_ssl").val(); var pms_ssl = $("#pms_ssl").val();
var pms_is_remote = $("#pms_is_remote").val(); var pms_is_remote = $("#pms_is_remote").val();
if ((pms_ip !== '') || (pms_port !== '')) { if ((pms_ip !== '') || (pms_port !== '')) {
$("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i> Validating server...'); $("#pms-verify-status").html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Validating server...');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
$.ajax({ $.ajax({
url: 'get_server_id', url: 'get_server_id',
@@ -429,7 +462,7 @@ $(document).ready(function() {
async: true, async: true,
timeout: 5000, timeout: 5000,
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> This is not a Plex Server!'); $("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i>&nbsp; This is not a Plex Server!');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
}, },
success: function(xhr, status) { success: function(xhr, status) {
@@ -437,18 +470,18 @@ $(document).ready(function() {
var identifier = result.identifier; var identifier = result.identifier;
if (identifier) { if (identifier) {
$("#pms_identifier").val(identifier); $("#pms_identifier").val(identifier);
$("#pms-verify-status").html('<i class="fa fa-check"></i> Server found!'); $("#pms-verify-status").html('<i class="fa fa-check"></i>&nbsp; Server found!');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
pms_verified = true; pms_verified = true;
$("#pms_valid").val("valid"); $("#pms_valid").val("valid");
} else { } else {
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> This is not a Plex Server!'); $("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i>&nbsp; This is not a Plex Server!');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
} }
} }
}); });
} else { } else {
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> Please enter both fields.'); $("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i>&nbsp; Please enter both fields.');
$('#pms-verify-status').fadeIn('fast'); $('#pms-verify-status').fadeIn('fast');
} }
} }
@@ -460,47 +493,22 @@ $(document).ready(function() {
$("#pms-verify-status").html(""); $("#pms-verify-status").html("");
}); });
$( ".pms-auth" ).change(function() { function OAuthPreFunction() {
authenticated = false; $("#pms_token").val('');
$("#pms_token").val(""); $("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Waiting for authentication...').fadeIn('fast');
$("#pms-token-status").html(""); }
}); function OAuthSuccessCallback(authToken) {
$("#pms_token").val(authToken);
$("#pms-token-status").html('<i class="fa fa-check"></i>&nbsp; Authentication successful.').fadeIn('fast');
authenticated = true;
getServerOptions(authToken);
}
function OAuthErrorCallback() {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i>&nbsp; Error communicating with Plex.tv.').fadeIn('fast');
}
// Plex.tv auth token fetch $('#sign-in-plex').click(function() {
$("#pms-authenticate").click(function() { PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback, OAuthPreFunction);
$("#pms-token-status").html('<i class="fa fa-refresh fa-spin"></i> Fetching token...');
$('#pms-token-status').fadeIn('fast');
var pms_username = $("#pms_username").val().trim();
var pms_password = $("#pms_password").val().trim();
if ((pms_username !== '') && (pms_password !== '')) {
$.ajax({
type: 'GET',
url: 'get_plexpy_pms_token',
data: {
username: pms_username,
password: pms_password
},
cache: false,
async: true,
complete: function (xhr, status) {
var result = $.parseJSON(xhr.responseText);
var msg = result.message;
if (result.result == 'success') {
var authToken = result.token;
$("#pms-token-status").html('<i class="fa fa-check"></i> ' + msg);
$('#pms-token-status').fadeIn('fast');
$("#pms_token").val(authToken);
authenticated = true;
getServerOptions(authToken)
} else {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> ' + msg);
}
}
});
} else {
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Username and password required.');
$('#pms-token-status').fadeIn('fast');
}
}); });
}); });
</script> </script>

View File

@@ -691,7 +691,7 @@
<img src="${(base_url_image + 'images/libraries/show.png') if base_url_image else 'https://tautulli.com/images/libraries/show.png'}" class="sub-header-icon" width="30" height="30" style="border: none;-ms-interpolation-mode: bicubic;max-width: 100%;height: 30px;width: 30px;vertical-align: middle;margin-right: 5px;margin-bottom: 5px;"> Recently Added TV Shows <img src="${(base_url_image + 'images/libraries/show.png') if base_url_image else 'https://tautulli.com/images/libraries/show.png'}" class="sub-header-icon" width="30" height="30" style="border: none;-ms-interpolation-mode: bicubic;max-width: 100%;height: 30px;width: 30px;vertical-align: middle;margin-right: 5px;margin-bottom: 5px;"> Recently Added TV Shows
</div> </div>
<div class="sub-header-count" style="margin-left: auto;margin-right: auto;font-size: 30px;text-align: center;"> <div class="sub-header-count" style="margin-left: auto;margin-right: auto;font-size: 30px;text-align: center;">
<span class="count" style="color: #E5A00D;">${len(recently_added['show'])}</span> <span class="count-units" style="color: #aaaaaa;font-size: 20px;text-transform: uppercase;">show${'s' if len(recently_added['show']) > 1 else ''}</span> / <span class="count" style="color: #E5A00D;">${len(recently_added['show'])}</span> <span class="count-units" style="color: #aaaaaa;font-size: 20px;text-transform: uppercase;">show${'s' if len(recently_added['show']) > 1 else ''}</span>&nbsp;/&nbsp;
<% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %> <% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %>
<span class="count" style="color: #E5A00D;">${total_episodes}</span> <span class="count-units" style="color: #aaaaaa;font-size: 20px;text-transform: uppercase;">episode${'s' if total > 1 else ''}</span> <span class="count" style="color: #E5A00D;">${total_episodes}</span> <span class="count-units" style="color: #aaaaaa;font-size: 20px;text-transform: uppercase;">episode${'s' if total > 1 else ''}</span>
</div> </div>
@@ -744,7 +744,7 @@
<td class="card-info-body" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-size: 0.75rem;vertical-align: top;padding: 5px;height: 100%;"> <td class="card-info-body" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-size: 0.75rem;vertical-align: top;padding: 5px;height: 100%;">
<p class="nowrap mb5" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;margin-bottom: 5px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;max-width: 325px;color: #ffffff;"> <p class="nowrap mb5" style="font-family: 'Open Sans', Helvetica, Arial, sans-serif;font-weight: 400;margin: 0;margin-bottom: 5px;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;max-width: 325px;color: #ffffff;">
% if show['season_count'] > 1: % if show['season_count'] > 1:
<em>${show['season_count']} seasons /</em> <em>${show['season_count']} seasons&nbsp;/&nbsp;</em>
% endif % endif
<% total_show_episodes = sum(s['episode_count'] for s in show['season']) %> <% total_show_episodes = sum(s['episode_count'] for s in show['season']) %>
<em>${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''}</em> <em>${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''}</em>
@@ -759,7 +759,8 @@
% if i < min(show['season_count'], 7): % if i < min(show['season_count'], 7):
<br> <br>
% elif i == 7 and show['season_count'] > 8: % elif i == 7 and show['season_count'] > 8:
...plus ${show['season_count'] - 8} more seasons! <% remaining_seasons = show['season_count'] - 8 %>
...plus ${remaining_seasons} more season${'s' if remaining_seasons > 1 else ''}!
% endif % endif
% endfor % endfor
</p> </p>

View File

@@ -692,7 +692,7 @@
<img src="${(base_url_image + 'images/libraries/show.png') if base_url_image else 'https://tautulli.com/images/libraries/show.png'}" class="sub-header-icon" width="30" height="30"/> Recently Added TV Shows <img src="${(base_url_image + 'images/libraries/show.png') if base_url_image else 'https://tautulli.com/images/libraries/show.png'}" class="sub-header-icon" width="30" height="30"/> Recently Added TV Shows
</div> </div>
<div class="sub-header-count"> <div class="sub-header-count">
<span class="count">${len(recently_added['show'])}</span> <span class="count-units">show${'s' if len(recently_added['show']) > 1 else ''}</span> / <span class="count">${len(recently_added['show'])}</span> <span class="count-units">show${'s' if len(recently_added['show']) > 1 else ''}</span>&nbsp;/&nbsp;
<% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %> <% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %>
<span class="count">${total_episodes}</span> <span class="count-units">episode${'s' if total > 1 else ''}</span> <span class="count">${total_episodes}</span> <span class="count-units">episode${'s' if total > 1 else ''}</span>
</div> </div>
@@ -745,7 +745,7 @@
<td class="card-info-body"> <td class="card-info-body">
<p class="nowrap mb5"> <p class="nowrap mb5">
% if show['season_count'] > 1: % if show['season_count'] > 1:
<em>${show['season_count']} seasons /</em> <em>${show['season_count']} seasons&nbsp;/&nbsp;</em>
% endif % endif
<% total_show_episodes = sum(s['episode_count'] for s in show['season']) %> <% total_show_episodes = sum(s['episode_count'] for s in show['season']) %>
<em>${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''}</em> <em>${total_show_episodes} episode${'s' if total_show_episodes > 1 else ''}</em>
@@ -760,7 +760,8 @@
% if i < min(show['season_count'], 7): % if i < min(show['season_count'], 7):
<br> <br>
% elif i == 7 and show['season_count'] > 8: % elif i == 7 and show['season_count'] > 8:
...plus ${show['season_count'] - 8} more seasons! <% remaining_seasons = show['season_count'] - 8 %>
...plus ${remaining_seasons} more season${'s' if remaining_seasons > 1 else ''}!
% endif % endif
% endfor % endfor
</p> </p>

View File

@@ -4,51 +4,54 @@
# #
# INSTALLATION NOTES # INSTALLATION NOTES
# #
# 1. Rename this file as you want, ensuring that it ends in .service # 1. Copy this file into your systemd service unit directory (often '/lib/systemd/system')
# e.g. 'tautulli.service' # and name it 'tautulli.service' with the following command:
# cp /opt/Tautulli/init-scripts/init.systemd /lib/systemd/system/tautulli.service
# #
# 2. Adjust configuration settings as required. More details in the # 2. Edit the new tautulli.service file with configuration settings as required.
# "CONFIGURATION NOTES" section shown below. # More details in the "CONFIGURATION NOTES" section shown below.
# #
# 3. Copy this file into your systemd service unit directory, which is # 3. Enable boot-time autostart with the following commands:
# often '/lib/systemd/system'.
#
# 4. Enable boot-time autostart with the following commands:
# systemctl daemon-reload # systemctl daemon-reload
# systemctl enable tautulli.service # systemctl enable tautulli.service
# #
# 5. Start now with the following command: # 4. Start now with the following command:
# systemctl start tautulli.service # systemctl start tautulli.service
# #
# CONFIGURATION NOTES # CONFIGURATION NOTES
# #
# - The example settings in this file assume that you will run Tautulli as user: tautulli # - The example settings in this file assume that you will run Tautulli as user: tautulli
# - To create this user and give it ownership of the tautulli directory: # - The example settings in this file assume that Tautulli is installed to: /opt/Tautulli
# sudo adduser --system --no-create-home tautulli
# sudo chown tautulli:nogroup -R /opt/Tautulli
# #
# - Option names (e.g. ExecStart=, Type=) appear to be case-sensitive) # - To create this user and give it ownership of the Tautulli directory:
# sudo adduser --system --no-create-home tautulli
# sudo chown tautulli:tautulli -R /opt/Tautulli
# #
# - Adjust ExecStart= to point to: # - Adjust ExecStart= to point to:
# 1. Your Tautulli executable, # 1. Your Tautulli executable
# - Default: /opt/Tautulli/Tautulli.py
# 2. Your config file (recommended is to put it somewhere in /etc) # 2. Your config file (recommended is to put it somewhere in /etc)
# - Default: --config /opt/Tautulli/config.ini
# 3. Your datadir (recommended is to NOT put it in your Tautulli exec dir) # 3. Your datadir (recommended is to NOT put it in your Tautulli exec dir)
# - Default: --datadir /opt/Tautulli
# #
# - Adjust User= and Group= to the user/group you want Tautulli to run as. # - Adjust User= and Group= to the user/group you want Tautulli to run as.
# #
# - WantedBy= specifies which target (i.e. runlevel) to start Tautulli for. # - WantedBy= specifies which target (i.e. runlevel) to start Tautulli for.
# multi-user.target equates to runlevel 3 (multi-user text mode) # multi-user.target equates to runlevel 3 (multi-user text mode)
# graphical.target equates to runlevel 5 (multi-user X11 graphical mode) # graphical.target equates to runlevel 5 (multi-user X11 graphical mode)
[Unit] [Unit]
Description=Tautulli - Stats for Plex Media Server usage Description=Tautulli - Stats for Plex Media Server usage
Wants=network-online.target
After=network-online.target
[Service] [Service]
ExecStart=/opt/Tautulli/Tautulli.py --quiet --daemon --nolaunch --config /opt/Tautulli/config.ini --datadir /opt/Tautulli ExecStart=/opt/Tautulli/Tautulli.py --config /opt/Tautulli/config.ini --datadir /opt/Tautulli --quiet --daemon --nolaunch
GuessMainPID=no GuessMainPID=no
Type=forking Type=forking
User=tautulli User=tautulli
Group=nogroup Group=tautlli
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -1,127 +0,0 @@
# Copyright (c) 2009 Raymond Hettinger
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__end
except AttributeError:
self.clear()
self.update(*args, **kwds)
def clear(self):
self.__end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.__map = {} # key --> [key, prev, next]
dict.clear(self)
def __setitem__(self, key, value):
if key not in self:
end = self.__end
curr = end[1]
curr[2] = end[1] = self.__map[key] = [key, curr, end]
dict.__setitem__(self, key, value)
def __delitem__(self, key):
dict.__delitem__(self, key)
key, prev, next = self.__map.pop(key)
prev[2] = next
next[1] = prev
def __iter__(self):
end = self.__end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]
def __reversed__(self):
end = self.__end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]
def popitem(self, last=True):
if not self:
raise KeyError('dictionary is empty')
if last:
key = reversed(self).next()
else:
key = iter(self).next()
value = self.pop(key)
return key, value
def __reduce__(self):
items = [[k, self[k]] for k in self]
tmp = self.__map, self.__end
del self.__map, self.__end
inst_dict = vars(self).copy()
self.__map, self.__end = tmp
if inst_dict:
return (self.__class__, (items,), inst_dict)
return self.__class__, (items,)
def keys(self):
return list(self)
setdefault = DictMixin.setdefault
update = DictMixin.update
pop = DictMixin.pop
values = DictMixin.values
items = DictMixin.items
iterkeys = DictMixin.iterkeys
itervalues = DictMixin.itervalues
iteritems = DictMixin.iteritems
def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, self.items())
def copy(self):
return self.__class__(self)
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
return dict.__eq__(self, other)
def __ne__(self, other):
return not self == other

File diff suppressed because it is too large Load Diff

2
lib/systray/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
__import__("pkg_resources").declare_namespace(__name__)
from .traybar import SysTrayIcon

314
lib/systray/traybar.py Normal file
View File

@@ -0,0 +1,314 @@
import os
from .win32_adapter import *
import threading
import uuid
class SysTrayIcon(object):
"""
menu_options: tuple of tuples (menu text, menu icon path or None, function name)
menu text and tray hover text should be Unicode
hover_text length is limited to 128; longer text will be truncated
Can be used as context manager to enable automatic termination of tray
if parent thread is closed:
with SysTrayIcon(icon, hover_text) as systray:
for item in ['item1', 'item2', 'item3']:
systray.update(hover_text=item)
do_something(item)
"""
QUIT = 'QUIT'
SPECIAL_ACTIONS = [QUIT]
FIRST_ID = 1023
def __init__(self,
icon,
hover_text,
menu_options=None,
on_quit=None,
default_menu_index=None,
window_class_name=None):
self._icon = icon
self._icon_shared = False
self._hover_text = hover_text
self._on_quit = on_quit
menu_options = menu_options or ()
menu_options = menu_options + (('Quit', None, SysTrayIcon.QUIT, None),)
self._next_action_id = SysTrayIcon.FIRST_ID
self._menu_actions_by_id = set()
self._menu_options = self._add_ids_to_menu_options(list(menu_options))
self._menu_actions_by_id = dict(self._menu_actions_by_id)
window_class_name = window_class_name or ("SysTrayIconPy-%s" % (str(uuid.uuid4())))
self._default_menu_index = (default_menu_index or 0)
self._window_class_name = encode_for_locale(window_class_name)
self._message_dict = {RegisterWindowMessage("TaskbarCreated"): self._restart,
WM_DESTROY: self._destroy,
WM_CLOSE: self._destroy,
WM_COMMAND: self._command,
WM_USER+20: self._notify}
self._notify_id = None
self._message_loop_thread = None
self._hwnd = None
self._hicon = 0
self._hinst = None
self._window_class = None
self._menu = None
self._register_class()
def __enter__(self):
"""Context manager so SysTray can automatically close"""
self.start()
return self
def __exit__(self, *args):
"""Context manager so SysTray can automatically close"""
self.shutdown()
def WndProc(self, hwnd, msg, wparam, lparam):
hwnd = HANDLE(hwnd)
wparam = WPARAM(wparam)
lparam = LPARAM(lparam)
if msg in self._message_dict:
self._message_dict[msg](hwnd, msg, wparam.value, lparam.value)
return DefWindowProc(hwnd, msg, wparam, lparam)
def _register_class(self):
# Register the Window class.
self._window_class = WNDCLASS()
self._hinst = self._window_class.hInstance = GetModuleHandle(None)
self._window_class.lpszClassName = self._window_class_name
self._window_class.style = CS_VREDRAW | CS_HREDRAW
self._window_class.hCursor = LoadCursor(0, IDC_ARROW)
self._window_class.hbrBackground = COLOR_WINDOW
self._window_class.lpfnWndProc = LPFN_WNDPROC(self.WndProc)
RegisterClass(ctypes.byref(self._window_class))
def _create_window(self):
style = WS_OVERLAPPED | WS_SYSMENU
self._hwnd = CreateWindowEx(0, self._window_class_name,
self._window_class_name,
style,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
self._hinst,
None)
UpdateWindow(self._hwnd)
self._refresh_icon()
def _message_loop_func(self):
self._create_window()
PumpMessages()
def start(self):
if self._hwnd:
return # already started
self._message_loop_thread = threading.Thread(target=self._message_loop_func)
self._message_loop_thread.start()
def shutdown(self):
if not self._hwnd:
return # not started
PostMessage(self._hwnd, WM_CLOSE, 0, 0)
self._message_loop_thread.join()
def update(self, icon=None, hover_text=None):
""" update icon image and/or hover text """
if icon:
self._icon = icon
self._load_icon()
if hover_text:
self._hover_text = hover_text
self._refresh_icon()
def _add_ids_to_menu_options(self, menu_options):
result = []
for menu_option in menu_options:
option_text, option_icon, option_action, option_state = menu_option
if callable(option_action) or option_action in SysTrayIcon.SPECIAL_ACTIONS:
self._menu_actions_by_id.add((self._next_action_id, option_action))
result.append(menu_option + (self._next_action_id,))
elif option_action == 'separator':
result.append((option_text,
option_icon,
option_action,
option_state,
self._next_action_id))
elif non_string_iterable(option_action):
result.append((option_text,
option_icon,
option_state,
self._add_ids_to_menu_options(option_action),
self._next_action_id))
else:
raise Exception('Unknown item', option_text, option_icon, option_action)
self._next_action_id += 1
return result
def _load_icon(self):
# release previous icon, if a custom one was loaded
# note: it's important *not* to release the icon if we loaded the default system icon (with
# the LoadIcon function) - this is why we assign self._hicon only if it was loaded using LoadImage
if not self._icon_shared and self._hicon != 0:
DestroyIcon(self._hicon)
self._hicon = 0
# Try and find a custom icon
hicon = 0
if self._icon is not None and os.path.isfile(self._icon):
icon_flags = LR_LOADFROMFILE | LR_DEFAULTSIZE
icon = encode_for_locale(self._icon)
hicon = self._hicon = LoadImage(0, icon, IMAGE_ICON, 0, 0, icon_flags)
self._icon_shared = False
# Can't find icon file - using default shared icon
if hicon == 0:
self._hicon = LoadIcon(0, IDI_APPLICATION)
self._icon_shared = True
self._icon = None
def _refresh_icon(self):
if self._hwnd is None:
return
if self._hicon == 0:
self._load_icon()
if self._notify_id:
message = NIM_MODIFY
else:
message = NIM_ADD
self._notify_id = NotifyData(self._hwnd,
0,
NIF_ICON | NIF_MESSAGE | NIF_TIP,
WM_USER+20,
self._hicon,
self._hover_text)
Shell_NotifyIcon(message, ctypes.byref(self._notify_id))
def _restart(self, hwnd, msg, wparam, lparam):
self._refresh_icon()
def _destroy(self, hwnd, msg, wparam, lparam):
if self._on_quit:
self._on_quit(self)
nid = NotifyData(self._hwnd, 0)
Shell_NotifyIcon(NIM_DELETE, ctypes.byref(nid))
PostQuitMessage(0) # Terminate the app.
# TODO * release self._menu with DestroyMenu and reset the memeber
# * release self._hicon with DestoryIcon and reset the member
# * release loaded menu icons (loaded in _load_menu_icon) with DeleteObject
# (we don't keep those objects anywhere now)
self._hwnd = None
self._notify_id = None
def _notify(self, hwnd, msg, wparam, lparam):
if lparam == WM_LBUTTONDBLCLK:
self._execute_menu_option(self._default_menu_index + SysTrayIcon.FIRST_ID)
elif lparam == WM_RBUTTONUP:
self._show_menu()
elif lparam == WM_LBUTTONUP:
pass
return True
def _show_menu(self):
if self._menu is None:
self._menu = CreatePopupMenu()
self._create_menu(self._menu, self._menu_options)
#SetMenuDefaultItem(self._menu, 1000, 0)
pos = POINT()
GetCursorPos(ctypes.byref(pos))
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
SetForegroundWindow(self._hwnd)
TrackPopupMenu(self._menu,
TPM_LEFTALIGN,
pos.x,
pos.y,
0,
self._hwnd,
None)
PostMessage(self._hwnd, WM_NULL, 0, 0)
def _create_menu(self, menu, menu_options):
for option_text, option_icon, option_action, option_state, option_id in menu_options[::-1]:
if option_icon:
option_icon = self._prep_menu_icon(option_icon)
mi_fstate = 0
mi_ftype = 0
if option_state == 'default':
mi_fstate = mi_fstate | MFS_DEFAULT
if option_state == 'highlight':
mi_fstate = mi_fstate | MFS_HILITE
if option_state == 'disabled':
mi_fstate = mi_fstate | MFS_DISABLED
if option_action == 'separator':
mi_ftype = mi_ftype | MFT_SEPARATOR
if isinstance(option_action, tuple):
submenu = CreatePopupMenu()
self._create_menu(submenu, option_action)
item = PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
hSubMenu=submenu)
InsertMenuItem(menu, 0, 1, ctypes.byref(item))
else:
item = PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
wID=option_id,
fState=mi_fstate,
fType=mi_ftype)
InsertMenuItem(menu, 0, 1, ctypes.byref(item))
def _prep_menu_icon(self, icon):
icon = encode_for_locale(icon)
# First load the icon.
ico_x = GetSystemMetrics(SM_CXSMICON)
ico_y = GetSystemMetrics(SM_CYSMICON)
hicon = LoadImage(0, icon, IMAGE_ICON, ico_x, ico_y, LR_LOADFROMFILE)
hdcBitmap = CreateCompatibleDC(None)
hdcScreen = GetDC(None)
hbm = CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)
hbmOld = SelectObject(hdcBitmap, hbm)
# Fill the background.
brush = GetSysColorBrush(COLOR_MENU)
FillRect(hdcBitmap, ctypes.byref(RECT(0, 0, 16, 16)), brush)
# draw the icon
DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, DI_NORMAL)
SelectObject(hdcBitmap, hbmOld)
# No need to free the brush
DeleteDC(hdcBitmap)
DestroyIcon(hicon)
return hbm
def _command(self, hwnd, msg, wparam, lparam):
id = LOWORD(wparam)
self._execute_menu_option(id)
def _execute_menu_option(self, id):
menu_action = self._menu_actions_by_id[id]
if menu_action == SysTrayIcon.QUIT:
DestroyWindow(self._hwnd)
else:
menu_action(self)
def non_string_iterable(obj):
try:
iter(obj)
except TypeError:
return False
else:
return not isinstance(obj, str)

View File

@@ -0,0 +1,199 @@
import ctypes
import ctypes.wintypes
import locale
import sys
RegisterWindowMessage = ctypes.windll.user32.RegisterWindowMessageA
LoadCursor = ctypes.windll.user32.LoadCursorA
LoadIcon = ctypes.windll.user32.LoadIconA
LoadImage = ctypes.windll.user32.LoadImageA
RegisterClass = ctypes.windll.user32.RegisterClassA
CreateWindowEx = ctypes.windll.user32.CreateWindowExA
UpdateWindow = ctypes.windll.user32.UpdateWindow
DefWindowProc = ctypes.windll.user32.DefWindowProcA
GetSystemMetrics = ctypes.windll.user32.GetSystemMetrics
InsertMenuItem = ctypes.windll.user32.InsertMenuItemA
PostMessage = ctypes.windll.user32.PostMessageA
PostQuitMessage = ctypes.windll.user32.PostQuitMessage
SetMenuDefaultItem = ctypes.windll.user32.SetMenuDefaultItem
GetCursorPos = ctypes.windll.user32.GetCursorPos
SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow
TrackPopupMenu = ctypes.windll.user32.TrackPopupMenu
CreatePopupMenu = ctypes.windll.user32.CreatePopupMenu
CreateCompatibleDC = ctypes.windll.gdi32.CreateCompatibleDC
GetDC = ctypes.windll.user32.GetDC
CreateCompatibleBitmap = ctypes.windll.gdi32.CreateCompatibleBitmap
GetSysColorBrush = ctypes.windll.user32.GetSysColorBrush
FillRect = ctypes.windll.user32.FillRect
DrawIconEx = ctypes.windll.user32.DrawIconEx
SelectObject = ctypes.windll.gdi32.SelectObject
DeleteDC = ctypes.windll.gdi32.DeleteDC
DestroyWindow = ctypes.windll.user32.DestroyWindow
GetModuleHandle = ctypes.windll.kernel32.GetModuleHandleA
GetMessage = ctypes.windll.user32.GetMessageA
TranslateMessage = ctypes.windll.user32.TranslateMessage
DispatchMessage = ctypes.windll.user32.DispatchMessageA
Shell_NotifyIcon = ctypes.windll.shell32.Shell_NotifyIcon
DestroyIcon = ctypes.windll.user32.DestroyIcon
NIM_ADD = 0
NIM_MODIFY = 1
NIM_DELETE = 2
NIF_ICON = 2
NIF_MESSAGE = 1
NIF_TIP = 4
MIIM_STATE = 1
MIIM_ID = 2
MIIM_SUBMENU = 4
MIIM_STRING = 64
MIIM_BITMAP = 128
MIIM_FTYPE = 256
WM_DESTROY = 2
WM_CLOSE = 16
WM_COMMAND = 273
WM_USER = 1024
WM_LBUTTONDBLCLK = 515
WM_RBUTTONUP = 517
WM_LBUTTONUP = 514
WM_NULL = 0
CS_VREDRAW = 1
CS_HREDRAW = 2
IDC_ARROW = 32512
COLOR_WINDOW = 5
WS_OVERLAPPED = 0
WS_SYSMENU = 524288
CW_USEDEFAULT = -2147483648
LR_LOADFROMFILE = 16
LR_DEFAULTSIZE = 64
IMAGE_ICON = 1
IDI_APPLICATION = 32512
TPM_LEFTALIGN = 0
SM_CXSMICON = 49
SM_CYSMICON = 50
COLOR_MENU = 4
DI_NORMAL = 3
MFS_DISABLED = 3
MFS_DEFAULT = 4096
MFS_HILITE = 128
MFT_SEPARATOR = 2048
WPARAM = ctypes.wintypes.WPARAM
LPARAM = ctypes.wintypes.LPARAM
HANDLE = ctypes.wintypes.HANDLE
if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p):
LRESULT = ctypes.c_long
elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p):
LRESULT = ctypes.c_longlong
SZTIP_MAX_LENGTH = 128
LOCALE_ENCODING = locale.getpreferredencoding()
def encode_for_locale(s):
"""
Encode text items for system locale. If encoding fails, fall back to ASCII.
"""
try:
return s.encode(LOCALE_ENCODING, 'ignore')
except (AttributeError, UnicodeDecodeError):
return s.decode('ascii', 'ignore').encode(LOCALE_ENCODING)
POINT = ctypes.wintypes.POINT
RECT = ctypes.wintypes.RECT
MSG = ctypes.wintypes.MSG
LPFN_WNDPROC = ctypes.CFUNCTYPE(LRESULT, HANDLE, ctypes.c_uint, WPARAM, LPARAM)
class WNDCLASS(ctypes.Structure):
_fields_ = [("style", ctypes.c_uint),
("lpfnWndProc", LPFN_WNDPROC),
("cbClsExtra", ctypes.c_int),
("cbWndExtra", ctypes.c_int),
("hInstance", HANDLE),
("hIcon", HANDLE),
("hCursor", HANDLE),
("hbrBackground", HANDLE),
("lpszMenuName", ctypes.c_char_p),
("lpszClassName", ctypes.c_char_p),
]
class MENUITEMINFO(ctypes.Structure):
_fields_ = [("cbSize", ctypes.c_uint),
("fMask", ctypes.c_uint),
("fType", ctypes.c_uint),
("fState", ctypes.c_uint),
("wID", ctypes.c_uint),
("hSubMenu", HANDLE),
("hbmpChecked", HANDLE),
("hbmpUnchecked", HANDLE),
("dwItemData", ctypes.c_void_p),
("dwTypeData", ctypes.c_char_p),
("cch", ctypes.c_uint),
("hbmpItem", HANDLE),
]
class NOTIFYICONDATA(ctypes.Structure):
_fields_ = [("cbSize", ctypes.c_uint),
("hWnd", HANDLE),
("uID", ctypes.c_uint),
("uFlags", ctypes.c_uint),
("uCallbackMessage", ctypes.c_uint),
("hIcon", HANDLE),
("szTip", ctypes.c_char * SZTIP_MAX_LENGTH),
("dwState", ctypes.c_uint),
("dwStateMask", ctypes.c_uint),
("szInfo", ctypes.c_char * 256),
("uTimeout", ctypes.c_uint),
("szInfoTitle", ctypes.c_char * 64),
("dwInfoFlags", ctypes.c_uint),
("guidItem", ctypes.c_char * 16),
]
if sys.getwindowsversion().major >= 5:
_fields_.append(("hBalloonIcon", HANDLE))
def PackMENUITEMINFO(text=None, hbmpItem=None, wID=None, hSubMenu=None,
fType=None, fState=None):
res = MENUITEMINFO()
res.cbSize = ctypes.sizeof(res)
res.fMask = 0
if hbmpItem is not None:
res.fMask |= MIIM_BITMAP
res.hbmpItem = hbmpItem
if wID is not None:
res.fMask |= MIIM_ID
res.wID = wID
if text is not None:
text = encode_for_locale(text)
res.fMask |= MIIM_STRING
res.dwTypeData = text
if hSubMenu is not None:
res.fMask |= MIIM_SUBMENU
res.hSubMenu = hSubMenu
if fType is not None:
res.fMask |= MIIM_FTYPE
res.fType = fType
if fState is not None:
res.fMask |= MIIM_STATE
res.fState = fState
return res
def LOWORD(w):
return w & 0xFFFF
def PumpMessages():
msg = MSG()
while GetMessage(ctypes.byref(msg), None, 0, 0) > 0:
TranslateMessage(ctypes.byref(msg))
DispatchMessage(ctypes.byref(msg))
def NotifyData(hWnd=0, uID=0, uFlags=0, uCallbackMessage=0, hIcon=0, szTip=""):
szTip = encode_for_locale(szTip)[:SZTIP_MAX_LENGTH]
res = NOTIFYICONDATA()
res.cbSize = ctypes.sizeof(res)
res.hWnd = hWnd
res.uID = uID
res.uFlags = uFlags
res.uCallbackMessage = uCallbackMessage
res.hIcon = hIcon
res.szTip = szTip
return res

View File

@@ -92,9 +92,11 @@ LATEST_VERSION = None
COMMITS_BEHIND = None COMMITS_BEHIND = None
PREV_RELEASE = None PREV_RELEASE = None
LATEST_RELEASE = None LATEST_RELEASE = None
UPDATE_AVAILABLE = False
UMASK = None UMASK = None
HTTP_PORT = None
HTTP_ROOT = None HTTP_ROOT = None
DEV = False DEV = False
@@ -105,6 +107,8 @@ PLEX_SERVER_UP = None
TRACKER = None TRACKER = None
WIN_SYS_TRAY_ICON = None
def initialize(config_file): def initialize(config_file):
with INIT_LOCK: with INIT_LOCK:
@@ -163,6 +167,15 @@ def initialize(config_file):
logger.info(u"Python {}".format( logger.info(u"Python {}".format(
sys.version sys.version
)) ))
logger.info(u"Program Dir: {}".format(
PROG_DIR
))
logger.info(u"Config File: {}".format(
CONFIG_FILE
))
logger.info(u"Database File: {}".format(
DB_FILE
))
if not CONFIG.BACKUP_DIR: if not CONFIG.BACKUP_DIR:
CONFIG.BACKUP_DIR = os.path.join(DATA_DIR, 'backups') CONFIG.BACKUP_DIR = os.path.join(DATA_DIR, 'backups')
@@ -256,7 +269,7 @@ def initialize(config_file):
# Check for new versions # Check for new versions
if CONFIG.CHECK_GITHUB_ON_STARTUP and CONFIG.CHECK_GITHUB: if CONFIG.CHECK_GITHUB_ON_STARTUP and CONFIG.CHECK_GITHUB:
try: try:
LATEST_VERSION = versioncheck.check_github() LATEST_VERSION = versioncheck.check_update()
except: except:
logger.exception(u"Unhandled exception") logger.exception(u"Unhandled exception")
LATEST_VERSION = CURRENT_VERSION LATEST_VERSION = CURRENT_VERSION
@@ -378,6 +391,51 @@ def launch_browser(host, port, root):
logger.error(u"Could not launch browser: %s" % e) logger.error(u"Could not launch browser: %s" % e)
def win_system_tray():
from systray import SysTrayIcon
def tray_open(sysTrayIcon):
launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT, plexpy.HTTP_ROOT)
def tray_check_update(sysTrayIcon):
versioncheck.check_update()
def tray_update(sysTrayIcon):
if plexpy.UPDATE_AVAILABLE:
plexpy.SIGNAL = 'update'
else:
hover_text = common.PRODUCT + ' - No Update Available'
plexpy.WIN_SYS_TRAY_ICON.update(hover_text=hover_text)
def tray_restart(sysTrayIcon):
plexpy.SIGNAL = 'restart'
def tray_quit(sysTrayIcon):
plexpy.SIGNAL = 'shutdown'
if plexpy.UPDATE_AVAILABLE:
icon = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images/logo_tray-update.ico')
hover_text = common.PRODUCT + ' - Update Available!'
else:
icon = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images/logo_tray.ico')
hover_text = common.PRODUCT
menu_options = (('Open Tautulli', None, tray_open, 'default'),
('', None, 'separator', None),
('Check for Updates', None, tray_check_update, None),
('Update', None, tray_update, None),
('Restart', None, tray_restart, None))
logger.info(u"Launching system tray icon.")
try:
plexpy.WIN_SYS_TRAY_ICON = SysTrayIcon(icon, hover_text, menu_options, on_quit=tray_quit)
plexpy.WIN_SYS_TRAY_ICON.start()
except Exception as e:
logger.error(u"Unable to launch system tray icon: %s." % e)
plexpy.WIN_SYS_TRAY_ICON = None
def initialize_scheduler(): def initialize_scheduler():
""" """
Start the scheduled background tasks. Re-schedule if interval settings changed. Start the scheduled background tasks. Re-schedule if interval settings changed.
@@ -391,7 +449,7 @@ def initialize_scheduler():
# Update check # Update check
github_minutes = CONFIG.CHECK_GITHUB_INTERVAL if CONFIG.CHECK_GITHUB_INTERVAL and CONFIG.CHECK_GITHUB else 0 github_minutes = CONFIG.CHECK_GITHUB_INTERVAL if CONFIG.CHECK_GITHUB_INTERVAL and CONFIG.CHECK_GITHUB else 0
schedule_job(versioncheck.check_github, 'Check GitHub for updates', schedule_job(versioncheck.check_update, 'Check GitHub for updates',
hours=0, minutes=github_minutes, seconds=0, args=(bool(CONFIG.PLEXPY_AUTO_UPDATE), True)) hours=0, minutes=github_minutes, seconds=0, args=(bool(CONFIG.PLEXPY_AUTO_UPDATE), True))
backup_hours = CONFIG.BACKUP_INTERVAL if 1 <= CONFIG.BACKUP_INTERVAL <= 24 else 6 backup_hours = CONFIG.BACKUP_INTERVAL if 1 <= CONFIG.BACKUP_INTERVAL <= 24 else 6
@@ -421,6 +479,8 @@ def initialize_scheduler():
schedule_job(activity_pinger.connect_server, 'Check for server response', schedule_job(activity_pinger.connect_server, 'Check for server response',
hours=0, minutes=0, seconds=0) hours=0, minutes=0, seconds=0)
schedule_job(web_socket.send_ping, 'Websocket ping',
hours=0, minutes=0, seconds=10 * bool(CONFIG.WEBSOCKET_MONITOR_PING_PONG))
else: else:
# Cancel all jobs # Cancel all jobs
@@ -440,6 +500,8 @@ def initialize_scheduler():
# Schedule job to reconnect server # Schedule job to reconnect server
schedule_job(activity_pinger.connect_server, 'Check for server response', schedule_job(activity_pinger.connect_server, 'Check for server response',
hours=0, minutes=0, seconds=60, args=(False,)) hours=0, minutes=0, seconds=60, args=(False,))
schedule_job(web_socket.send_ping, 'Websocket ping',
hours=0, minutes=0, seconds=0)
# Start scheduler # Start scheduler
if start_jobs and len(SCHED.get_jobs()): if start_jobs and len(SCHED.get_jobs()):
@@ -664,7 +726,8 @@ def dbcheck():
'CREATE TABLE IF NOT EXISTS newsletter_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, ' 'CREATE TABLE IF NOT EXISTS newsletter_log (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, '
'newsletter_id INTEGER, agent_id INTEGER, agent_name TEXT, notify_action TEXT, ' 'newsletter_id INTEGER, agent_id INTEGER, agent_name TEXT, notify_action TEXT, '
'subject_text TEXT, body_text TEXT, message_text TEXT, start_date TEXT, end_date TEXT, ' 'subject_text TEXT, body_text TEXT, message_text TEXT, start_date TEXT, end_date TEXT, '
'start_time INTEGER, end_time INTEGER, uuid TEXT UNIQUE, filename TEXT, success INTEGER DEFAULT 0)' 'start_time INTEGER, end_time INTEGER, uuid TEXT UNIQUE, filename TEXT, email_msg_id TEXT, '
'success INTEGER DEFAULT 0)'
) )
# recently_added table :: This table keeps record of recently added items # recently_added table :: This table keeps record of recently added items
@@ -1559,6 +1622,15 @@ def dbcheck():
'ALTER TABLE newsletter_log ADD COLUMN filename TEXT' 'ALTER TABLE newsletter_log ADD COLUMN filename TEXT'
) )
# Upgrade newsletter_log table from earlier versions
try:
c_db.execute('SELECT email_msg_id FROM newsletter_log')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table newsletter_log.")
c_db.execute(
'ALTER TABLE newsletter_log ADD COLUMN email_msg_id TEXT'
)
# Upgrade newsletters table from earlier versions # Upgrade newsletters table from earlier versions
try: try:
c_db.execute('SELECT id_name FROM newsletters') c_db.execute('SELECT id_name FROM newsletters')
@@ -1784,6 +1856,7 @@ def upgrade():
def shutdown(restart=False, update=False, checkout=False): def shutdown(restart=False, update=False, checkout=False):
logger.info(u"Stopping Tautulli web server...")
cherrypy.engine.exit() cherrypy.engine.exit()
# Shutdown the websocket connection # Shutdown the websocket connection
@@ -1822,6 +1895,9 @@ def shutdown(restart=False, update=False, checkout=False):
logger.info(u"Removing pidfile %s", PIDFILE) logger.info(u"Removing pidfile %s", PIDFILE)
os.remove(PIDFILE) os.remove(PIDFILE)
if WIN_SYS_TRAY_ICON:
WIN_SYS_TRAY_ICON.shutdown()
if restart: if restart:
logger.info(u"Tautulli is restarting...") logger.info(u"Tautulli is restarting...")
@@ -1863,7 +1939,7 @@ def generate_uuid():
def initialize_tracker(): def initialize_tracker():
data = { data = {
'dataSource': 'server', 'dataSource': 'server',
'appName': 'Tautulli', 'appName': common.PRODUCT,
'appVersion': common.RELEASE, 'appVersion': common.RELEASE,
'appId': plexpy.INSTALL_TYPE, 'appId': plexpy.INSTALL_TYPE,
'appInstallerId': plexpy.CONFIG.GIT_BRANCH, 'appInstallerId': plexpy.CONFIG.GIT_BRANCH,

View File

@@ -32,6 +32,7 @@ import xmltodict
import plexpy import plexpy
import config import config
import database import database
import helpers
import libraries import libraries
import logger import logger
import mobile_app import mobile_app
@@ -173,47 +174,51 @@ class API2:
end = int(end) end = int(end)
if regex: if regex:
logger.api_debug(u'Tautulli APIv2 :: Filtering log using regex %s' % regex) logger.api_debug(u"Tautulli APIv2 :: Filtering log using regex '%s'" % regex)
reg = re.compile('u' + regex, flags=re.I) reg = re.compile(regex, flags=re.I)
for line in open(logfile, 'r').readlines(): with open(logfile, 'r') as f:
temp_loglevel_and_time = None for line in f.readlines():
temp_loglevel_and_time = None
try: try:
temp_loglevel_and_time = line.split('- ') temp_loglevel_and_time = line.split('- ')
loglvl = temp_loglevel_and_time[1].split(' :')[0].strip() loglvl = temp_loglevel_and_time[1].split(' :')[0].strip()
tl_tread = line.split(' :: ') tl_tread = line.split(' :: ')
if loglvl is None: if loglvl is None:
msg = line.replace('\n', '') msg = line.replace('\n', '')
else: else:
msg = line.split(' : ')[1].replace('\n', '') msg = line.split(' : ')[1].replace('\n', '')
thread = tl_tread[1].split(' : ')[0] thread = tl_tread[1].split(' : ')[0]
except IndexError: except IndexError:
# We assume this is a traceback # We assume this is a traceback
tl = (len(templog) - 1) tl = (len(templog) - 1)
templog[tl]['msg'] += line.replace('\n', '') templog[tl]['msg'] += helpers.sanitize(unicode(line.replace('\n', ''), 'utf-8'))
continue continue
if len(line) > 1 and temp_loglevel_and_time is not None and loglvl in line: if len(line) > 1 and temp_loglevel_and_time is not None and loglvl in line:
d = { d = {
'time': temp_loglevel_and_time[0], 'time': temp_loglevel_and_time[0],
'loglevel': loglvl, 'loglevel': loglvl,
'msg': msg.replace('\n', ''), 'msg': helpers.sanitize(unicode(msg.replace('\n', ''), 'utf-8')),
'thread': thread 'thread': thread
} }
templog.append(d) templog.append(d)
if order == 'desc':
templog = templog[::-1]
if end > 0 or start > 0: if end > 0 or start > 0:
logger.api_debug(u'Tautulli APIv2 :: Slicing the log from %s to %s' % (start, end)) logger.api_debug(u"Tautulli APIv2 :: Slicing the log from %s to %s" % (start, end))
templog = templog[start:end] templog = templog[start:end]
if sort: if sort:
logger.api_debug(u'Tautulli APIv2 :: Sorting log based on %s' % sort) logger.api_debug(u"Tautulli APIv2 :: Sorting log based on '%s'" % sort)
templog = sorted(templog, key=lambda k: k[sort]) templog = sorted(templog, key=lambda k: k[sort])
if search: if search:
logger.api_debug(u'Tautulli APIv2 :: Searching log values for %s' % search) logger.api_debug(u"Tautulli APIv2 :: Searching log values for '%s'" % search)
tt = [d for d in templog for k, v in d.items() if search.lower() in v.lower()] tt = [d for d in templog for k, v in d.items() if search.lower() in v.lower()]
if len(tt): if len(tt):
@@ -222,16 +227,13 @@ class API2:
if regex: if regex:
tt = [] tt = []
for l in templog: for l in templog:
stringdict = ' '.join('{}{}'.format(k, v) for k, v in l.items()) stringdict = ' '.join(u'{}{}'.format(k, v) for k, v in l.items())
if reg.search(stringdict): if reg.search(stringdict):
tt.append(l) tt.append(l)
if len(tt): if len(tt):
templog = tt templog = tt
if order == 'desc':
templog = templog[::-1]
return templog return templog
def get_settings(self, key=''): def get_settings(self, key=''):
@@ -309,8 +311,8 @@ class API2:
self.backup_db() self.backup_db()
else: else:
# If the backup is less then 24 h old lets make a backup # If the backup is less then 24 h old lets make a backup
if any([os.path.getctime(os.path.join(plexpy.CONFIG.BACKUP_DIR, file_)) < (time.time() - 86400) if not any(os.path.getctime(os.path.join(plexpy.CONFIG.BACKUP_DIR, file_)) > (time.time() - 86400)
and file_.endswith('.db') for file_ in os.listdir(plexpy.CONFIG.BACKUP_DIR)]): and file_.endswith('.db') for file_ in os.listdir(plexpy.CONFIG.BACKUP_DIR)):
self.backup_db() self.backup_db()
db = database.MonitorDatabase() db = database.MonitorDatabase()
@@ -411,7 +413,7 @@ class API2:
body (str): The body of the message body (str): The body of the message
Optional parameters: Optional parameters:
None script_args (str): The arguments for script notifications
Returns: Returns:
None None
@@ -494,10 +496,16 @@ class API2:
""" Tries to make a API.md to simplify the api docs. """ """ Tries to make a API.md to simplify the api docs. """
head = '''# API Reference\n head = '''# API Reference\n
The API is still pretty new and needs some serious cleaning up on the backend but should be reasonably functional. There are no error codes yet.
## General structure ## General structure
The API endpoint is `http://ip:port + HTTP_ROOT + /api/v2?apikey=$apikey&cmd=$command` The API endpoint is
```
http://IP_ADDRESS:PORT + [/HTTP_ROOT] + /api/v2?apikey=$apikey&cmd=$command
```
Example:
```
http://localhost:8181/api/v2?apikey=66198313a092496b8a725867d2223b5f&cmd=get_metadata&rating_key=153037
```
Response example (default `json`) Response example (default `json`)
``` ```
@@ -594,8 +602,9 @@ General optional parameters:
return return
elif self._api_cmd == 'pms_image_proxy': elif self._api_cmd == 'pms_image_proxy':
cherrypy.response.headers['Content-Type'] = 'image/jpeg' if 'return_hash' not in self._api_kwargs:
return out['response']['data'] cherrypy.response.headers['Content-Type'] = 'image/jpeg'
return out['response']['data']
if self._api_out_type == 'json': if self._api_out_type == 'json':
cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8' cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8'

View File

@@ -19,6 +19,7 @@ from collections import OrderedDict
import version import version
# Identify Our Application # Identify Our Application
PRODUCT = 'Tautulli'
PLATFORM = platform.system() PLATFORM = platform.system()
PLATFORM_RELEASE = platform.release() PLATFORM_RELEASE = platform.release()
PLATFORM_VERSION = platform.version() PLATFORM_VERSION = platform.version()
@@ -27,7 +28,7 @@ PLATFORM_DEVICE_NAME = platform.node()
BRANCH = version.PLEXPY_BRANCH BRANCH = version.PLEXPY_BRANCH
RELEASE = version.PLEXPY_RELEASE_VERSION RELEASE = version.PLEXPY_RELEASE_VERSION
USER_AGENT = 'Tautulli/{} ({} {})'.format(RELEASE, PLATFORM, PLATFORM_RELEASE) USER_AGENT = '{}/{} ({} {})'.format(PRODUCT, RELEASE, PLATFORM, PLATFORM_RELEASE)
DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png" DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png"
DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png" DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png"
@@ -176,7 +177,8 @@ HW_ENCODERS = [
'videotoolbox', 'videotoolbox',
'mediacodecndk', 'mediacodecndk',
'vaapi', 'vaapi',
'nvenc' 'nvenc',
'x264'
] ]
EXTRA_TYPES = { EXTRA_TYPES = {
@@ -319,6 +321,7 @@ NOTIFICATION_PARAMETERS = [
{'name': 'Datestamp', 'type': 'str', 'value': 'datestamp', 'description': 'The date (in date format) when the notification is triggered.'}, {'name': 'Datestamp', 'type': 'str', 'value': 'datestamp', 'description': 'The date (in date format) when the notification is triggered.'},
{'name': 'Timestamp', 'type': 'str', 'value': 'timestamp', 'description': 'The time (in time format) when the notification is triggered.'}, {'name': 'Timestamp', 'type': 'str', 'value': 'timestamp', 'description': 'The time (in time format) when the notification is triggered.'},
{'name': 'Unix Time', 'type': 'int', 'value': 'unixtime', 'description': 'The unix timestamp when the notification is triggered.'}, {'name': 'Unix Time', 'type': 'int', 'value': 'unixtime', 'description': 'The unix timestamp when the notification is triggered.'},
{'name': 'UTC Time', 'type': 'int', 'value': 'utctime', 'description': 'The UTC timestamp in ISO format when the notification is triggered.'},
] ]
}, },
{ {
@@ -440,7 +443,8 @@ NOTIFICATION_PARAMETERS = [
{'name': 'Summary', 'type': 'str', 'value': 'summary', 'description': 'A short plot summary for the item.'}, {'name': 'Summary', 'type': 'str', 'value': 'summary', 'description': 'A short plot summary for the item.'},
{'name': 'Tagline', 'type': 'str', 'value': 'tagline', 'description': 'A tagline for the media item.'}, {'name': 'Tagline', 'type': 'str', 'value': 'tagline', 'description': 'A tagline for the media item.'},
{'name': 'Rating', 'type': 'float', 'value': 'rating', 'description': 'The rating (out of 10) for the item.'}, {'name': 'Rating', 'type': 'float', 'value': 'rating', 'description': 'The rating (out of 10) for the item.'},
{'name': 'Audience Rating', 'type': 'float', 'value': 'audience_rating', 'description': 'The audience rating (%) for the item.', 'help_text': 'Ratings source must be Rotten Tomatoes for the Plex Movie agent'}, {'name': 'Critic Rating', 'type': 'int', 'value': 'critic_rating', 'description': 'The critic rating (%) for the item.', 'help_text': 'Ratings source must be Rotten Tomatoes for the Plex Movie agent'},
{'name': 'Audience Rating', 'type': 'int', 'value': 'audience_rating', 'description': 'The audience rating (%) for the item.', 'help_text': 'Ratings source must be Rotten Tomatoes for the Plex Movie agent'},
{'name': 'Duration', 'type': 'int', 'value': 'duration', 'description': 'The duration (in minutes) for the item.'}, {'name': 'Duration', 'type': 'int', 'value': 'duration', 'description': 'The duration (in minutes) for the item.'},
{'name': 'Poster URL', 'type': 'str', 'value': 'poster_url', 'description': 'A URL for the movie, TV show, or album poster.'}, {'name': 'Poster URL', 'type': 'str', 'value': 'poster_url', 'description': 'A URL for the movie, TV show, or album poster.'},
{'name': 'Plex URL', 'type': 'str', 'value': 'plex_url', 'description': 'The Plex URL to your server for the item.'}, {'name': 'Plex URL', 'type': 'str', 'value': 'plex_url', 'description': 'The Plex URL to your server for the item.'},

View File

@@ -607,6 +607,7 @@ _CONFIG_DEFINITIONS = {
'UPDATE_NOTIFIERS_DB': (int, 'General', 1), 'UPDATE_NOTIFIERS_DB': (int, 'General', 1),
'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1), 'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1),
'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1), 'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1),
'WEBSOCKET_MONITOR_PING_PONG': (int, 'Advanced', 0),
'WEBSOCKET_CONNECTION_ATTEMPTS': (int, 'Advanced', 5), 'WEBSOCKET_CONNECTION_ATTEMPTS': (int, 'Advanced', 5),
'WEBSOCKET_CONNECTION_TIMEOUT': (int, 'Advanced', 5), 'WEBSOCKET_CONNECTION_TIMEOUT': (int, 'Advanced', 5),
'WEEK_START_MONDAY': (int, 'General', 0), 'WEEK_START_MONDAY': (int, 'General', 0),
@@ -629,7 +630,8 @@ _CONFIG_DEFINITIONS = {
'XBMC_ON_CONCURRENT': (int, 'XBMC', 0), 'XBMC_ON_CONCURRENT': (int, 'XBMC', 0),
'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0), 'XBMC_ON_NEWDEVICE': (int, 'XBMC', 0),
'JWT_SECRET': (str, 'Advanced', ''), 'JWT_SECRET': (str, 'Advanced', ''),
'SYSTEM_ANALYTICS': (int, 'Advanced', 1) 'SYSTEM_ANALYTICS': (int, 'Advanced', 1),
'WIN_SYS_TRAY': (int, 'General', 1)
} }
_BLACKLIST_KEYS = ['_APITOKEN', '_TOKEN', '_KEY', '_SECRET', '_PASSWORD', '_APIKEY', '_ID', '_HOOK'] _BLACKLIST_KEYS = ['_APITOKEN', '_TOKEN', '_KEY', '_SECRET', '_PASSWORD', '_APIKEY', '_ID', '_HOOK']
@@ -802,6 +804,7 @@ class Config(object):
if self.VIDEO_LOGGING_ENABLE == 0: if self.VIDEO_LOGGING_ENABLE == 0:
self.MOVIE_LOGGING_ENABLE = 0 self.MOVIE_LOGGING_ENABLE = 0
self.TV_LOGGING_ENABLE = 0 self.TV_LOGGING_ENABLE = 0
self.CONFIG_VERSION = 1 self.CONFIG_VERSION = 1
if self.CONFIG_VERSION == 1: if self.CONFIG_VERSION == 1:
@@ -817,11 +820,12 @@ class Config(object):
if 'library_statistics' in home_library_cards: if 'library_statistics' in home_library_cards:
home_library_cards.remove('library_statistics') home_library_cards.remove('library_statistics')
self.HOME_LIBRARY_CARDS = home_library_cards self.HOME_LIBRARY_CARDS = home_library_cards
self.CONFIG_VERSION = 2 self.CONFIG_VERSION = 2
if self.CONFIG_VERSION == 2: if self.CONFIG_VERSION == 2:
def rep(s): def rep(s):
return s.replace('{progress}','{progress_duration}') return s.replace('{progress}', '{progress_duration}')
self.NOTIFY_ON_START_SUBJECT_TEXT = rep(self.NOTIFY_ON_START_SUBJECT_TEXT) self.NOTIFY_ON_START_SUBJECT_TEXT = rep(self.NOTIFY_ON_START_SUBJECT_TEXT)
self.NOTIFY_ON_START_BODY_TEXT = rep(self.NOTIFY_ON_START_BODY_TEXT) self.NOTIFY_ON_START_BODY_TEXT = rep(self.NOTIFY_ON_START_BODY_TEXT)
@@ -836,10 +840,13 @@ class Config(object):
self.NOTIFY_ON_WATCHED_SUBJECT_TEXT = rep(self.NOTIFY_ON_WATCHED_SUBJECT_TEXT) self.NOTIFY_ON_WATCHED_SUBJECT_TEXT = rep(self.NOTIFY_ON_WATCHED_SUBJECT_TEXT)
self.NOTIFY_ON_WATCHED_BODY_TEXT = rep(self.NOTIFY_ON_WATCHED_BODY_TEXT) self.NOTIFY_ON_WATCHED_BODY_TEXT = rep(self.NOTIFY_ON_WATCHED_BODY_TEXT)
self.NOTIFY_SCRIPTS_ARGS_TEXT = rep(self.NOTIFY_SCRIPTS_ARGS_TEXT) self.NOTIFY_SCRIPTS_ARGS_TEXT = rep(self.NOTIFY_SCRIPTS_ARGS_TEXT)
self.CONFIG_VERSION = 3 self.CONFIG_VERSION = 3
if self.CONFIG_VERSION == 3: if self.CONFIG_VERSION == 3:
if self.HTTP_ROOT == '/': self.HTTP_ROOT = '' if self.HTTP_ROOT == '/':
self.HTTP_ROOT = ''
self.CONFIG_VERSION = 4 self.CONFIG_VERSION = 4
if self.CONFIG_VERSION == 4: if self.CONFIG_VERSION == 4:
@@ -851,20 +858,26 @@ class Config(object):
home_sections = self.HOME_SECTIONS home_sections = self.HOME_SECTIONS
home_sections.remove('library_stats') home_sections.remove('library_stats')
self.HOME_SECTIONS = home_sections self.HOME_SECTIONS = home_sections
self.CONFIG_VERSION = 5 self.CONFIG_VERSION = 5
if self.CONFIG_VERSION == 5: if self.CONFIG_VERSION == 5:
self.MONITOR_PMS_UPDATES = 0 self.MONITOR_PMS_UPDATES = 0
self.CONFIG_VERSION = 6 self.CONFIG_VERSION = 6
if self.CONFIG_VERSION == 6: if self.CONFIG_VERSION == 6:
if self.GIT_USER.lower() == 'drzoidberg33': if self.GIT_USER.lower() == 'drzoidberg33':
self.GIT_USER = 'JonnyWong16' self.GIT_USER = 'JonnyWong16'
self.CONFIG_VERSION = 7 self.CONFIG_VERSION = 7
if self.CONFIG_VERSION == 7: if self.CONFIG_VERSION == 7:
def rep(s): def rep(s):
return s.replace('<tv>','<episode>').replace('</tv>','</episode>').replace('<music>','<track>').replace('</music>','</track>') return s.replace('<tv>', '<episode>') \
.replace('</tv>', '</episode>') \
.replace('<music>', '<track>') \
.replace('</music>', '</track>')
self.NOTIFY_ON_START_SUBJECT_TEXT = rep(self.NOTIFY_ON_START_SUBJECT_TEXT) self.NOTIFY_ON_START_SUBJECT_TEXT = rep(self.NOTIFY_ON_START_SUBJECT_TEXT)
self.NOTIFY_ON_START_BODY_TEXT = rep(self.NOTIFY_ON_START_BODY_TEXT) self.NOTIFY_ON_START_BODY_TEXT = rep(self.NOTIFY_ON_START_BODY_TEXT)
@@ -904,3 +917,7 @@ class Config(object):
self.GIT_REPO = 'Tautulli' self.GIT_REPO = 'Tautulli'
self.CONFIG_VERSION = 11 self.CONFIG_VERSION = 11
if self.CONFIG_VERSION == 11:
self.ANON_REDIRECT = self.ANON_REDIRECT.replace('http://www.nullrefer.com/?',
'https://www.nullrefer.com/?')

View File

@@ -33,6 +33,7 @@ import maxminddb
from operator import itemgetter from operator import itemgetter
import os import os
import re import re
import shlex
import socket import socket
import sys import sys
import time import time
@@ -202,17 +203,22 @@ def convert_seconds_to_minutes(s):
def today(): def today():
today = datetime.date.today() today = datetime.date.today()
yyyymmdd = datetime.date.isoformat(today) yyyymmdd = datetime.date.isoformat(today)
return yyyymmdd return yyyymmdd
def now(): def now():
now = datetime.datetime.now() now = datetime.datetime.now()
return now.strftime("%Y-%m-%d %H:%M:%S") return now.strftime("%Y-%m-%d %H:%M:%S")
def utc_now_iso(): def utc_now_iso():
utcnow = datetime.datetime.utcnow() utcnow = datetime.datetime.utcnow()
return utcnow.isoformat() return utcnow.isoformat()
def human_duration(s, sig='dhms'): def human_duration(s, sig='dhms'):
hd = '' hd = ''
@@ -466,7 +472,7 @@ def get_percent(value1, value2):
else: else:
percent = 0 percent = 0
return math.trunc(percent) return math.trunc(round(percent, 0))
def hex_to_int(hex): def hex_to_int(hex):
@@ -1115,3 +1121,29 @@ def grouper(iterable, n, fillvalue=None):
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
args = [iter(iterable)] * n args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args) return izip_longest(fillvalue=fillvalue, *args)
def traverse_map(obj, func):
if isinstance(obj, list):
new_obj = []
for i in obj:
new_obj.append(traverse_map(i, func))
elif isinstance(obj, dict):
new_obj = {}
for k, v in obj.iteritems():
new_obj[traverse_map(k, func)] = traverse_map(v, func)
else:
new_obj = func(obj)
return new_obj
def split_args(args=None):
if isinstance(args, list):
return args
elif isinstance(args, basestring):
return [arg.decode(plexpy.SYS_ENCODING, 'ignore')
for arg in shlex.split(args.encode(plexpy.SYS_ENCODING, 'ignore'))]
return []

View File

@@ -33,20 +33,26 @@ class HTTPHandler(object):
Retrieve data from Plex Server Retrieve data from Plex Server
""" """
def __init__(self, urls, token=None, timeout=10, ssl_verify=True): def __init__(self, urls, headers=None, token=None, timeout=10, ssl_verify=True, silent=False):
self._silent = silent
if isinstance(urls, basestring): if isinstance(urls, basestring):
self.urls = urls.split() or urls.split(',') self.urls = urls.split() or urls.split(',')
else: else:
self.urls = urls self.urls = urls
self.headers = {'X-Plex-Product': 'Tautulli', if headers:
'X-Plex-Version': plexpy.common.RELEASE, self.headers = headers
'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID, else:
'X-Plex-Platform': plexpy.common.PLATFORM, self.headers = {'X-Plex-Product': plexpy.common.PRODUCT,
'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE, 'X-Plex-Version': plexpy.common.RELEASE,
'X-Plex-Device': 'Web', 'X-Plex-Client-Identifier': plexpy.CONFIG.PMS_UUID,
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME 'X-Plex-Platform': plexpy.common.PLATFORM,
} 'X-Plex-Platform-Version': plexpy.common.PLATFORM_RELEASE,
'X-Plex-Device': '{} {}'.format(plexpy.common.PLATFORM,
plexpy.common.PLATFORM_RELEASE),
'X-Plex-Device-Name': plexpy.common.PLATFORM_DEVICE_NAME
}
self.token = token self.token = token
if self.token: if self.token:
@@ -127,7 +133,8 @@ class HTTPHandler(object):
for work in pool.imap_unordered(part, urls, chunk): for work in pool.imap_unordered(part, urls, chunk):
yield work yield work
except Exception as e: except Exception as e:
logger.error(u"Failed to yield request: %s" % e) if not self._silent:
logger.error(u"Failed to yield request: %s" % e)
finally: finally:
pool.close() pool.close()
pool.join() pool.join()
@@ -137,13 +144,16 @@ class HTTPHandler(object):
try: try:
r = session.request(self.request_type, url, headers=self.headers, timeout=self.timeout) r = session.request(self.request_type, url, headers=self.headers, timeout=self.timeout)
except IOError as e: except IOError as e:
logger.warn(u"Failed to access uri endpoint %s with error %s" % (self.uri, e)) if not self._silent:
logger.warn(u"Failed to access uri endpoint %s with error %s" % (self.uri, e))
return None return None
except Exception as e: except Exception as e:
logger.warn(u"Failed to access uri endpoint %s. Is your server maybe accepting SSL connections only? %s" % (self.uri, e)) if not self._silent:
logger.warn(u"Failed to access uri endpoint %s. Is your server maybe accepting SSL connections only? %s" % (self.uri, e))
return None return None
except: except:
logger.warn(u"Failed to access uri endpoint %s with Uncaught exception." % self.uri) if not self._silent:
logger.warn(u"Failed to access uri endpoint %s with Uncaught exception." % self.uri)
return None return None
response_status = r.status response_status = r.status
@@ -153,7 +163,8 @@ class HTTPHandler(object):
if response_status in (200, 201): if response_status in (200, 201):
return self._http_format_output(response_content, response_headers) return self._http_format_output(response_content, response_headers)
else: else:
logger.warn(u"Failed to access uri endpoint %s. Status code %r" % (self.uri, response_status)) if not self._silent:
logger.warn(u"Failed to access uri endpoint %s. Status code %r" % (self.uri, response_status))
return None return None
def _http_format_output(self, response_content, response_headers): def _http_format_output(self, response_content, response_headers):
@@ -179,5 +190,6 @@ class HTTPHandler(object):
return output return output
except Exception as e: except Exception as e:
logger.warn(u"Failed format response from uri %s to %s error %s" % (self.uri, self.output_format, e)) if not self._silent:
logger.warn(u"Failed format response from uri %s to %s error %s" % (self.uri, self.output_format, e))
return None return None

View File

@@ -633,7 +633,8 @@ class Libraries(object):
if 'media_info' in child_metadata and len(child_metadata['media_info']) > 0: if 'media_info' in child_metadata and len(child_metadata['media_info']) > 0:
media_info = child_metadata['media_info'][0] media_info = child_metadata['media_info'][0]
if 'parts' in media_info and len (media_info['parts']) > 0: if 'parts' in media_info and len (media_info['parts']) > 0:
media_part_info = media_info['parts'][0] media_part_info = next((p for p in media_info['parts'] if p['selected']),
media_info['parts'][0])
file_size += helpers.cast_to_int(media_part_info.get('file_size', 0)) file_size += helpers.cast_to_int(media_part_info.get('file_size', 0))

View File

@@ -18,6 +18,7 @@ import time
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.cron import CronTrigger
import email.utils
import plexpy import plexpy
import database import database
@@ -86,6 +87,9 @@ def notify(newsletter_id=None, notify_action=None, **kwargs):
body = newsletter_config['body'] body = newsletter_config['body']
message = newsletter_config['message'] message = newsletter_config['message']
email_msg_id = email.utils.make_msgid()
email_reply_msg_id = get_last_newsletter_email_msg_id(newsletter_id=newsletter_id, notify_action=notify_action)
newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id, newsletter_agent = newsletters.get_agent_class(newsletter_id=newsletter_id,
newsletter_id_name=newsletter_config['id_name'], newsletter_id_name=newsletter_config['id_name'],
agent_id=newsletter_config['agent_id'], agent_id=newsletter_config['agent_id'],
@@ -93,7 +97,9 @@ def notify(newsletter_id=None, notify_action=None, **kwargs):
email_config=newsletter_config['email_config'], email_config=newsletter_config['email_config'],
subject=subject, subject=subject,
body=body, body=body,
message=message message=message,
email_msg_id=email_msg_id,
email_reply_msg_id=email_reply_msg_id
) )
# Set the newsletter state in the db # Set the newsletter state in the db
@@ -107,7 +113,8 @@ def notify(newsletter_id=None, notify_action=None, **kwargs):
end_date=newsletter_agent.end_date.format('YYYY-MM-DD'), end_date=newsletter_agent.end_date.format('YYYY-MM-DD'),
start_time=newsletter_agent.start_time, start_time=newsletter_agent.start_time,
end_time=newsletter_agent.end_time, end_time=newsletter_agent.end_time,
newsletter_uuid=newsletter_agent.uuid) newsletter_uuid=newsletter_agent.uuid,
email_msg_id=email_msg_id)
# Send the notification # Send the notification
success = newsletter_agent.send() success = newsletter_agent.send()
@@ -118,7 +125,7 @@ def notify(newsletter_id=None, notify_action=None, **kwargs):
def set_notify_state(newsletter, notify_action, subject, body, message, filename, def set_notify_state(newsletter, notify_action, subject, body, message, filename,
start_date, end_date, start_time, end_time, newsletter_uuid): start_date, end_date, start_time, end_time, newsletter_uuid, email_msg_id):
if newsletter and notify_action: if newsletter and notify_action:
db = database.MonitorDatabase() db = database.MonitorDatabase()
@@ -137,6 +144,7 @@ def set_notify_state(newsletter, notify_action, subject, body, message, filename
'end_date': end_date, 'end_date': end_date,
'start_time': start_time, 'start_time': start_time,
'end_time': end_time, 'end_time': end_time,
'email_msg_id': email_msg_id,
'filename': filename} 'filename': filename}
db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values) db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values)
@@ -153,6 +161,17 @@ def set_notify_success(newsletter_log_id):
db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values) db.upsert(table_name='newsletter_log', key_dict=keys, value_dict=values)
def get_last_newsletter_email_msg_id(newsletter_id, notify_action):
db = database.MonitorDatabase()
result = db.select_single('SELECT email_msg_id FROM newsletter_log '
'WHERE newsletter_id = ? AND notify_action = ? AND success = 1 '
'ORDER BY timestamp DESC LIMIT 1', [newsletter_id, notify_action])
if result:
return result['email_msg_id']
def get_newsletter(newsletter_uuid=None, newsletter_id_name=None): def get_newsletter(newsletter_uuid=None, newsletter_id_name=None):
db = database.MonitorDatabase() db = database.MonitorDatabase()

View File

@@ -65,7 +65,8 @@ def available_notification_actions():
def get_agent_class(newsletter_id=None, newsletter_id_name=None, agent_id=None, config=None, email_config=None, def get_agent_class(newsletter_id=None, newsletter_id_name=None, agent_id=None, config=None, email_config=None,
start_date=None, end_date=None, subject=None, body=None, message=None): start_date=None, end_date=None, subject=None, body=None, message=None,
email_msg_id=None, email_reply_msg_id=None):
if str(agent_id).isdigit(): if str(agent_id).isdigit():
agent_id = int(agent_id) agent_id = int(agent_id)
@@ -77,7 +78,9 @@ def get_agent_class(newsletter_id=None, newsletter_id_name=None, agent_id=None,
'end_date': end_date, 'end_date': end_date,
'subject': subject, 'subject': subject,
'body': body, 'body': body,
'message': message} 'message': message,
'email_msg_id': email_msg_id,
'email_reply_msg_id': email_reply_msg_id}
if agent_id == 0: if agent_id == 0:
return RecentlyAdded(**kwargs) return RecentlyAdded(**kwargs)
@@ -326,6 +329,7 @@ class Newsletter(object):
'time_frame': 7, 'time_frame': 7,
'time_frame_units': 'days', 'time_frame_units': 'days',
'formatted': 1, 'formatted': 1,
'threaded': 0,
'notifier_id': 0, 'notifier_id': 0,
'filename': '', 'filename': '',
'save_only': 0} 'save_only': 0}
@@ -339,11 +343,15 @@ class Newsletter(object):
_TEMPLATE = '' _TEMPLATE = ''
def __init__(self, newsletter_id=None, newsletter_id_name=None, config=None, email_config=None, def __init__(self, newsletter_id=None, newsletter_id_name=None, config=None, email_config=None,
start_date=None, end_date=None, subject=None, body=None, message=None): start_date=None, end_date=None, subject=None, body=None, message=None,
email_msg_id=None, email_reply_msg_id=None):
self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG) self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG)
self.email_config = self.set_config(config=email_config, default=self._DEFAULT_EMAIL_CONFIG) self.email_config = self.set_config(config=email_config, default=self._DEFAULT_EMAIL_CONFIG)
self.uuid = generate_newsletter_uuid() self.uuid = generate_newsletter_uuid()
self.email_msg_id = email_msg_id
self.email_reply_msg_id = email_reply_msg_id
self.newsletter_id = newsletter_id self.newsletter_id = newsletter_id
self.newsletter_id_name = newsletter_id_name or '' self.newsletter_id_name = newsletter_id_name or ''
self.start_date = None self.start_date = None
@@ -516,12 +524,16 @@ class Newsletter(object):
if plexpy.CONFIG.NEWSLETTER_SELF_HOSTED and plexpy.CONFIG.HTTP_BASE_URL: if plexpy.CONFIG.NEWSLETTER_SELF_HOSTED and plexpy.CONFIG.HTTP_BASE_URL:
plaintext += self._DEFAULT_BODY.format(**self.parameters) plaintext += self._DEFAULT_BODY.format(**self.parameters)
email_reply_msg_id = self.email_reply_msg_id if self.config['threaded'] else None
if self.email_config['notifier_id']: if self.email_config['notifier_id']:
return send_notification( return send_notification(
notifier_id=self.email_config['notifier_id'], notifier_id=self.email_config['notifier_id'],
subject=self.subject_formatted, subject=self.subject_formatted,
body=newsletter_stripped, body=newsletter_stripped,
plaintext=plaintext plaintext=plaintext,
msg_id=self.email_msg_id,
reply_msg_id=email_reply_msg_id
) )
else: else:
@@ -529,7 +541,9 @@ class Newsletter(object):
return email.notify( return email.notify(
subject=self.subject_formatted, subject=self.subject_formatted,
body=newsletter_stripped, body=newsletter_stripped,
plaintext=plaintext plaintext=plaintext,
msg_id=self.email_msg_id,
reply_msg_id=email_reply_msg_id
) )
elif self.config['notifier_id']: elif self.config['notifier_id']:
return send_notification( return send_notification(

View File

@@ -23,7 +23,6 @@ import json
from operator import itemgetter from operator import itemgetter
import os import os
import re import re
import shlex
from string import Formatter from string import Formatter
import threading import threading
import time import time
@@ -337,12 +336,7 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data
if notify_action in ('test', 'api'): if notify_action in ('test', 'api'):
subject = kwargs.pop('subject', 'Tautulli') subject = kwargs.pop('subject', 'Tautulli')
body = kwargs.pop('body', 'Test Notification') body = kwargs.pop('body', 'Test Notification')
script_args = kwargs.pop('script_args', []) script_args = helpers.split_args(kwargs.pop('script_args', []))
if script_args and isinstance(script_args, basestring):
# Attemps to format test script args for the user
script_args = [arg.decode(plexpy.SYS_ENCODING, 'ignore')
for arg in shlex.split(script_args.encode(plexpy.SYS_ENCODING, 'ignore'))]
else: else:
# Get the subject and body strings # Get the subject and body strings
@@ -486,20 +480,24 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
if 'media_info' in notify_params and len(notify_params['media_info']) > 0: if 'media_info' in notify_params and len(notify_params['media_info']) > 0:
media_info = notify_params['media_info'][0] media_info = notify_params['media_info'][0]
if 'parts' in media_info and len(media_info['parts']) > 0: if 'parts' in media_info and len(media_info['parts']) > 0:
media_part_info = media_info.pop('parts')[0] parts = media_info.pop('parts')
media_part_info = next((p for p in parts if p['selected']), parts[0])
stream_video = stream_audio = stream_subtitle = False
if 'streams' in media_part_info: if 'streams' in media_part_info:
for stream in media_part_info.pop('streams'): streams = media_part_info.pop('streams')
if not stream_video and stream['type'] == '1': video_streams = [s for s in streams if s['type'] == '1']
media_part_info.update(stream) audio_streams = [s for s in streams if s['type'] == '2']
stream_video = True subtitle_streams = [s for s in streams if s['type'] == '3']
if not stream_audio and stream['type'] == '2':
media_part_info.update(stream) if video_streams:
stream_audio = True video_stream = next((s for s in video_streams if s['selected']), video_streams[0])
if not stream_subtitle and stream['type'] == '3': media_part_info.update(video_stream)
media_part_info.update(stream) if audio_streams:
stream_subtitle = True audio_stream = next((s for s in audio_streams if s['selected']), audio_streams[0])
media_part_info.update(audio_stream)
if subtitle_streams:
subtitle_stream = next((s for s in subtitle_streams if s['selected']), subtitle_streams[0])
media_part_info.update(subtitle_stream)
notify_params.update(media_info) notify_params.update(media_info)
notify_params.update(media_part_info) notify_params.update(media_part_info)
@@ -527,7 +525,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
else: else:
transcode_decision = 'Direct Play' transcode_decision = 'Direct Play'
if notify_action != 'play': if notify_action != 'on_play':
stream_duration = int((time.time() - stream_duration = int((time.time() -
helpers.cast_to_int(session.get('started', 0)) - helpers.cast_to_int(session.get('started', 0)) -
helpers.cast_to_int(session.get('paused_counter', 0))) / 60) helpers.cast_to_int(session.get('paused_counter', 0))) / 60)
@@ -708,6 +706,14 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
child_count = 1 child_count = 1
grandchild_count = 1 grandchild_count = 1
critic_rating = ''
if notify_params['rating_image'].startswith('rottentomatoes://') and notify_params['rating']:
critic_rating = helpers.get_percent(notify_params['rating'], 10)
audience_rating = ''
if notify_params['audience_rating']:
audience_rating = helpers.get_percent(notify_params['audience_rating'], 10)
now = arrow.now() now = arrow.now()
now_iso = now.isocalendar() now_iso = now.isocalendar()
@@ -737,6 +743,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
'datestamp': now.format(date_format), 'datestamp': now.format(date_format),
'timestamp': now.format(time_format), 'timestamp': now.format(time_format),
'unixtime': int(time.time()), 'unixtime': int(time.time()),
'utctime': helpers.utc_now_iso(),
# Stream parameters # Stream parameters
'streams': stream_count, 'streams': stream_count,
'user_streams': user_stream_count, 'user_streams': user_stream_count,
@@ -856,7 +863,8 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
'summary': notify_params['summary'], 'summary': notify_params['summary'],
'tagline': notify_params['tagline'], 'tagline': notify_params['tagline'],
'rating': notify_params['rating'], 'rating': notify_params['rating'],
'audience_rating': helpers.get_percent(notify_params['audience_rating'], 10) or '', 'critic_rating': critic_rating,
'audience_rating': audience_rating,
'duration': duration, 'duration': duration,
'poster_title': notify_params['poster_title'], 'poster_title': notify_params['poster_title'],
'poster_url': notify_params['poster_url'], 'poster_url': notify_params['poster_url'],
@@ -956,6 +964,7 @@ def build_server_notify_params(notify_action=None, **kwargs):
'datestamp': now.format(date_format), 'datestamp': now.format(date_format),
'timestamp': now.format(time_format), 'timestamp': now.format(time_format),
'unixtime': int(time.time()), 'unixtime': int(time.time()),
'utctime': helpers.utc_now_iso(),
# Plex Media Server update parameters # Plex Media Server update parameters
'update_version': pms_download_info['version'], 'update_version': pms_download_info['version'],
'update_url': pms_download_info['download_url'], 'update_url': pms_download_info['download_url'],
@@ -1026,6 +1035,7 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
# Remove the unwanted tags and strip any unmatch tags too. # Remove the unwanted tags and strip any unmatch tags too.
subject = strip_tag(re.sub(pattern, '', subject), agent_id).strip(' \t\n\r') subject = strip_tag(re.sub(pattern, '', subject), agent_id).strip(' \t\n\r')
body = strip_tag(re.sub(pattern, '', body), agent_id).strip(' \t\n\r') body = strip_tag(re.sub(pattern, '', body), agent_id).strip(' \t\n\r')
script_args = []
if test: if test:
return subject, body return subject, body
@@ -1034,34 +1044,55 @@ def build_notify_text(subject='', body='', notify_action=None, parameters=None,
if agent_id == 15: if agent_id == 15:
try: try:
script_args = [custom_formatter.format(arg, **parameters).decode(plexpy.SYS_ENCODING, 'ignore') script_args = [custom_formatter.format(arg, **parameters) for arg in helpers.split_args(subject)]
for arg in shlex.split(subject.encode(plexpy.SYS_ENCODING, 'ignore'))]
except LookupError as e: except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in script argument. Using fallback." % e) logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in script argument. Using fallback." % e)
script_args = [] script_args = []
except Exception as e: except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom script arguments: %s. Using fallback." % e) logger.error(u"Tautulli NotificationHandler :: Unable to parse custom script arguments: %s. Using fallback." % e)
script_args = [] script_args = []
elif agent_id == 25:
if body:
try:
body = json.loads(body)
except ValueError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook json data: %s. Using fallback." % e)
body = ''
if body:
def str_format(s):
if isinstance(s, basestring):
return custom_formatter.format(unicode(s), **parameters)
return s
try:
body = json.dumps(helpers.traverse_map(body, str_format))
except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in webhook data. Using fallback." % e)
body = ''
except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom webhook data: %s. Using fallback." % e)
body = ''
else: else:
script_args = [] try:
subject = custom_formatter.format(unicode(subject), **parameters)
except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in notification subject. Using fallback." % e)
subject = unicode(default_subject).format(**parameters)
except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom notification subject: %s. Using fallback." % e)
subject = unicode(default_subject).format(**parameters)
try: try:
subject = custom_formatter.format(unicode(subject), **parameters) body = custom_formatter.format(unicode(body), **parameters)
except LookupError as e: except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in notification subject. Using fallback." % e) logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in notification body. Using fallback." % e)
subject = unicode(default_subject).format(**parameters) body = unicode(default_body).format(**parameters)
except Exception as e: except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom notification subject: %s. Using fallback." % e) logger.error(u"Tautulli NotificationHandler :: Unable to parse custom notification body: %s. Using fallback." % e)
subject = unicode(default_subject).format(**parameters) body = unicode(default_body).format(**parameters)
try:
body = custom_formatter.format(unicode(body), **parameters)
except LookupError as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse parameter %s in notification body. Using fallback." % e)
body = unicode(default_body).format(**parameters)
except Exception as e:
logger.error(u"Tautulli NotificationHandler :: Unable to parse custom notification body: %s. Using fallback." % e)
body = unicode(default_body).format(**parameters)
return subject, body, script_args return subject, body, script_args
@@ -1218,7 +1249,8 @@ def get_img_info(img=None, rating_key=None, title='', width=1000, height=1500,
def set_hash_image_info(img=None, rating_key=None, width=750, height=1000, def set_hash_image_info(img=None, rating_key=None, width=750, height=1000,
opacity=100, background='000000', blur=0, fallback=None): opacity=100, background='000000', blur=0, fallback=None,
add_to_db=True):
if not rating_key and not img: if not rating_key and not img:
return fallback return fallback
@@ -1236,18 +1268,19 @@ def set_hash_image_info(img=None, rating_key=None, width=750, height=1000,
plexpy.CONFIG.PMS_UUID, img, rating_key, width, height, opacity, background, blur, fallback) plexpy.CONFIG.PMS_UUID, img, rating_key, width, height, opacity, background, blur, fallback)
img_hash = hashlib.sha256(img_string).hexdigest() img_hash = hashlib.sha256(img_string).hexdigest()
keys = {'img_hash': img_hash} if add_to_db:
values = {'img': img, keys = {'img_hash': img_hash}
'rating_key': rating_key, values = {'img': img,
'width': width, 'rating_key': rating_key,
'height': height, 'width': width,
'opacity': opacity, 'height': height,
'background': background, 'opacity': opacity,
'blur': blur, 'background': background,
'fallback': fallback} 'blur': blur,
'fallback': fallback}
db = database.MonitorDatabase() db = database.MonitorDatabase()
db.upsert('image_hash_lookup', key_dict=keys, value_dict=values) db.upsert('image_hash_lookup', key_dict=keys, value_dict=values)
return img_hash return img_hash
@@ -1422,6 +1455,10 @@ def get_themoviedb_info(rating_key=None, media_type=None, themoviedb_id=None):
class CustomFormatter(Formatter): class CustomFormatter(Formatter):
def __init__(self, default='{{{0}}}', default_format_spec='{{{0}:{1}}}'):
self.default = default
self.default_format_spec = default_format_spec
def convert_field(self, value, conversion): def convert_field(self, value, conversion):
if conversion is None: if conversion is None:
return value return value
@@ -1450,4 +1487,13 @@ class CustomFormatter(Formatter):
else: else:
return value return value
else: else:
return super(CustomFormatter, self).format_field(value, format_spec) try:
return super(CustomFormatter, self).format_field(value, format_spec)
except ValueError:
return self.default_format_spec.format(value[1:-1], format_spec)
def get_value(self, key, args, kwargs):
if isinstance(key, basestring):
return kwargs.get(key, self.default.format(key))
else:
return super(CustomFormatter, self).get_value(key, args, kwargs)

View File

@@ -91,7 +91,8 @@ AGENT_IDS = {'growl': 0,
'androidapp': 21, 'androidapp': 21,
'groupme': 22, 'groupme': 22,
'mqtt': 23, 'mqtt': 23,
'zapier': 24 'zapier': 24,
'webhook': 25
} }
DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': ''}] DEFAULT_CUSTOM_CONDITIONS = [{'parameter': '', 'operator': '', 'value': ''}]
@@ -146,10 +147,10 @@ def available_notification_agents():
'name': 'xbmc', 'name': 'xbmc',
'id': AGENT_IDS['xbmc'] 'id': AGENT_IDS['xbmc']
}, },
{'label': 'Notify My Android', # {'label': 'Notify My Android',
'name': 'nma', # 'name': 'nma',
'id': AGENT_IDS['nma'] # 'id': AGENT_IDS['nma']
}, # },
{'label': 'MQTT', {'label': 'MQTT',
'name': 'mqtt', 'name': 'mqtt',
'id': AGENT_IDS['mqtt'] 'id': AGENT_IDS['mqtt']
@@ -190,6 +191,10 @@ def available_notification_agents():
'name': 'twitter', 'name': 'twitter',
'id': AGENT_IDS['twitter'] 'id': AGENT_IDS['twitter']
}, },
{'label': 'Webhook',
'name': 'webhook',
'id': AGENT_IDS['webhook']
},
{'label': 'Zapier', {'label': 'Zapier',
'name': 'zapier', 'name': 'zapier',
'id': AGENT_IDS['zapier'] 'id': AGENT_IDS['zapier']
@@ -386,6 +391,8 @@ def get_agent_class(agent_id=None, config=None):
return MQTT(config=config) return MQTT(config=config)
elif agent_id == 24: elif agent_id == 24:
return ZAPIER(config=config) return ZAPIER(config=config)
elif agent_id == 25:
return WEBHOOK(config=config)
else: else:
return Notifier(config=config) return Notifier(config=config)
else: else:
@@ -513,7 +520,7 @@ def add_notifier_config(agent_id=None, **kwargs):
'custom_conditions_logic': '' 'custom_conditions_logic': ''
} }
if agent['name'] == 'scripts': if agent['name'] in ('scripts', 'webhook'):
for a in available_notification_actions(): for a in available_notification_actions():
values[a['name'] + '_subject'] = '' values[a['name'] + '_subject'] = ''
values[a['name'] + '_body'] = '' values[a['name'] + '_body'] = ''
@@ -774,7 +781,7 @@ class Notifier(object):
return self._DEFAULT_CONFIG.copy() return self._DEFAULT_CONFIG.copy()
def notify(self, subject='', body='', action='', **kwargs): def notify(self, subject='', body='', action='', **kwargs):
if self.NAME != 'Script': if self.NAME not in ('Script', 'Webhook'):
if not subject and self.config.get('incl_subject', True): if not subject and self.config.get('incl_subject', True):
logger.error(u"Tautulli Notifiers :: %s notification subject cannot be blank." % self.NAME) logger.error(u"Tautulli Notifiers :: %s notification subject cannot be blank." % self.NAME)
return return
@@ -788,6 +795,7 @@ class Notifier(object):
pass pass
def make_request(self, url, method='POST', **kwargs): def make_request(self, url, method='POST', **kwargs):
logger.info(u"Tautulli Notifiers :: Sending {name} notification...".format(name=self.NAME))
response, err_msg, req_msg = request.request_response2(url, method, **kwargs) response, err_msg, req_msg = request.request_response2(url, method, **kwargs)
if response and not err_msg: if response and not err_msg:
@@ -1138,7 +1146,7 @@ class DISCORD(Notifier):
# Build Discord post attachment # Build Discord post attachment
attachment = {'title': title, attachment = {'title': title,
'timestamp': helpers.utc_now_iso() 'timestamp': pretty_metadata.parameters['utctime']
} }
if self.config['color']: if self.config['color']:
@@ -1302,13 +1310,20 @@ class EMAIL(Notifier):
msg.replace_header('Content-Transfer-Encoding', 'quoted-printable') msg.replace_header('Content-Transfer-Encoding', 'quoted-printable')
msg.set_payload(body, 'utf-8') msg.set_payload(body, 'utf-8')
msg['Message-ID'] = email.utils.make_msgid() msg_id = kwargs.get('msg_id', email.utils.make_msgid())
reply_msg_id = kwargs.get('reply_msg_id')
msg['Message-ID'] = msg_id
msg['Date'] = email.utils.formatdate(localtime=True) msg['Date'] = email.utils.formatdate(localtime=True)
msg['Subject'] = subject msg['Subject'] = subject
msg['From'] = email.utils.formataddr((self.config['from_name'], self.config['from'])) msg['From'] = email.utils.formataddr((self.config['from_name'], self.config['from']))
msg['To'] = ','.join(self.config['to']) msg['To'] = ','.join(self.config['to'])
msg['CC'] = ','.join(self.config['cc']) msg['CC'] = ','.join(self.config['cc'])
if reply_msg_id:
msg["In-Reply-To"] = reply_msg_id
msg["References"] = reply_msg_id
recipients = self.config['to'] + self.config['cc'] + self.config['bcc'] recipients = self.config['to'] + self.config['cc'] + self.config['bcc']
mailserver = None mailserver = None
@@ -2971,7 +2986,9 @@ class SCRIPTS(Notifier):
'.sh': '' '.sh': ''
} }
self.arg_overrides = ('python2', 'python3', 'python', 'pythonw', 'php', 'ruby', 'perl') self.pythonpath_override = 'nopythonpath'
self.pythonpath = True
self.prefix_overrides = ('python2', 'python3', 'python', 'pythonw', 'php', 'ruby', 'perl')
self.script_killed = False self.script_killed = False
def list_scripts(self): def list_scripts(self):
@@ -2998,11 +3015,14 @@ class SCRIPTS(Notifier):
'PLEX_URL': plexpy.CONFIG.PMS_URL, 'PLEX_URL': plexpy.CONFIG.PMS_URL,
'PLEX_TOKEN': plexpy.CONFIG.PMS_TOKEN, 'PLEX_TOKEN': plexpy.CONFIG.PMS_TOKEN,
'TAUTULLI_URL': helpers.get_plexpy_url(hostname='localhost'), 'TAUTULLI_URL': helpers.get_plexpy_url(hostname='localhost'),
'TAUTULLI_PUBLIC_URL': plexpy.CONFIG.HTTP_BASE_URL + plexpy.HTTP_ROOT,
'TAUTULLI_APIKEY': plexpy.CONFIG.API_KEY, 'TAUTULLI_APIKEY': plexpy.CONFIG.API_KEY,
'TAUTULLI_ENCODING': plexpy.SYS_ENCODING, 'TAUTULLI_ENCODING': plexpy.SYS_ENCODING
'PYTHONPATH': (';' if os.name == 'nt' else ':').join(sys.path)
}) })
if self.pythonpath:
env['PYTHONPATH'] = os.pathsep.join([p for p in sys.path if p])
try: try:
process = subprocess.Popen(script, process = subprocess.Popen(script,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
@@ -3058,7 +3078,7 @@ class SCRIPTS(Notifier):
logger.error(u"Tautulli Notifiers :: No script folder specified.") logger.error(u"Tautulli Notifiers :: No script folder specified.")
return return
script_args = kwargs.get('script_args', []) script_args = helpers.split_args(kwargs.get('script_args', subject))
logger.debug(u"Tautulli Notifiers :: Trying to run notify script, action: %s, arguments: %s" logger.debug(u"Tautulli Notifiers :: Trying to run notify script, action: %s, arguments: %s"
% (action, script_args)) % (action, script_args))
@@ -3094,9 +3114,15 @@ class SCRIPTS(Notifier):
if script_args: # and os.name == 'nt': if script_args: # and os.name == 'nt':
script_args = [arg.encode(plexpy.SYS_ENCODING, 'ignore') for arg in script_args] script_args = [arg.encode(plexpy.SYS_ENCODING, 'ignore') for arg in script_args]
# Allow overrides for PYTHONPATH
if prefix and script_args:
if script_args[0] == self.pythonpath_override:
self.pythonpath = False
del script_args[0]
# Allow overrides for shitty systems # Allow overrides for shitty systems
if prefix and script_args: if prefix and script_args:
if script_args[0] in self.arg_overrides: if script_args[0] in self.prefix_overrides:
script[0] = script_args[0] script[0] = script_args[0]
del script_args[0] del script_args[0]
@@ -3527,6 +3553,53 @@ class TWITTER(Notifier):
return config_option return config_option
class WEBHOOK(Notifier):
"""
Webhook notifications
"""
NAME = 'Webhook'
_DEFAULT_CONFIG = {'hook': '',
'method': ''
}
def agent_notify(self, subject='', body='', action='', **kwargs):
if body:
try:
webhook_data = json.loads(body)
except ValueError as e:
logger.error(u"Tautulli Notifiers :: Invalid {name} json data: {e}".format(name=self.NAME, e=e))
return False
else:
webhook_data = None
headers = {'Content-type': 'application/json'}
return self.make_request(self.config['hook'], method=self.config['method'], headers=headers, json=webhook_data)
def return_config_options(self):
config_option = [{'label': 'Webhook URL',
'value': self.config['hook'],
'name': 'webhook_hook',
'description': 'Your Webhook URL.',
'input_type': 'text'
},
{'label': 'Webhook Method',
'value': self.config['method'],
'name': 'webhook_method',
'description': 'The Webhook HTTP request method.',
'input_type': 'select',
'select_options': {'': '',
'GET': 'GET',
'POST': 'POST',
'PUT': 'PUT',
'DELETE': 'DELETE'}
}
]
return config_option
class XBMC(Notifier): class XBMC(Notifier):
""" """
Kodi notifications Kodi notifications

View File

@@ -121,7 +121,7 @@ class PlexTV(object):
Plex.tv authentication Plex.tv authentication
""" """
def __init__(self, username=None, password=None, token=None): def __init__(self, username=None, password=None, token=None, headers=None):
self.username = username self.username = username
self.password = password self.password = password
self.token = token self.token = token
@@ -147,7 +147,8 @@ class PlexTV(object):
self.request_handler = http_handler.HTTPHandler(urls=self.urls, self.request_handler = http_handler.HTTPHandler(urls=self.urls,
token=self.token, token=self.token,
timeout=self.timeout, timeout=self.timeout,
ssl_verify=self.ssl_verify) ssl_verify=self.ssl_verify,
headers=headers)
def get_plex_auth(self, output_format='raw'): def get_plex_auth(self, output_format='raw'):
uri = '/users/sign_in.xml' uri = '/users/sign_in.xml'
@@ -210,22 +211,62 @@ class PlexTV(object):
def get_server_token(self): def get_server_token(self):
servers = self.get_plextv_server_list(output_format='xml') servers = self.get_plextv_resources(output_format='xml')
server_token = '' server_token = ''
try: try:
xml_head = servers.getElementsByTagName('Server') xml_head = servers.getElementsByTagName('Device')
except Exception as e: except Exception as e:
logger.warn(u"Tautulli PlexTV :: Unable to parse XML for get_server_token: %s." % e) logger.warn(u"Tautulli PlexTV :: Unable to parse XML for get_server_token: %s." % e)
return None return None
for a in xml_head: for a in xml_head:
if helpers.get_xml_attr(a, 'machineIdentifier') == plexpy.CONFIG.PMS_IDENTIFIER: if helpers.get_xml_attr(a, 'clientIdentifier') == plexpy.CONFIG.PMS_IDENTIFIER \
and 'server' in helpers.get_xml_attr(a, 'provides'):
server_token = helpers.get_xml_attr(a, 'accessToken') server_token = helpers.get_xml_attr(a, 'accessToken')
break break
return server_token return server_token
def get_plextv_pin(self, pin='', output_format=''):
if pin:
uri = '/api/v2/pins/' + pin
request = self.request_handler.make_request(uri=uri,
request_type='GET',
output_format=output_format,
no_token=True)
else:
uri = '/api/v2/pins?strong=true'
request = self.request_handler.make_request(uri=uri,
request_type='POST',
output_format=output_format,
no_token=True)
return request
def get_pin(self, pin=''):
plextv_response = self.get_plextv_pin(pin=pin,
output_format='xml')
if plextv_response:
try:
xml_head = plextv_response.getElementsByTagName('pin')
if xml_head:
pin = {'id': xml_head[0].getAttribute('id'),
'code': xml_head[0].getAttribute('code'),
'token': xml_head[0].getAttribute('authToken')
}
return pin
else:
logger.warn(u"Tautulli PlexTV :: Could not get Plex authentication pin.")
return None
except Exception as e:
logger.warn(u"Tautulli PlexTV :: Unable to parse XML for get_pin: %s." % e)
return None
else:
return None
def get_plextv_user_data(self): def get_plextv_user_data(self):
plextv_response = self.get_plex_auth(output_format='dict') plextv_response = self.get_plex_auth(output_format='dict')
@@ -645,6 +686,27 @@ class PlexTV(object):
def discover(self, include_cloud=True, all_servers=False): def discover(self, include_cloud=True, all_servers=False):
""" Query plex for all servers online. Returns the ones you own in a selectize format """ """ Query plex for all servers online. Returns the ones you own in a selectize format """
# Try to discover localhost server
local_machine_identifier = None
request_handler = http_handler.HTTPHandler(urls='http://127.0.0.1:32400', timeout=1,
ssl_verify=False, silent=True)
request = request_handler.make_request(uri='/identity', request_type='GET', output_format='xml')
if request:
xml_head = request.getElementsByTagName('MediaContainer')[0]
local_machine_identifier = xml_head.getAttribute('machineIdentifier')
local_server = {'httpsRequired': '0',
'clientIdentifier': local_machine_identifier,
'label': 'Local',
'ip': '127.0.0.1',
'port': '32400',
'uri': 'http://127.0.0.1:32400',
'local': '1',
'value': '127.0.0.1:32400',
'is_cloud': False
}
servers = self.get_plextv_resources(include_https=True, output_format='xml') servers = self.get_plextv_resources(include_https=True, output_format='xml')
clean_servers = [] clean_servers = []
@@ -664,8 +726,8 @@ class PlexTV(object):
for d in devices: for d in devices:
if helpers.get_xml_attr(d, 'presence') == '1' and \ if helpers.get_xml_attr(d, 'presence') == '1' and \
helpers.get_xml_attr(d, 'owned') == '1' and \ helpers.get_xml_attr(d, 'owned') == '1' and \
helpers.get_xml_attr(d, 'provides') == 'server': helpers.get_xml_attr(d, 'provides') == 'server':
is_cloud = (helpers.get_xml_attr(d, 'platform').lower() == 'cloud') is_cloud = (helpers.get_xml_attr(d, 'platform').lower() == 'cloud')
if not include_cloud and is_cloud: if not include_cloud and is_cloud:
@@ -677,14 +739,20 @@ class PlexTV(object):
if not all_servers: if not all_servers:
# If this is a remote server don't show any local IPs. # If this is a remote server don't show any local IPs.
if helpers.get_xml_attr(d, 'publicAddressMatches') == '0' and \ if helpers.get_xml_attr(d, 'publicAddressMatches') == '0' and \
helpers.get_xml_attr(c, 'local') == '1': helpers.get_xml_attr(c, 'local') == '1':
continue continue
# If this is a local server don't show any remote IPs. # If this is a local server don't show any remote IPs.
if helpers.get_xml_attr(d, 'publicAddressMatches') == '1' and \ if helpers.get_xml_attr(d, 'publicAddressMatches') == '1' and \
helpers.get_xml_attr(c, 'local') == '0': helpers.get_xml_attr(c, 'local') == '0':
continue continue
if helpers.get_xml_attr(d, 'clientIdentifier') == local_machine_identifier:
local_server['httpsRequired'] = helpers.get_xml_attr(d, 'httpsRequired')
local_server['label'] = helpers.get_xml_attr(d, 'name')
clean_servers.append(local_server)
local_machine_identifier = None
server = {'httpsRequired': '1' if is_cloud else helpers.get_xml_attr(d, 'httpsRequired'), server = {'httpsRequired': '1' if is_cloud else helpers.get_xml_attr(d, 'httpsRequired'),
'clientIdentifier': helpers.get_xml_attr(d, 'clientIdentifier'), 'clientIdentifier': helpers.get_xml_attr(d, 'clientIdentifier'),
'label': helpers.get_xml_attr(d, 'name'), 'label': helpers.get_xml_attr(d, 'name'),
@@ -692,11 +760,16 @@ class PlexTV(object):
'port': helpers.get_xml_attr(c, 'port'), 'port': helpers.get_xml_attr(c, 'port'),
'uri': helpers.get_xml_attr(c, 'uri'), 'uri': helpers.get_xml_attr(c, 'uri'),
'local': helpers.get_xml_attr(c, 'local'), 'local': helpers.get_xml_attr(c, 'local'),
'value': helpers.get_xml_attr(c, 'address'), 'value': helpers.get_xml_attr(c, 'address') + ':' + helpers.get_xml_attr(c, 'port'),
'is_cloud': is_cloud 'is_cloud': is_cloud
} }
clean_servers.append(server) clean_servers.append(server)
if local_machine_identifier:
clean_servers.append(local_server)
clean_servers.sort(key=lambda s: (s['label'], -int(s['local']), s['ip']))
return clean_servers return clean_servers
def get_plex_downloads(self): def get_plex_downloads(self):
@@ -819,3 +892,28 @@ class PlexTV(object):
return True return True
else: else:
return False return False
def get_plex_account_details(self):
account_data = self.get_plextv_user_details(output_format='xml')
try:
xml_head = account_data.getElementsByTagName('user')
except Exception as e:
logger.warn(u"Tautulli PlexTV :: Unable to parse XML for get_plex_account_details: %s." % e)
return None
for a in xml_head:
account_details = {"user_id": helpers.get_xml_attr(a, 'id'),
"username": helpers.get_xml_attr(a, 'username'),
"thumb": helpers.get_xml_attr(a, 'thumb'),
"email": helpers.get_xml_attr(a, 'email'),
"is_home_user": helpers.get_xml_attr(a, 'home'),
"is_restricted": helpers.get_xml_attr(a, 'restricted'),
"filter_all": helpers.get_xml_attr(a, 'filterAll'),
"filter_movies": helpers.get_xml_attr(a, 'filterMovies'),
"filter_tv": helpers.get_xml_attr(a, 'filterTelevision'),
"filter_music": helpers.get_xml_attr(a, 'filterMusic'),
"filter_photos": helpers.get_xml_attr(a, 'filterPhotos'),
"user_token": helpers.get_xml_attr(a, 'authToken')
}
return account_details

View File

@@ -527,7 +527,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(m, 'summary'), 'summary': helpers.get_xml_attr(m, 'summary'),
'tagline': helpers.get_xml_attr(m, 'tagline'), 'tagline': helpers.get_xml_attr(m, 'tagline'),
'rating': helpers.get_xml_attr(m, 'rating'), 'rating': helpers.get_xml_attr(m, 'rating'),
'rating_image': helpers.get_xml_attr(m, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(m, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(m, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(m, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(m, 'userRating'), 'user_rating': helpers.get_xml_attr(m, 'userRating'),
'duration': helpers.get_xml_attr(m, 'duration'), 'duration': helpers.get_xml_attr(m, 'duration'),
'year': helpers.get_xml_attr(m, 'year'), 'year': helpers.get_xml_attr(m, 'year'),
@@ -680,7 +682,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -728,7 +732,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': duration, 'duration': duration,
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -773,7 +779,9 @@ class PmsConnect(object):
'summary': show_details['summary'], 'summary': show_details['summary'],
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': show_details['duration'], 'duration': show_details['duration'],
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -801,11 +809,27 @@ class PmsConnect(object):
elif metadata_type == 'episode': elif metadata_type == 'episode':
grandparent_rating_key = helpers.get_xml_attr(metadata_main, 'grandparentRatingKey') grandparent_rating_key = helpers.get_xml_attr(metadata_main, 'grandparentRatingKey')
show_details = self.get_metadata_details(grandparent_rating_key) show_details = self.get_metadata_details(grandparent_rating_key)
parent_rating_key = helpers.get_xml_attr(metadata_main, 'parentRatingKey')
parent_media_index = helpers.get_xml_attr(metadata_main, 'parentIndex')
parent_thumb = helpers.get_xml_attr(metadata_main, 'parentThumb')
if not parent_rating_key:
# Try getting the parent_rating_key from the parent_thumb
if parent_thumb.startswith('/library/metadata/'):
parent_rating_key = parent_thumb.split('/')[3]
# Try getting the parent_rating_key from the grandparent's children
if not parent_rating_key:
children_list = self.get_item_children(grandparent_rating_key)
parent_rating_key = next((c['rating_key'] for c in children_list['children_list']
if c['media_index'] == parent_media_index), '')
metadata = {'media_type': metadata_type, metadata = {'media_type': metadata_type,
'section_id': section_id, 'section_id': section_id,
'library_name': library_name, 'library_name': library_name,
'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'), 'rating_key': helpers.get_xml_attr(metadata_main, 'ratingKey'),
'parent_rating_key': helpers.get_xml_attr(metadata_main, 'parentRatingKey'), 'parent_rating_key': parent_rating_key,
'grandparent_rating_key': helpers.get_xml_attr(metadata_main, 'grandparentRatingKey'), 'grandparent_rating_key': helpers.get_xml_attr(metadata_main, 'grandparentRatingKey'),
'title': helpers.get_xml_attr(metadata_main, 'title'), 'title': helpers.get_xml_attr(metadata_main, 'title'),
'parent_title': 'Season %s' % helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_title': 'Season %s' % helpers.get_xml_attr(metadata_main, 'parentIndex'),
@@ -813,18 +837,20 @@ class PmsConnect(object):
'original_title': helpers.get_xml_attr(metadata_main, 'originalTitle'), 'original_title': helpers.get_xml_attr(metadata_main, 'originalTitle'),
'sort_title': helpers.get_xml_attr(metadata_main, 'titleSort'), 'sort_title': helpers.get_xml_attr(metadata_main, 'titleSort'),
'media_index': helpers.get_xml_attr(metadata_main, 'index'), 'media_index': helpers.get_xml_attr(metadata_main, 'index'),
'parent_media_index': helpers.get_xml_attr(metadata_main, 'parentIndex'), 'parent_media_index': parent_media_index,
'studio': show_details['studio'], 'studio': show_details['studio'],
'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'), 'content_rating': helpers.get_xml_attr(metadata_main, 'contentRating'),
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
'thumb': helpers.get_xml_attr(metadata_main, 'thumb'), 'thumb': helpers.get_xml_attr(metadata_main, 'thumb'),
'parent_thumb': helpers.get_xml_attr(metadata_main, 'parentThumb'), 'parent_thumb': parent_thumb,
'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'), 'grandparent_thumb': helpers.get_xml_attr(metadata_main, 'grandparentThumb'),
'art': helpers.get_xml_attr(metadata_main, 'art'), 'art': helpers.get_xml_attr(metadata_main, 'art'),
'banner': show_details['banner'], 'banner': show_details['banner'],
@@ -863,7 +889,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -908,7 +936,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary') or artist_details['summary'], 'summary': helpers.get_xml_attr(metadata_main, 'summary') or artist_details['summary'],
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -956,7 +986,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': album_details['year'], 'year': album_details['year'],
@@ -1000,7 +1032,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -1045,7 +1079,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -1090,7 +1126,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -1136,7 +1174,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(metadata_main, 'summary'), 'summary': helpers.get_xml_attr(metadata_main, 'summary'),
'tagline': helpers.get_xml_attr(metadata_main, 'tagline'), 'tagline': helpers.get_xml_attr(metadata_main, 'tagline'),
'rating': helpers.get_xml_attr(metadata_main, 'rating'), 'rating': helpers.get_xml_attr(metadata_main, 'rating'),
'rating_image': helpers.get_xml_attr(metadata_main, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(metadata_main, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(metadata_main, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'), 'user_rating': helpers.get_xml_attr(metadata_main, 'userRating'),
'duration': helpers.get_xml_attr(metadata_main, 'duration'), 'duration': helpers.get_xml_attr(metadata_main, 'duration'),
'year': helpers.get_xml_attr(metadata_main, 'year'), 'year': helpers.get_xml_attr(metadata_main, 'year'),
@@ -1189,7 +1229,8 @@ class PmsConnect(object):
'video_width': helpers.get_xml_attr(stream, 'width'), 'video_width': helpers.get_xml_attr(stream, 'width'),
'video_language': helpers.get_xml_attr(stream, 'language'), 'video_language': helpers.get_xml_attr(stream, 'language'),
'video_language_code': helpers.get_xml_attr(stream, 'languageCode'), 'video_language_code': helpers.get_xml_attr(stream, 'languageCode'),
'video_profile': helpers.get_xml_attr(stream, 'profile') 'video_profile': helpers.get_xml_attr(stream, 'profile'),
'selected': int(helpers.get_xml_attr(stream, 'selected') == '1')
}) })
elif helpers.get_xml_attr(stream, 'streamType') == '2': elif helpers.get_xml_attr(stream, 'streamType') == '2':
@@ -1203,7 +1244,8 @@ class PmsConnect(object):
'audio_sample_rate': helpers.get_xml_attr(stream, 'samplingRate'), 'audio_sample_rate': helpers.get_xml_attr(stream, 'samplingRate'),
'audio_language': helpers.get_xml_attr(stream, 'language'), 'audio_language': helpers.get_xml_attr(stream, 'language'),
'audio_language_code': helpers.get_xml_attr(stream, 'languageCode'), 'audio_language_code': helpers.get_xml_attr(stream, 'languageCode'),
'audio_profile': helpers.get_xml_attr(stream, 'profile') 'audio_profile': helpers.get_xml_attr(stream, 'profile'),
'selected': int(helpers.get_xml_attr(stream, 'selected') == '1')
}) })
elif helpers.get_xml_attr(stream, 'streamType') == '3': elif helpers.get_xml_attr(stream, 'streamType') == '3':
@@ -1215,14 +1257,16 @@ class PmsConnect(object):
'subtitle_forced': int(helpers.get_xml_attr(stream, 'forced') == '1'), 'subtitle_forced': int(helpers.get_xml_attr(stream, 'forced') == '1'),
'subtitle_location': 'external' if helpers.get_xml_attr(stream, 'key') else 'embedded', 'subtitle_location': 'external' if helpers.get_xml_attr(stream, 'key') else 'embedded',
'subtitle_language': helpers.get_xml_attr(stream, 'language'), 'subtitle_language': helpers.get_xml_attr(stream, 'language'),
'subtitle_language_code': helpers.get_xml_attr(stream, 'languageCode') 'subtitle_language_code': helpers.get_xml_attr(stream, 'languageCode'),
'selected': int(helpers.get_xml_attr(stream, 'selected') == '1')
}) })
parts.append({'id': helpers.get_xml_attr(part, 'id'), parts.append({'id': helpers.get_xml_attr(part, 'id'),
'file': helpers.get_xml_attr(part, 'file'), 'file': helpers.get_xml_attr(part, 'file'),
'file_size': helpers.get_xml_attr(part, 'size'), 'file_size': helpers.get_xml_attr(part, 'size'),
'indexes': int(helpers.get_xml_attr(part, 'indexes') == 'sd'), 'indexes': int(helpers.get_xml_attr(part, 'indexes') == 'sd'),
'streams': streams 'streams': streams,
'selected': int(helpers.get_xml_attr(part, 'selected') == '1')
}) })
audio_channels = helpers.get_xml_attr(media, 'audioChannels') audio_channels = helpers.get_xml_attr(media, 'audioChannels')
@@ -1714,7 +1758,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(session, 'summary'), 'summary': helpers.get_xml_attr(session, 'summary'),
'tagline': helpers.get_xml_attr(session, 'tagline'), 'tagline': helpers.get_xml_attr(session, 'tagline'),
'rating': helpers.get_xml_attr(session, 'rating'), 'rating': helpers.get_xml_attr(session, 'rating'),
'rating_image': helpers.get_xml_attr(session, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(session, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(session, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(session, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(session, 'userRating'), 'user_rating': helpers.get_xml_attr(session, 'userRating'),
'duration': helpers.get_xml_attr(session, 'duration'), 'duration': helpers.get_xml_attr(session, 'duration'),
'year': helpers.get_xml_attr(session, 'year'), 'year': helpers.get_xml_attr(session, 'year'),
@@ -2037,7 +2083,9 @@ class PmsConnect(object):
'summary': helpers.get_xml_attr(m, 'summary'), 'summary': helpers.get_xml_attr(m, 'summary'),
'tagline': helpers.get_xml_attr(m, 'tagline'), 'tagline': helpers.get_xml_attr(m, 'tagline'),
'rating': helpers.get_xml_attr(m, 'rating'), 'rating': helpers.get_xml_attr(m, 'rating'),
'rating_image': helpers.get_xml_attr(m, 'ratingImage'),
'audience_rating': helpers.get_xml_attr(m, 'audienceRating'), 'audience_rating': helpers.get_xml_attr(m, 'audienceRating'),
'audience_rating_image': helpers.get_xml_attr(m, 'audienceRatingImage'),
'user_rating': helpers.get_xml_attr(m, 'userRating'), 'user_rating': helpers.get_xml_attr(m, 'userRating'),
'duration': helpers.get_xml_attr(m, 'duration'), 'duration': helpers.get_xml_attr(m, 'duration'),
'year': helpers.get_xml_attr(m, 'year'), 'year': helpers.get_xml_attr(m, 'year'),

View File

@@ -1,2 +1,2 @@
PLEXPY_BRANCH = "beta" PLEXPY_BRANCH = "master"
PLEXPY_RELEASE_VERSION = "v2.1.15-beta" PLEXPY_RELEASE_VERSION = "v2.1.20"

View File

@@ -131,6 +131,30 @@ def getVersion():
return None, 'origin', common.BRANCH return None, 'origin', common.BRANCH
def check_update(auto_update=False, notify=False):
check_github(auto_update=auto_update, notify=notify)
if not plexpy.CURRENT_VERSION:
plexpy.UPDATE_AVAILABLE = None
elif plexpy.COMMITS_BEHIND > 0 and plexpy.common.BRANCH in ('master', 'beta') and \
plexpy.common.RELEASE != plexpy.LATEST_RELEASE:
plexpy.UPDATE_AVAILABLE = 'release'
elif plexpy.COMMITS_BEHIND > 0 and plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and \
plexpy.INSTALL_TYPE != 'win':
plexpy.UPDATE_AVAILABLE = 'commit'
else:
plexpy.UPDATE_AVAILABLE = False
if plexpy.WIN_SYS_TRAY_ICON:
if plexpy.UPDATE_AVAILABLE:
icon = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images/logo_tray-update.ico')
hover_text = common.PRODUCT + ' - Update Available!'
else:
icon = os.path.join(plexpy.PROG_DIR, 'data/interfaces/', plexpy.CONFIG.INTERFACE, 'images/logo_tray.ico')
hover_text = common.PRODUCT + ' - No Update Available'
plexpy.WIN_SYS_TRAY_ICON.update(icon=icon, hover_text=hover_text)
def check_github(auto_update=False, notify=False): def check_github(auto_update=False, notify=False):
plexpy.COMMITS_BEHIND = 0 plexpy.COMMITS_BEHIND = 0

View File

@@ -31,6 +31,8 @@ import logger
name = 'websocket' name = 'websocket'
opcode_data = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY) opcode_data = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
ws_shutdown = False ws_shutdown = False
pong_timer = None
pong_count = 0
def start_thread(): def start_thread():
@@ -58,6 +60,8 @@ def on_connect():
plexpy.PLEX_SERVER_UP = True plexpy.PLEX_SERVER_UP = True
plexpy.initialize_scheduler() plexpy.initialize_scheduler()
if plexpy.CONFIG.WEBSOCKET_MONITOR_PING_PONG:
send_ping()
def on_disconnect(): def on_disconnect():
@@ -91,6 +95,37 @@ def close():
plexpy.WS_CONNECTED = False plexpy.WS_CONNECTED = False
def send_ping():
if plexpy.WS_CONNECTED:
# logger.debug(u"Tautulli WebSocket :: Sending ping.")
plexpy.WEBSOCKET.ping("Hi?")
global pong_timer
pong_timer = threading.Timer(5.0, wait_pong)
pong_timer.daemon = True
pong_timer.start()
def wait_pong():
global pong_count
pong_count += 1
logger.warning(u"Tautulli WebSocket :: Failed to receive pong from websocket, ping attempt %s." % str(pong_count))
if pong_count >= plexpy.CONFIG.WEBSOCKET_CONNECTION_ATTEMPTS:
pong_count = 0
close()
def receive_pong():
# logger.debug(u"Tautulli WebSocket :: Received pong.")
global pong_timer
global pong_count
if pong_timer:
pong_timer = pong_timer.cancel()
pong_count = 0
def run(): def run():
from websocket import create_connection from websocket import create_connection
@@ -115,24 +150,13 @@ def run():
reconnects = 0 reconnects = 0
# Try an open the websocket connection # Try an open the websocket connection
while not plexpy.WS_CONNECTED and reconnects < plexpy.CONFIG.WEBSOCKET_CONNECTION_ATTEMPTS: logger.info(u"Tautulli WebSocket :: Opening %swebsocket." % secure)
if reconnects == 0: try:
logger.info(u"Tautulli WebSocket :: Opening %swebsocket." % secure) plexpy.WEBSOCKET = create_connection(uri, header=header)
logger.info(u"Tautulli WebSocket :: Ready")
reconnects += 1 plexpy.WS_CONNECTED = True
except (websocket.WebSocketException, IOError, Exception) as e:
# Sleep 5 between connection attempts logger.error("Tautulli WebSocket :: %s." % e)
if reconnects > 1:
time.sleep(plexpy.CONFIG.WEBSOCKET_CONNECTION_TIMEOUT)
logger.info(u"Tautulli WebSocket :: Connection attempt %s." % str(reconnects))
try:
plexpy.WEBSOCKET = create_connection(uri, header=header)
logger.info(u"Tautulli WebSocket :: Ready")
plexpy.WS_CONNECTED = True
except (websocket.WebSocketException, IOError, Exception) as e:
logger.error("Tautulli WebSocket :: %s." % e)
if plexpy.WS_CONNECTED: if plexpy.WS_CONNECTED:
on_connect() on_connect()
@@ -196,7 +220,10 @@ def receive(ws):
ws.send_close() ws.send_close()
return frame.opcode, None return frame.opcode, None
elif frame.opcode == websocket.ABNF.OPCODE_PING: elif frame.opcode == websocket.ABNF.OPCODE_PING:
# logger.debug(u"Tautulli WebSocket :: Received ping, sending pong.")
ws.pong("Hi!") ws.pong("Hi!")
elif frame.opcode == websocket.ABNF.OPCODE_PONG:
receive_pong()
return None, None return None, None

View File

@@ -19,7 +19,6 @@
# Session tool to be loaded. # Session tool to be loaded.
from datetime import datetime, timedelta from datetime import datetime, timedelta
import re
from urllib import quote, unquote from urllib import quote, unquote
import cherrypy import cherrypy
@@ -37,17 +36,27 @@ JWT_ALGORITHM = 'HS256'
JWT_COOKIE_NAME = 'tautulli_token_' JWT_COOKIE_NAME = 'tautulli_token_'
def user_login(username=None, password=None): def plex_user_login(username=None, password=None, token=None, headers=None):
if not username or not password: user_token = None
return None user_id = None
# Try to login to Plex.tv to check if the user has a vaild account # Try to login to Plex.tv to check if the user has a vaild account
plex_tv = PlexTV(username=username, password=password) if username and password:
plex_user = plex_tv.get_token() plex_tv = PlexTV(username=username, password=password, headers=headers)
if plex_user: plex_user = plex_tv.get_token()
user_token = plex_user['auth_token'] if plex_user:
user_id = plex_user['user_id'] user_token = plex_user['auth_token']
user_id = plex_user['user_id']
elif token:
plex_tv = PlexTV(token=token, headers=headers)
plex_user = plex_tv.get_plex_account_details()
if plex_user:
user_token = token
user_id = plex_user['user_id']
else:
return None
if user_token and user_id:
# Try to retrieve the user from the database. # Try to retrieve the user from the database.
# Also make sure guest access is enabled for the user and the user is not deleted. # Also make sure guest access is enabled for the user and the user is not deleted.
user_data = Users() user_data = Users()
@@ -57,7 +66,7 @@ def user_login(username=None, password=None):
return None return None
elif plexpy.CONFIG.HTTP_PLEX_ADMIN and user_details['is_admin']: elif plexpy.CONFIG.HTTP_PLEX_ADMIN and user_details['is_admin']:
# Plex admin login # Plex admin login
return 'admin' return user_details, 'admin'
elif not user_details['allow_guest'] or user_details['deleted_user']: elif not user_details['allow_guest'] or user_details['deleted_user']:
# Guest access is disabled or the user is deleted. # Guest access is disabled or the user is deleted.
return None return None
@@ -68,56 +77,65 @@ def user_login(username=None, password=None):
# The user is in the database, and guest access is enabled, so try to retrieve a server token. # The user is in the database, and guest access is enabled, so try to retrieve a server token.
# If a server token is returned, then the user is a valid friend of the server. # If a server token is returned, then the user is a valid friend of the server.
plex_tv = PlexTV(token=user_token) plex_tv = PlexTV(token=user_token, headers=headers)
server_token = plex_tv.get_server_token() server_token = plex_tv.get_server_token()
if server_token: if server_token:
# Register the new user / update the access tokens. # Register the new user / update the access tokens.
monitor_db = MonitorDatabase() monitor_db = MonitorDatabase()
try: try:
logger.debug(u"Tautulli WebAuth :: Regestering tokens for user '%s' in the database." % username) logger.debug(u"Tautulli WebAuth :: Registering token for user '%s' in the database."
result = monitor_db.action('UPDATE users SET user_token = ?, server_token = ? WHERE user_id = ?', % user_details['username'])
[user_token, server_token, user_id]) result = monitor_db.action('UPDATE users SET server_token = ? WHERE user_id = ?',
[server_token, user_details['user_id']])
if result: if result:
# Refresh the users list to make sure we have all the correct permissions. # Refresh the users list to make sure we have all the correct permissions.
refresh_users() refresh_users()
# Successful login # Successful login
return 'guest' return user_details, 'guest'
else: else:
logger.warn(u"Tautulli WebAuth :: Unable to register user '%s' in database." % username) logger.warn(u"Tautulli WebAuth :: Unable to register user '%s' in database."
% user_details['username'])
return None return None
except Exception as e: except Exception as e:
logger.warn(u"Tautulli WebAuth :: Unable to register user '%s' in database: %s." % (username, e)) logger.warn(u"Tautulli WebAuth :: Unable to register user '%s' in database: %s."
% (user_details['username'], e))
return None return None
else: else:
logger.warn(u"Tautulli WebAuth :: Unable to retrieve Plex.tv server token for user '%s'." % username) logger.warn(u"Tautulli WebAuth :: Unable to retrieve Plex.tv server token for user '%s'."
% user_details['username'])
return None return None
else: elif username:
logger.warn(u"Tautulli WebAuth :: Unable to retrieve Plex.tv user token for user '%s'." % username) logger.warn(u"Tautulli WebAuth :: Unable to retrieve Plex.tv user token for user '%s'." % username)
return None return None
return None elif token:
logger.warn(u"Tautulli WebAuth :: Unable to retrieve Plex.tv user token for Plex OAuth.")
return None
def check_credentials(username, password, admin_login='0'): def check_credentials(username=None, password=None, token=None, admin_login='0', headers=None):
"""Verifies credentials for username and password. """Verifies credentials for username and password.
Returns True and the user group on success or False and no user group""" Returns True and the user group on success or False and no user group"""
if plexpy.CONFIG.HTTP_PASSWORD: if username and password:
if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ if plexpy.CONFIG.HTTP_PASSWORD:
username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): user_details = {'user_id': None, 'username': username}
return True, 'tautulli admin'
elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \
username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD: username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD):
return True, 'tautulli admin' return True, user_details, 'admin'
elif not plexpy.CONFIG.HTTP_HASHED_PASSWORD and \
username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD:
return True, user_details, 'admin'
if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS): if plexpy.CONFIG.HTTP_PLEX_ADMIN or (not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS):
plex_login = user_login(username, password) plex_login = plex_user_login(username=username, password=password, token=token, headers=headers)
if plex_login is not None: if plex_login is not None:
return True, plex_login return True, plex_login[0], plex_login[1]
return False, None return False, None, None
def check_jwt_token(): def check_jwt_token():
@@ -220,7 +238,7 @@ class AuthController(object):
return return
raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT) raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT)
def on_login(self, username, user_id=None, user_group=None, success=0): def on_login(self, username=None, user_id=None, user_group=None, success=False, oauth=False):
"""Called on successful login""" """Called on successful login"""
# Save login to the database # Save login to the database
@@ -236,8 +254,10 @@ class AuthController(object):
user_agent=user_agent, user_agent=user_agent,
success=success) success=success)
if success == 1: if success:
logger.debug(u"Tautulli WebAuth :: %s user '%s' logged into Tautulli." % (user_group.capitalize(), username)) use_oauth = 'Plex OAuth' if oauth else 'form'
logger.debug(u"Tautulli WebAuth :: %s user '%s' logged into Tautulli using %s login."
% (user_group.capitalize(), username, use_oauth))
def on_logout(self, username, user_group): def on_logout(self, username, user_group):
"""Called on logout""" """Called on logout"""
@@ -279,43 +299,37 @@ class AuthController(object):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
def signin(self, username=None, password=None, remember_me='0', admin_login='0', *args, **kwargs): def signin(self, username=None, password=None, token=None, remember_me='0', admin_login='0', *args, **kwargs):
if cherrypy.request.method != 'POST': if cherrypy.request.method != 'POST':
cherrypy.response.status = 405 cherrypy.response.status = 405
return {'status': 'error', 'message': 'Sign in using POST.'} return {'status': 'error', 'message': 'Sign in using POST.'}
error_message = {'status': 'error', 'message': 'Incorrect username or password.'} error_message = {'status': 'error', 'message': 'Invalid credentials.'}
valid_login, user_group = check_credentials(username, password, admin_login) valid_login, user_details, user_group = check_credentials(username=username,
password=password,
token=token,
admin_login=admin_login,
headers=kwargs)
if valid_login: if valid_login:
if user_group == 'tautulli admin':
user_group = 'admin'
user_id = None
else:
if re.match(r"[^@]+@[^@]+\.[^@]+", username):
user_details = Users().get_details(email=username)
else:
user_details = Users().get_details(user=username)
user_id = user_details['user_id']
time_delta = timedelta(days=30) if remember_me == '1' else timedelta(minutes=60) time_delta = timedelta(days=30) if remember_me == '1' else timedelta(minutes=60)
expiry = datetime.utcnow() + time_delta expiry = datetime.utcnow() + time_delta
payload = { payload = {
'user_id': user_id, 'user_id': user_details['user_id'],
'user': username, 'user': user_details['username'],
'user_group': user_group, 'user_group': user_group,
'exp': expiry 'exp': expiry
} }
jwt_token = jwt.encode(payload, plexpy.CONFIG.JWT_SECRET, algorithm=JWT_ALGORITHM) jwt_token = jwt.encode(payload, plexpy.CONFIG.JWT_SECRET, algorithm=JWT_ALGORITHM)
self.on_login(username=username, self.on_login(username=user_details['username'],
user_id=user_id, user_id=user_details['user_id'],
user_group=user_group, user_group=user_group,
success=1) success=True,
oauth=bool(token))
jwt_cookie = JWT_COOKIE_NAME + plexpy.CONFIG.PMS_UUID jwt_cookie = JWT_COOKIE_NAME + plexpy.CONFIG.PMS_UUID
cherrypy.response.cookie[jwt_cookie] = jwt_token cherrypy.response.cookie[jwt_cookie] = jwt_token
@@ -326,14 +340,20 @@ class AuthController(object):
cherrypy.response.status = 200 cherrypy.response.status = 200
return {'status': 'success', 'token': jwt_token.decode('utf-8'), 'uuid': plexpy.CONFIG.PMS_UUID} return {'status': 'success', 'token': jwt_token.decode('utf-8'), 'uuid': plexpy.CONFIG.PMS_UUID}
elif admin_login == '1': elif admin_login == '1' and username:
self.on_login(username=username) self.on_login(username=username)
logger.debug(u"Tautulli WebAuth :: Invalid admin login attempt from '%s'." % username) logger.debug(u"Tautulli WebAuth :: Invalid admin login attempt from '%s'." % username)
cherrypy.response.status = 401 cherrypy.response.status = 401
return error_message return error_message
else: elif username:
self.on_login(username=username) self.on_login(username=username)
logger.debug(u"Tautulli WebAuth :: Invalid login attempt from '%s'." % username) logger.debug(u"Tautulli WebAuth :: Invalid user login attempt from '%s'." % username)
cherrypy.response.status = 401
return error_message
elif token:
self.on_login(username='Plex OAuth', oauth=True)
logger.debug(u"Tautulli WebAuth :: Invalid Plex OAuth login attempt.")
cherrypy.response.status = 401 cherrypy.response.status = 401
return error_message return error_message

View File

@@ -110,6 +110,7 @@ class WebInterface(object):
"pms_is_cloud": plexpy.CONFIG.PMS_IS_CLOUD, "pms_is_cloud": plexpy.CONFIG.PMS_IS_CLOUD,
"pms_token": plexpy.CONFIG.PMS_TOKEN, "pms_token": plexpy.CONFIG.PMS_TOKEN,
"pms_uuid": plexpy.CONFIG.PMS_UUID, "pms_uuid": plexpy.CONFIG.PMS_UUID,
"pms_name": plexpy.CONFIG.PMS_NAME,
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL "logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL
} }
@@ -277,7 +278,7 @@ class WebInterface(object):
def return_plex_xml_url(self, endpoint='', plextv=False, **kwargs): def return_plex_xml_url(self, endpoint='', plextv=False, **kwargs):
kwargs['X-Plex-Token'] = plexpy.CONFIG.PMS_TOKEN kwargs['X-Plex-Token'] = plexpy.CONFIG.PMS_TOKEN
if plextv: if plextv == 'true':
base_url = 'https://plex.tv' base_url = 'https://plex.tv'
else: else:
if plexpy.CONFIG.PMS_URL_OVERRIDE: if plexpy.CONFIG.PMS_URL_OVERRIDE:
@@ -2802,6 +2803,7 @@ class WebInterface(object):
"pms_url_manual": checked(plexpy.CONFIG.PMS_URL_MANUAL), "pms_url_manual": checked(plexpy.CONFIG.PMS_URL_MANUAL),
"pms_uuid": plexpy.CONFIG.PMS_UUID, "pms_uuid": plexpy.CONFIG.PMS_UUID,
"pms_web_url": plexpy.CONFIG.PMS_WEB_URL, "pms_web_url": plexpy.CONFIG.PMS_WEB_URL,
"pms_name": plexpy.CONFIG.PMS_NAME,
"date_format": plexpy.CONFIG.DATE_FORMAT, "date_format": plexpy.CONFIG.DATE_FORMAT,
"time_format": plexpy.CONFIG.TIME_FORMAT, "time_format": plexpy.CONFIG.TIME_FORMAT,
"week_start_monday": checked(plexpy.CONFIG.WEEK_START_MONDAY), "week_start_monday": checked(plexpy.CONFIG.WEEK_START_MONDAY),
@@ -2853,7 +2855,8 @@ class WebInterface(object):
"newsletter_auth": plexpy.CONFIG.NEWSLETTER_AUTH, "newsletter_auth": plexpy.CONFIG.NEWSLETTER_AUTH,
"newsletter_password": plexpy.CONFIG.NEWSLETTER_PASSWORD, "newsletter_password": plexpy.CONFIG.NEWSLETTER_PASSWORD,
"newsletter_inline_styles": checked(plexpy.CONFIG.NEWSLETTER_INLINE_STYLES), "newsletter_inline_styles": checked(plexpy.CONFIG.NEWSLETTER_INLINE_STYLES),
"newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR "newsletter_custom_dir": plexpy.CONFIG.NEWSLETTER_CUSTOM_DIR,
"win_sys_tray": checked(plexpy.CONFIG.WIN_SYS_TRAY)
} }
return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs) return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs)
@@ -2875,7 +2878,7 @@ class WebInterface(object):
"allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip", "allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip",
"history_table_activity", "plexpy_auto_update", "history_table_activity", "plexpy_auto_update",
"themoviedb_lookup", "tvmaze_lookup", "http_plex_admin", "themoviedb_lookup", "tvmaze_lookup", "http_plex_admin",
"newsletter_self_hosted", "newsletter_inline_styles" "newsletter_self_hosted", "newsletter_inline_styles", "win_sys_tray"
] ]
for checked_config in checked_configs: for checked_config in checked_configs:
if checked_config not in kwargs: if checked_config not in kwargs:
@@ -3800,16 +3803,15 @@ class WebInterface(object):
} }
``` ```
""" """
versioncheck.check_github() versioncheck.check_update()
if not plexpy.CURRENT_VERSION: if plexpy.UPDATE_AVAILABLE is None:
return {'result': 'error', return {'result': 'error',
'update': None, 'update': None,
'message': 'You are running an unknown version of Tautulli.' 'message': 'You are running an unknown version of Tautulli.'
} }
elif plexpy.COMMITS_BEHIND > 0 and plexpy.common.BRANCH in ('master', 'beta') and \ elif plexpy.UPDATE_AVAILABLE == 'release':
plexpy.common.RELEASE != plexpy.LATEST_RELEASE:
return {'result': 'success', return {'result': 'success',
'update': True, 'update': True,
'release': True, 'release': True,
@@ -3822,8 +3824,7 @@ class WebInterface(object):
plexpy.LATEST_RELEASE)) plexpy.LATEST_RELEASE))
} }
elif plexpy.COMMITS_BEHIND > 0 and plexpy.CURRENT_VERSION != plexpy.LATEST_VERSION and \ elif plexpy.UPDATE_AVAILABLE == 'commit':
plexpy.INSTALL_TYPE != 'win':
return {'result': 'success', return {'result': 'success',
'update': True, 'update': True,
'release': False, 'release': False,
@@ -4030,7 +4031,7 @@ class WebInterface(object):
return self.real_pms_image_proxy(**kwargs) return self.real_pms_image_proxy(**kwargs)
@addtoapi('pms_image_proxy') @addtoapi('pms_image_proxy')
def real_pms_image_proxy(self, img='', rating_key=None, width=0, height=0, def real_pms_image_proxy(self, img=None, rating_key=None, width=750, height=1000,
opacity=100, background='000000', blur=0, img_format='png', opacity=100, background='000000', blur=0, img_format='png',
fallback=None, refresh=False, clip=False, **kwargs): fallback=None, refresh=False, clip=False, **kwargs):
""" Gets an image from the PMS and saves it to the image cache directory. """ Gets an image from the PMS and saves it to the image cache directory.
@@ -4050,6 +4051,7 @@ class WebInterface(object):
img_format (str): png img_format (str): png
fallback (str): "poster", "cover", "art" fallback (str): "poster", "cover", "art"
refresh (bool): True or False whether to refresh the image cache refresh (bool): True or False whether to refresh the image cache
return_hash (bool): True or False to return the self-hosted image hash instead of the image
Returns: Returns:
None None
@@ -4059,6 +4061,8 @@ class WebInterface(object):
logger.warn('No image input received.') logger.warn('No image input received.')
return return
return_hash = (kwargs.get('return_hash') == 'true')
if rating_key and not img: if rating_key and not img:
if fallback == 'art': if fallback == 'art':
img = '/library/metadata/{}/art'.format(rating_key) img = '/library/metadata/{}/art'.format(rating_key)
@@ -4069,9 +4073,13 @@ class WebInterface(object):
img = '/'.join(img_split[:5]) img = '/'.join(img_split[:5])
rating_key = rating_key or img_split[3] rating_key = rating_key or img_split[3]
img_string = '{}.{}.{}.{}.{}.{}.{}.{}'.format( img_hash = notification_handler.set_hash_image_info(
plexpy.CONFIG.PMS_UUID, img, rating_key, width, height, opacity, background, blur, fallback) img=img, rating_key=rating_key, width=width, height=height,
img_hash = hashlib.sha256(img_string).hexdigest() opacity=opacity, background=background, blur=blur, fallback=fallback,
add_to_db=return_hash)
if return_hash:
return {'img_hash': img_hash}
fp = '{}.{}'.format(img_hash, img_format) # we want to be able to preview the thumbs fp = '{}.{}'.format(img_hash, img_format) # we want to be able to preview the thumbs
c_dir = os.path.join(plexpy.CONFIG.CACHE_DIR, 'images') c_dir = os.path.join(plexpy.CONFIG.CACHE_DIR, 'images')
@@ -4560,6 +4568,7 @@ class WebInterface(object):
"added_at": "1461572396", "added_at": "1461572396",
"art": "/library/metadata/1219/art/1462175063", "art": "/library/metadata/1219/art/1462175063",
"audience_rating": "8", "audience_rating": "8",
"audience_rating_image": "rottentomatoes://image.rating.upright",
"banner": "/library/metadata/1219/banner/1462175063", "banner": "/library/metadata/1219/banner/1462175063",
"collections": [], "collections": [],
"content_rating": "TV-MA", "content_rating": "TV-MA",
@@ -4613,7 +4622,8 @@ class WebInterface(object):
"video_language_code": "", "video_language_code": "",
"video_profile": "high", "video_profile": "high",
"video_ref_frames": "4", "video_ref_frames": "4",
"video_width": "1920" "video_width": "1920",
"selected": 0
}, },
{ {
"audio_bitrate": "384", "audio_bitrate": "384",
@@ -4626,7 +4636,8 @@ class WebInterface(object):
"audio_profile": "", "audio_profile": "",
"audio_sample_rate": "48000", "audio_sample_rate": "48000",
"id": "511664", "id": "511664",
"type": "2" "type": "2",
"selected": 1
}, },
{ {
"id": "511953", "id": "511953",
@@ -4637,7 +4648,8 @@ class WebInterface(object):
"subtitle_language": "English", "subtitle_language": "English",
"subtitle_language_code": "eng", "subtitle_language_code": "eng",
"subtitle_location": "external", "subtitle_location": "external",
"type": "3" "type": "3",
"selected": 1
} }
] ]
} }
@@ -4657,6 +4669,7 @@ class WebInterface(object):
"parent_thumb": "/library/metadata/153036/thumb/1462175062", "parent_thumb": "/library/metadata/153036/thumb/1462175062",
"parent_title": "", "parent_title": "",
"rating": "7.8", "rating": "7.8",
"rating_image": "rottentomatoes://image.rating.ripe",
"rating_key": "153037", "rating_key": "153037",
"section_id": "2", "section_id": "2",
"sort_title": "Game of Thrones", "sort_title": "Game of Thrones",
@@ -4893,7 +4906,7 @@ class WebInterface(object):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth() @requireAuth()
@addtoapi() @addtoapi()
def get_activity(self, session_key=None, **kwargs): def get_activity(self, session_key=None, session_id=None, **kwargs):
""" Get the current activity on the PMS. """ Get the current activity on the PMS.
``` ```
@@ -4901,7 +4914,8 @@ class WebInterface(object):
None None
Optional parameters: Optional parameters:
None session_key (int): Session key for the session info to return, OR
session_id (str): Session ID for the session info to return
Returns: Returns:
json: json:
@@ -4920,6 +4934,7 @@ class WebInterface(object):
"art": "/library/metadata/1219/art/1503306930", "art": "/library/metadata/1219/art/1503306930",
"aspect_ratio": "1.78", "aspect_ratio": "1.78",
"audience_rating": "", "audience_rating": "",
"audience_rating_image": "rottentomatoes://image.rating.upright",
"audio_bitrate": "384", "audio_bitrate": "384",
"audio_bitrate_mode": "", "audio_bitrate_mode": "",
"audio_channel_layout": "5.1(side)", "audio_channel_layout": "5.1(side)",
@@ -4996,6 +5011,7 @@ class WebInterface(object):
"progress_percent": "0", "progress_percent": "0",
"quality_profile": "Original", "quality_profile": "Original",
"rating": "7.8", "rating": "7.8",
"rating_image": "rottentomatoes://image.rating.ripe",
"rating_key": "153037", "rating_key": "153037",
"relay": 0, "relay": 0,
"section_id": "2", "section_id": "2",
@@ -5130,6 +5146,8 @@ class WebInterface(object):
if result: if result:
if session_key: if session_key:
return next((s for s in result['sessions'] if s['session_key'] == session_key), {}) return next((s for s in result['sessions'] if s['session_key'] == session_key), {})
if session_id:
return next((s for s in result['sessions'] if s['session_id'] == session_id), {})
counts = {'stream_count_direct_play': 0, counts = {'stream_count_direct_play': 0,
'stream_count_direct_stream': 0, 'stream_count_direct_stream': 0,

View File

@@ -202,6 +202,8 @@ def initialize(options):
# Prevent time-outs # Prevent time-outs
cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.engine.timeout_monitor.unsubscribe()
cherrypy.tree.mount(WebInterface(), options['http_root'], config=conf) cherrypy.tree.mount(WebInterface(), options['http_root'], config=conf)
if plexpy.HTTP_ROOT != '/':
cherrypy.tree.mount(BaseRedirect(), '/')
try: try:
logger.info(u"Tautulli WebStart :: Starting Tautulli web server on %s://%s:%d%s", protocol, logger.info(u"Tautulli WebStart :: Starting Tautulli web server on %s://%s:%d%s", protocol,
@@ -218,3 +220,9 @@ def initialize(options):
sys.exit(1) sys.exit(1)
cherrypy.server.wait() cherrypy.server.wait()
class BaseRedirect(object):
@cherrypy.expose
def index(self):
raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT)