mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 04:49:36 -07:00
Add CustomArrow date/time formatter
This commit is contained in:
parent
ab5836a65b
commit
2da3714dd1
1 changed files with 33 additions and 14 deletions
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from typing import Optional
|
||||||
from future.builtins import next
|
from future.builtins import next
|
||||||
from future.builtins import map
|
from future.builtins import map
|
||||||
from future.builtins import str
|
from future.builtins import str
|
||||||
|
@ -1006,21 +1007,21 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
|
||||||
'product': notify_params['product'],
|
'product': notify_params['product'],
|
||||||
'player': notify_params['player'],
|
'player': notify_params['player'],
|
||||||
'ip_address': notify_params.get('ip_address', 'N/A'),
|
'ip_address': notify_params.get('ip_address', 'N/A'),
|
||||||
'started_datestamp': arrow.get(notify_params['started']).format(date_format) if notify_params['started'] else '',
|
'started_datestamp': CustomArrow(arrow.get(notify_params['started']), date_format) if notify_params['started'] else '',
|
||||||
'started_timestamp': arrow.get(notify_params['started']).format(time_format) if notify_params['started'] else '',
|
'started_timestamp': CustomArrow(arrow.get(notify_params['started']), time_format) if notify_params['started'] else '',
|
||||||
'started_unixtime': notify_params['started'],
|
'started_unixtime': notify_params['started'],
|
||||||
'stopped_datestamp': arrow.get(notify_params['stopped']).format(date_format) if notify_params['stopped'] else '',
|
'stopped_datestamp': CustomArrow(arrow.get(notify_params['stopped']), date_format) if notify_params['stopped'] else '',
|
||||||
'stopped_timestamp': arrow.get(notify_params['stopped']).format(time_format) if notify_params['stopped'] else '',
|
'stopped_timestamp': CustomArrow(arrow.get(notify_params['stopped']), time_format) if notify_params['stopped'] else '',
|
||||||
'stopped_unixtime': notify_params['stopped'],
|
'stopped_unixtime': notify_params['stopped'],
|
||||||
'stream_duration': stream_duration,
|
'stream_duration': stream_duration,
|
||||||
'stream_duration_sec': stream_duration_sec,
|
'stream_duration_sec': stream_duration_sec,
|
||||||
'stream_time': arrow.get(stream_duration_sec).format(duration_format),
|
'stream_time': CustomArrow(arrow.get(stream_duration_sec), duration_format),
|
||||||
'remaining_duration': remaining_duration,
|
'remaining_duration': remaining_duration,
|
||||||
'remaining_duration_sec': remaining_duration_sec,
|
'remaining_duration_sec': remaining_duration_sec,
|
||||||
'remaining_time': arrow.get(remaining_duration_sec).format(duration_format),
|
'remaining_time': CustomArrow(arrow.get(remaining_duration_sec), duration_format),
|
||||||
'progress_duration': progress_duration,
|
'progress_duration': progress_duration,
|
||||||
'progress_duration_sec': progress_duration_sec,
|
'progress_duration_sec': progress_duration_sec,
|
||||||
'progress_time': arrow.get(progress_duration_sec).format(duration_format),
|
'progress_time': CustomArrow(arrow.get(progress_duration_sec), duration_format),
|
||||||
'progress_percent': helpers.get_percent(progress_duration_sec, duration_sec),
|
'progress_percent': helpers.get_percent(progress_duration_sec, duration_sec),
|
||||||
'view_offset': session.get('view_offset', 0),
|
'view_offset': session.get('view_offset', 0),
|
||||||
'initial_stream': notify_params['initial_stream'],
|
'initial_stream': notify_params['initial_stream'],
|
||||||
|
@ -1128,15 +1129,15 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
|
||||||
'track_count': grandchild_count,
|
'track_count': grandchild_count,
|
||||||
'year': notify_params['year'],
|
'year': notify_params['year'],
|
||||||
'show_year': show_year,
|
'show_year': show_year,
|
||||||
'release_date': arrow.get(notify_params['originally_available_at']).format(date_format)
|
'release_date': CustomArrow(arrow.get(notify_params['originally_available_at']), date_format)
|
||||||
if notify_params['originally_available_at'] else '',
|
if notify_params['originally_available_at'] else '',
|
||||||
'air_date': arrow.get(notify_params['originally_available_at']).format(date_format)
|
'air_date': CustomArrow(arrow.get(notify_params['originally_available_at']), date_format)
|
||||||
if notify_params['originally_available_at'] else '',
|
if notify_params['originally_available_at'] else '',
|
||||||
'added_date': arrow.get(int(notify_params['added_at'])).format(date_format)
|
'added_date': CustomArrow(arrow.get(int(notify_params['added_at'])), date_format)
|
||||||
if notify_params['added_at'] else '',
|
if notify_params['added_at'] else '',
|
||||||
'updated_date': arrow.get(int(notify_params['updated_at'])).format(date_format)
|
'updated_date': CustomArrow(arrow.get(int(notify_params['updated_at'])), date_format)
|
||||||
if notify_params['updated_at'] else '',
|
if notify_params['updated_at'] else '',
|
||||||
'last_viewed_date': arrow.get(int(notify_params['last_viewed_at'])).format(date_format)
|
'last_viewed_date': CustomArrow(arrow.get(int(notify_params['last_viewed_at'])), date_format)
|
||||||
if notify_params['last_viewed_at'] else '',
|
if notify_params['last_viewed_at'] else '',
|
||||||
'studio': notify_params['studio'],
|
'studio': notify_params['studio'],
|
||||||
'content_rating': notify_params['content_rating'],
|
'content_rating': notify_params['content_rating'],
|
||||||
|
@ -1155,7 +1156,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'duration_sec': duration_sec,
|
'duration_sec': duration_sec,
|
||||||
'duration_ms': notify_params['duration'],
|
'duration_ms': notify_params['duration'],
|
||||||
'druation_time': arrow.get(duration_sec).format(duration_format),
|
'druation_time': CustomArrow(arrow.get(duration_sec), duration_format),
|
||||||
'poster_title': notify_params['poster_title'],
|
'poster_title': notify_params['poster_title'],
|
||||||
'poster_url': notify_params['poster_url'],
|
'poster_url': notify_params['poster_url'],
|
||||||
'plex_id': notify_params['plex_id'],
|
'plex_id': notify_params['plex_id'],
|
||||||
|
@ -1292,7 +1293,7 @@ def build_server_notify_params(notify_action=None, **kwargs):
|
||||||
# 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'],
|
||||||
'update_release_date': arrow.get(pms_download_info['release_date']).format(date_format)
|
'update_release_date': CustomArrow(arrow.get(pms_download_info['release_date']), date_format)
|
||||||
if pms_download_info['release_date'] else '',
|
if pms_download_info['release_date'] else '',
|
||||||
'update_channel': 'Beta' if update_channel == 'beta' else 'Public',
|
'update_channel': 'Beta' if update_channel == 'beta' else 'Public',
|
||||||
'update_platform': pms_download_info['platform'],
|
'update_platform': pms_download_info['platform'],
|
||||||
|
@ -2095,3 +2096,21 @@ class CustomFormatter(Formatter):
|
||||||
return ''.join(result)
|
return ''.join(result)
|
||||||
else:
|
else:
|
||||||
return ''.join(result), auto_arg_index
|
return ''.join(result), auto_arg_index
|
||||||
|
|
||||||
|
|
||||||
|
class CustomArrow:
|
||||||
|
def __init__(self, arrow_value: arrow.arrow.Arrow, default_format: Optional[str] = None):
|
||||||
|
self.arrow_value = arrow_value
|
||||||
|
self.default_format = default_format
|
||||||
|
|
||||||
|
def __format__(self, formatstr: str) -> str:
|
||||||
|
if len(formatstr) > 0:
|
||||||
|
return self.arrow_value.format(formatstr)
|
||||||
|
|
||||||
|
if self.default_format is not None:
|
||||||
|
return self.__format__(self.default_format)
|
||||||
|
|
||||||
|
return str(self.arrow_value)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.__format__('')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue