|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
|
|
|
# This file is part of SickGear.
|
|
|
|
#
|
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import functools
|
|
|
|
import locale
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from dateutil import tz
|
|
|
|
|
|
|
|
from six import integer_types, PY2, string_types
|
|
|
|
|
|
|
|
# noinspection PyUnreachableCode
|
|
|
|
if False:
|
|
|
|
from typing import Callable, Optional, Union
|
|
|
|
|
|
|
|
date_presets = ('%Y-%m-%d',
|
|
|
|
'%a, %Y-%m-%d',
|
|
|
|
'%A, %Y-%m-%d',
|
|
|
|
'%y-%m-%d',
|
|
|
|
'%a, %y-%m-%d',
|
|
|
|
'%A, %y-%m-%d',
|
|
|
|
'%m/%d/%Y',
|
|
|
|
'%a, %m/%d/%Y',
|
|
|
|
'%A, %m/%d/%Y',
|
|
|
|
'%m/%d/%y',
|
|
|
|
'%a, %m/%d/%y',
|
|
|
|
'%A, %m/%d/%y',
|
|
|
|
'%m-%d-%Y',
|
|
|
|
'%a, %m-%d-%Y',
|
|
|
|
'%A, %m-%d-%Y',
|
|
|
|
'%m-%d-%y',
|
|
|
|
'%a, %m-%d-%y',
|
|
|
|
'%A, %m-%d-%y',
|
|
|
|
'%m.%d.%Y',
|
|
|
|
'%a, %m.%d.%Y',
|
|
|
|
'%A, %m.%d.%Y',
|
|
|
|
'%m.%d.%y',
|
|
|
|
'%a, %m.%d.%y',
|
|
|
|
'%A, %m.%d.%y',
|
|
|
|
'%d-%m-%Y',
|
|
|
|
'%a, %d-%m-%Y',
|
|
|
|
'%A, %d-%m-%Y',
|
|
|
|
'%d-%m-%y',
|
|
|
|
'%a, %d-%m-%y',
|
|
|
|
'%A, %d-%m-%y',
|
|
|
|
'%d/%m/%Y',
|
|
|
|
'%a, %d/%m/%Y',
|
|
|
|
'%A, %d/%m/%Y',
|
|
|
|
'%d/%m/%y',
|
|
|
|
'%a, %d/%m/%y',
|
|
|
|
'%A, %d/%m/%y',
|
|
|
|
'%d.%m.%Y',
|
|
|
|
'%a, %d.%m.%Y',
|
|
|
|
'%A, %d.%m.%Y',
|
|
|
|
'%d.%m.%y',
|
|
|
|
'%a, %d.%m.%y',
|
|
|
|
'%A, %d.%m.%y',
|
|
|
|
'%d. %b %Y',
|
|
|
|
'%a, %d. %b %Y',
|
|
|
|
'%A, %d. %b %Y',
|
|
|
|
'%d. %b %y',
|
|
|
|
'%a, %d. %b %y',
|
|
|
|
'%A, %d. %b %y',
|
|
|
|
'%d. %B %Y',
|
|
|
|
'%a, %d. %B %Y',
|
|
|
|
'%A, %d. %B %Y',
|
|
|
|
'%d. %B %y',
|
|
|
|
'%a, %d. %B %y',
|
|
|
|
'%A, %d. %B %y',
|
|
|
|
'%b %d, %Y',
|
|
|
|
'%a, %b %d, %Y',
|
|
|
|
'%A, %b %d, %Y',
|
|
|
|
'%B %d, %Y',
|
|
|
|
'%a, %B %d, %Y',
|
|
|
|
'%A, %B %d, %Y')
|
|
|
|
|
|
|
|
time_presets = ('%I:%M:%S %p',
|
|
|
|
'%I:%M:%S %P',
|
|
|
|
'%H:%M:%S')
|
|
|
|
|
|
|
|
is_win = 'win32' == sys.platform
|
|
|
|
|
|
|
|
|
|
|
|
# helper decorator class
|
|
|
|
# noinspection PyPep8Naming
|
|
|
|
class static_or_instance(object):
|
|
|
|
def __init__(self, func):
|
|
|
|
self.func = func
|
|
|
|
|
|
|
|
def __get__(self, instance, owner):
|
|
|
|
return functools.partial(self.func, instance)
|
|
|
|
|
|
|
|
|
|
|
|
# subclass datetime.datetime to add function to display custom date and time formats
|
|
|
|
class SGDatetime(datetime.datetime):
|
|
|
|
has_locale = True
|
|
|
|
|
|
|
|
@static_or_instance
|
|
|
|
def is_locale_eng(self):
|
|
|
|
today = SGDatetime.sbfdate(SGDatetime.now(), '%A').lower()
|
|
|
|
return ('day' == today[-3::] and today[0:-3:] in ['sun', 'mon', 'tues', 'wednes', 'thurs', 'fri', 'satur']
|
|
|
|
and SGDatetime.sbfdate(SGDatetime.now(), '%B').lower() in [
|
|
|
|
'january', 'february', 'march', 'april', 'may', 'june',
|
|
|
|
'july', 'august', 'september', 'october', 'november', 'december'])
|
|
|
|
|
|
|
|
@static_or_instance
|
|
|
|
def convert_to_setting(self, dt=None, force_local=False):
|
|
|
|
# type: (Optional[datetime.datetime, SGDatetime], bool) -> Union[SGDatetime, datetime.datetime]
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
try:
|
|
|
|
if force_local or 'local' == sickbeard.TIMEZONE_DISPLAY:
|
|
|
|
from sickbeard.network_timezones import SG_TIMEZONE
|
|
|
|
return obj.astimezone(SG_TIMEZONE)
|
|
|
|
except (BaseException, Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
@static_or_instance
|
|
|
|
def setlocale(self, setlocale=True, use_has_locale=None, locale_str=''):
|
|
|
|
if setlocale:
|
|
|
|
try:
|
|
|
|
if None is use_has_locale or use_has_locale:
|
|
|
|
locale.setlocale(locale.LC_TIME, locale_str)
|
|
|
|
except locale.Error:
|
|
|
|
if None is not use_has_locale:
|
|
|
|
SGDatetime.has_locale = False
|
|
|
|
pass
|
|
|
|
|
|
|
|
# display Time in SickGear Format
|
|
|
|
@static_or_instance
|
|
|
|
def sbftime(self, dt=None, show_seconds=False, t_preset=None, setlocale=True, markup=False):
|
|
|
|
|
|
|
|
SGDatetime.setlocale(setlocale=setlocale, use_has_locale=SGDatetime.has_locale, locale_str='us_US')
|
|
|
|
|
|
|
|
strt = ''
|
|
|
|
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
if None is not obj:
|
|
|
|
tmpl = (((sickbeard.TIME_PRESET, sickbeard.TIME_PRESET_W_SECONDS)[show_seconds]),
|
|
|
|
t_preset)[None is not t_preset]
|
|
|
|
tmpl = (tmpl.replace(':%S', ''), tmpl)[show_seconds]
|
|
|
|
|
|
|
|
strt = SGDatetime.sbstrftime(obj, tmpl.replace('%P', '%p'))
|
|
|
|
|
|
|
|
if sickbeard.TRIM_ZERO:
|
|
|
|
strt = re.sub(r'^0(\d:\d\d)', r'\1', strt)
|
|
|
|
|
|
|
|
if re.search(r'(?im)%p$', tmpl):
|
|
|
|
if '%p' in tmpl:
|
|
|
|
strt = strt.upper()
|
|
|
|
elif '%P' in tmpl:
|
|
|
|
strt = strt.lower()
|
|
|
|
|
|
|
|
if sickbeard.TRIM_ZERO:
|
|
|
|
strt = re.sub(r'(?im)^(\d+)(?::00)?(\s?[ap]m)', r'\1\2', strt)
|
|
|
|
|
|
|
|
if markup:
|
|
|
|
match = re.search(r'(?im)(\d{1,2})(?:(.)(\d\d)(?:(.)(\d\d))?)?(?:\s?([ap]m))?$', strt)
|
|
|
|
if match:
|
|
|
|
strt = ('%s%s%s%s%s%s' % (
|
|
|
|
('<span class="time-hr">%s</span>' % match.group(1), '')[None is match.group(1)],
|
|
|
|
('<span class="time-hr-min">%s</span>' % match.group(2), '')[None is match.group(2)],
|
|
|
|
('<span class="time-min">%s</span>' % match.group(3), '')[None is match.group(3)],
|
|
|
|
('<span class="time-min-sec">%s</span>' % match.group(4), '')[None is match.group(4)],
|
|
|
|
('<span class="time-sec">%s</span>' % match.group(5), '')[None is match.group(5)],
|
|
|
|
('<span class="time-am-pm">%s</span>' % match.group(6), '')[None is match.group(6)]))
|
|
|
|
|
|
|
|
SGDatetime.setlocale(setlocale=setlocale, use_has_locale=SGDatetime.has_locale)
|
|
|
|
return strt
|
|
|
|
|
|
|
|
# display Date in SickGear Format
|
|
|
|
@static_or_instance
|
|
|
|
def sbfdate(self, dt=None, d_preset=None, setlocale=True):
|
|
|
|
|
|
|
|
SGDatetime.setlocale(setlocale=setlocale)
|
|
|
|
|
|
|
|
strd = ''
|
|
|
|
try:
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
if None is not obj:
|
|
|
|
strd = SGDatetime.sbstrftime(obj, (sickbeard.DATE_PRESET, d_preset)[None is not d_preset])
|
|
|
|
|
|
|
|
finally:
|
|
|
|
SGDatetime.setlocale(setlocale=setlocale)
|
|
|
|
return strd
|
|
|
|
|
|
|
|
# display Datetime in SickGear Format
|
|
|
|
@static_or_instance
|
|
|
|
def sbfdatetime(self, dt=None, show_seconds=False, d_preset=None, t_preset=None, markup=False):
|
|
|
|
|
|
|
|
SGDatetime.setlocale()
|
|
|
|
|
|
|
|
strd = ''
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
try:
|
|
|
|
if None is not obj:
|
|
|
|
strd = u'%s, %s' % (
|
|
|
|
SGDatetime.sbstrftime(obj, (sickbeard.DATE_PRESET, d_preset)[None is not d_preset]),
|
|
|
|
SGDatetime.sbftime(dt, show_seconds, t_preset, False, markup))
|
|
|
|
|
|
|
|
finally:
|
|
|
|
SGDatetime.setlocale(use_has_locale=SGDatetime.has_locale)
|
|
|
|
return strd
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def sbstrftime(obj, str_format):
|
|
|
|
try:
|
|
|
|
result = obj.strftime(str_format),
|
|
|
|
except ValueError:
|
|
|
|
result = obj.replace(tzinfo=None).strftime(str_format)
|
|
|
|
return result if isinstance(result, string_types) else \
|
|
|
|
isinstance(result, tuple) and 1 == len(result) and '%s' % result[0] or ''
|
|
|
|
|
|
|
|
@static_or_instance
|
|
|
|
def to_file_timestamp(self, dt=None):
|
|
|
|
# type: (Optional[SGDatetime, datetime.datetime]) -> Union[float, integer_types]
|
|
|
|
"""
|
|
|
|
convert datetime to filetime
|
|
|
|
special handling for windows filetime issues
|
|
|
|
for pre Windows 7 this can result in an exception for pre 1970 dates
|
|
|
|
"""
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
if is_win:
|
|
|
|
from .network_timezones import EPOCH_START_WIN
|
|
|
|
return (obj.replace(tzinfo=tz.tzwinlocal()) - EPOCH_START_WIN).total_seconds()
|
|
|
|
return SGDatetime.timestamp_far(obj)
|
|
|
|
|
|
|
|
@staticmethod
|
Add support for multiple TV info sources.
Changelog
---------
Change improve loading speed of shows at startup.
Change improve main execution loop speed.
Add force cast update to view show page.
Add person view.
Add character view.
Add characters, person to clean-up cache (30 days).
Add reload person, character images every 7 days.
Add suppress UI notification for scheduled people updates during show updates and during switching ids.
Add resume support of switched shows after restart that switched id but not finished updating.
Add failed TV info switches to show tasks page.
Add remove item from queue and clear queue test buttons to mange/show-tasks and manage/search-tasks.
Change improve show update logic.
Add to view-show page a notification message if a show fails to switch.
Add check for existing show with new id pair before switching.
Change prioritize first episode start year over the start year set at the tv info source.
Change delete non existing episodes when switching indexer.
Change "exists in db" link on search results page to support any info source.
Add TMDB person pics as fallback.
Add use person fallback for character images.
Add logic to add start, end year in case of multiple characters per person.
Change improve speed getting list in the import view.
Add abort people cast update when show is deleted, also remove show from any queued show item or search item
Support list of names to search for in show search.
Change assist user search terms when the actual title of a show is unknown.
Add support URLs in search.
Change remove year from search term ... year is still used for relevancy order.
Add updating show.nfo when a cast changes.
Change use longest biography available for output.
Add UI requests of details for feb 28 will also return feb 29 in years without feb 29.
Add fetch extra data fallback from TMDB for persons.
technical commit messages (combined commits)
--------------------------------------------
Add tmdb get_trending, get_popular, get_top_rated, discover to tvinfoapi.
Add home/get_persons ajax endpoint, currently supports: birthday, deathday, names.
Change daily-schedule to new get_episode_time - More TODO
Change view-show to use get_episode_time.
Add get show updates list in show updater.
Add get_episode_time to network_timezones.
Add airtime for episode and show to get_episode_time.
Small ep obj load performance improvement.
Add handle special episodes and assign numbers based on airdate.
Add handle tvmaze specials without airdate.
Change during switch tv info source, specials are removed from db because of non-existing generic numbering.
Change add first/latest regular episode, use first_aired_regular_episode in all places that have airdate of first episode.
Add IMDb to person interface.
Add akas to person.
Add IMDb bio parser.
Add TMDB api for people.
Add character role start/end year to IMDb api and tv character.
Fix updating characters with multiple persons, by limiting to one.
Add cache to imdb_api.py.
Add cache to tmdb_api: get_person, _search_person.
Add cache to trakt get_person, _search_person cache.
Improve main execution loop speed https://stackify.com/20-simple-python-performance-tuning-tips/ point: 12
Add network to episode for tvdb_api (from show data).
Add fallback for network/timezone for tv episode to tv show.
Add skip retrieve_exceptions for tv info sources that don't have 'scene_url'.
Change move network load before show load to make sure the tvshow obj timezone can be set (startup).
Add datetime.time to/from integer to sbdatetime (hour, minute only).
Add load all indexer mapping at once from db during startup.
Add load the failed count during startup.
Change move sanitize_filename to sg_helpers.
Change move download_file to sg_helpers.
Add list_tables, list_indexes to db.py.
Add multi db column add function.
Restore backup tables during upgrade.
Use lib.tvinfo_base import everywhere.
Add new properties to tvepisode.
Add show_updates to indexer endpoint.
Add new db schema.
Add Character and Persons tables.
Add tvmaze_api lib.
Add pytvmaze lib.
Add debug __repr__ to people/show queue.
Add crew to show tvinfo_base.
Drop backup tables for now.
Don't save switch refresh, update show queue items (since they are sub queues of switch).
Remove show from switched_shows in case it is in it when deleting the show.
Use switch queue for manual switch
Load/save updated time for person/Character.
Add show_queue table.
Add _get_item_sql, _delete_item_from_db_sql to search search_queue.
Add people_queue type.
Add people scheduler.
Add people queue.
Add tvinfo source switch queue item.
Alternate naming for person/character images.
Add load and save image/thumb urls for persons.
Add load character pics.
Add save images for characters.
Add save image urls for characters to db.
Change limit for person searches to 100 instead of 10 default.
Add person verification.
Add people_url and character_url to sources that support them.
Add save castlist changes.
Add remove old characters from castlist.
Change optimize find_show_by_id.
Change improve debug info for person, character obj.
Add db_support_upsert support flag in db.py.
Add cast list objs and load from db.
Add parse and add additional images to TVInfo.
Add optional loading of images and actors/crew.
Fix _make_timestamp in py2.
Save and load _src_update_time.
Change use update time for show updates.
Add _set_network optimization.
Add src_update_timestamp to tvshow tbl.
Add updated_timestamp to TVInfoShow.
Add _indexer_update_time TVShow obj.
Add support to search for external ids on TV info sources: [TVINFO_TVDB, TVINFO_IMDb, TVINFO_TMDB, TVINFO_TRAKT].
Change show tasks page, keep remove button for failed switches always visible.
Add use get_url for tvmaze_api interface (to support failure handling), without changing original lib.
Add missing settings in switch show.
Add new switch error: TVSWITCH_ID_CONFLICT: 'new id conflicts with existing show'.
Add messages for manual switch id.
Add connection skip handling.
Add get_url failure handling to Trakt lib.
Add real search_person to tvinfo interface.
Change move TMDB api key to tmdb_api.
Add get_url usage via tmdb_api.
Change join/split of akas/join and sql group_concat to `;;;` to prevent issues with names that may contain comma (`,`).
Add Trakt api specific failure times.
Add warning about reassigning MEMCACHE
Add calc_age to sg_helpers for person page to remove dupe code.
Add return age in ajax for persons.
Change format dates on person page to honour config/General.
Add convert_to_inch_fraction_html to sg_helpers.
Change direct assign method instead of wrapper (faster).
Change force disk_pickle_protocol=2 for py2 compatibility in tvinfo cache.
Add episode rename info during switch.
Add save deleted episodes when switching tvinfo source.
Add get_switch_changed page.
Add force=True to QueueItemRefresh during switch of tvinfo to force rewriting of metadata.
Add filter character dupes in tvdb_api only take images for unique character, role combos on tvdb.
Fix humanize lib in py27.
Add diskcache to tvinfo_base.
Add doc files for diskcache lib.
Add clean tvinfo to show_updater.
Add switch_ep_errors table to sickbeard.db
Add debug log message when extra data is fetched for a person.
Change make character loading more efficient.
Add placeholder image for characters and persons.
Change start, end year moved to new extra table to support multiple person per character.
Change replace start_year, end_year with persons_years in Character class.
Add new table character_person_years, change table structure characters.
Add check if show is found for switch pages.
Add missing scheduled to cache.db people queue table.
Change trakt show search now will ignore failure handling, to make sure it's always tried when searching for shows.
Change add/improve tvmaze id cross search.
Change improve search, if only ids are given, resulting seriesnames on source will be used as text search on following tvinfo sources.
Add new parameter: prefer_person to imagecache/character endpoint.
Add if prefer_person is set and person_id is set to valid person and the character has more then 1 person assigned the character image will not be returned, instead the actors image or the placeholder.
Add only take external ids if character is confirmed in logic.
Add match name instead of person id for checking same person in show when adding cast for sources without person id (tvdb)
Add cache tmdb genres directly in dict for performance.
4 years ago
|
|
|
def from_timestamp(ts, local_time=True, tz_aware=False, tzinfo=None):
|
|
|
|
# type: (Union[float, integer_types], bool, bool, datetime.tzinfo) -> datetime.datetime
|
|
|
|
"""
|
|
|
|
convert timestamp to datetime.datetime obj
|
|
|
|
:param ts: timestamp integer, float
|
|
|
|
:param local_time: return as local timezone (SG_TIMEZONE)
|
|
|
|
:param tz_aware: return tz aware datetime
|
Add support for multiple TV info sources.
Changelog
---------
Change improve loading speed of shows at startup.
Change improve main execution loop speed.
Add force cast update to view show page.
Add person view.
Add character view.
Add characters, person to clean-up cache (30 days).
Add reload person, character images every 7 days.
Add suppress UI notification for scheduled people updates during show updates and during switching ids.
Add resume support of switched shows after restart that switched id but not finished updating.
Add failed TV info switches to show tasks page.
Add remove item from queue and clear queue test buttons to mange/show-tasks and manage/search-tasks.
Change improve show update logic.
Add to view-show page a notification message if a show fails to switch.
Add check for existing show with new id pair before switching.
Change prioritize first episode start year over the start year set at the tv info source.
Change delete non existing episodes when switching indexer.
Change "exists in db" link on search results page to support any info source.
Add TMDB person pics as fallback.
Add use person fallback for character images.
Add logic to add start, end year in case of multiple characters per person.
Change improve speed getting list in the import view.
Add abort people cast update when show is deleted, also remove show from any queued show item or search item
Support list of names to search for in show search.
Change assist user search terms when the actual title of a show is unknown.
Add support URLs in search.
Change remove year from search term ... year is still used for relevancy order.
Add updating show.nfo when a cast changes.
Change use longest biography available for output.
Add UI requests of details for feb 28 will also return feb 29 in years without feb 29.
Add fetch extra data fallback from TMDB for persons.
technical commit messages (combined commits)
--------------------------------------------
Add tmdb get_trending, get_popular, get_top_rated, discover to tvinfoapi.
Add home/get_persons ajax endpoint, currently supports: birthday, deathday, names.
Change daily-schedule to new get_episode_time - More TODO
Change view-show to use get_episode_time.
Add get show updates list in show updater.
Add get_episode_time to network_timezones.
Add airtime for episode and show to get_episode_time.
Small ep obj load performance improvement.
Add handle special episodes and assign numbers based on airdate.
Add handle tvmaze specials without airdate.
Change during switch tv info source, specials are removed from db because of non-existing generic numbering.
Change add first/latest regular episode, use first_aired_regular_episode in all places that have airdate of first episode.
Add IMDb to person interface.
Add akas to person.
Add IMDb bio parser.
Add TMDB api for people.
Add character role start/end year to IMDb api and tv character.
Fix updating characters with multiple persons, by limiting to one.
Add cache to imdb_api.py.
Add cache to tmdb_api: get_person, _search_person.
Add cache to trakt get_person, _search_person cache.
Improve main execution loop speed https://stackify.com/20-simple-python-performance-tuning-tips/ point: 12
Add network to episode for tvdb_api (from show data).
Add fallback for network/timezone for tv episode to tv show.
Add skip retrieve_exceptions for tv info sources that don't have 'scene_url'.
Change move network load before show load to make sure the tvshow obj timezone can be set (startup).
Add datetime.time to/from integer to sbdatetime (hour, minute only).
Add load all indexer mapping at once from db during startup.
Add load the failed count during startup.
Change move sanitize_filename to sg_helpers.
Change move download_file to sg_helpers.
Add list_tables, list_indexes to db.py.
Add multi db column add function.
Restore backup tables during upgrade.
Use lib.tvinfo_base import everywhere.
Add new properties to tvepisode.
Add show_updates to indexer endpoint.
Add new db schema.
Add Character and Persons tables.
Add tvmaze_api lib.
Add pytvmaze lib.
Add debug __repr__ to people/show queue.
Add crew to show tvinfo_base.
Drop backup tables for now.
Don't save switch refresh, update show queue items (since they are sub queues of switch).
Remove show from switched_shows in case it is in it when deleting the show.
Use switch queue for manual switch
Load/save updated time for person/Character.
Add show_queue table.
Add _get_item_sql, _delete_item_from_db_sql to search search_queue.
Add people_queue type.
Add people scheduler.
Add people queue.
Add tvinfo source switch queue item.
Alternate naming for person/character images.
Add load and save image/thumb urls for persons.
Add load character pics.
Add save images for characters.
Add save image urls for characters to db.
Change limit for person searches to 100 instead of 10 default.
Add person verification.
Add people_url and character_url to sources that support them.
Add save castlist changes.
Add remove old characters from castlist.
Change optimize find_show_by_id.
Change improve debug info for person, character obj.
Add db_support_upsert support flag in db.py.
Add cast list objs and load from db.
Add parse and add additional images to TVInfo.
Add optional loading of images and actors/crew.
Fix _make_timestamp in py2.
Save and load _src_update_time.
Change use update time for show updates.
Add _set_network optimization.
Add src_update_timestamp to tvshow tbl.
Add updated_timestamp to TVInfoShow.
Add _indexer_update_time TVShow obj.
Add support to search for external ids on TV info sources: [TVINFO_TVDB, TVINFO_IMDb, TVINFO_TMDB, TVINFO_TRAKT].
Change show tasks page, keep remove button for failed switches always visible.
Add use get_url for tvmaze_api interface (to support failure handling), without changing original lib.
Add missing settings in switch show.
Add new switch error: TVSWITCH_ID_CONFLICT: 'new id conflicts with existing show'.
Add messages for manual switch id.
Add connection skip handling.
Add get_url failure handling to Trakt lib.
Add real search_person to tvinfo interface.
Change move TMDB api key to tmdb_api.
Add get_url usage via tmdb_api.
Change join/split of akas/join and sql group_concat to `;;;` to prevent issues with names that may contain comma (`,`).
Add Trakt api specific failure times.
Add warning about reassigning MEMCACHE
Add calc_age to sg_helpers for person page to remove dupe code.
Add return age in ajax for persons.
Change format dates on person page to honour config/General.
Add convert_to_inch_fraction_html to sg_helpers.
Change direct assign method instead of wrapper (faster).
Change force disk_pickle_protocol=2 for py2 compatibility in tvinfo cache.
Add episode rename info during switch.
Add save deleted episodes when switching tvinfo source.
Add get_switch_changed page.
Add force=True to QueueItemRefresh during switch of tvinfo to force rewriting of metadata.
Add filter character dupes in tvdb_api only take images for unique character, role combos on tvdb.
Fix humanize lib in py27.
Add diskcache to tvinfo_base.
Add doc files for diskcache lib.
Add clean tvinfo to show_updater.
Add switch_ep_errors table to sickbeard.db
Add debug log message when extra data is fetched for a person.
Change make character loading more efficient.
Add placeholder image for characters and persons.
Change start, end year moved to new extra table to support multiple person per character.
Change replace start_year, end_year with persons_years in Character class.
Add new table character_person_years, change table structure characters.
Add check if show is found for switch pages.
Add missing scheduled to cache.db people queue table.
Change trakt show search now will ignore failure handling, to make sure it's always tried when searching for shows.
Change add/improve tvmaze id cross search.
Change improve search, if only ids are given, resulting seriesnames on source will be used as text search on following tvinfo sources.
Add new parameter: prefer_person to imagecache/character endpoint.
Add if prefer_person is set and person_id is set to valid person and the character has more then 1 person assigned the character image will not be returned, instead the actors image or the placeholder.
Add only take external ids if character is confirmed in logic.
Add match name instead of person id for checking same person in show when adding cast for sources without person id (tvdb)
Add cache tmdb genres directly in dict for performance.
4 years ago
|
|
|
:param tzinfo: tzinfo to be used
|
|
|
|
"""
|
|
|
|
from .network_timezones import EPOCH_START, SG_TIMEZONE
|
|
|
|
result = EPOCH_START + datetime.timedelta(seconds=ts)
|
|
|
|
if local_time and SG_TIMEZONE:
|
|
|
|
result = result.astimezone(SG_TIMEZONE)
|
Add support for multiple TV info sources.
Changelog
---------
Change improve loading speed of shows at startup.
Change improve main execution loop speed.
Add force cast update to view show page.
Add person view.
Add character view.
Add characters, person to clean-up cache (30 days).
Add reload person, character images every 7 days.
Add suppress UI notification for scheduled people updates during show updates and during switching ids.
Add resume support of switched shows after restart that switched id but not finished updating.
Add failed TV info switches to show tasks page.
Add remove item from queue and clear queue test buttons to mange/show-tasks and manage/search-tasks.
Change improve show update logic.
Add to view-show page a notification message if a show fails to switch.
Add check for existing show with new id pair before switching.
Change prioritize first episode start year over the start year set at the tv info source.
Change delete non existing episodes when switching indexer.
Change "exists in db" link on search results page to support any info source.
Add TMDB person pics as fallback.
Add use person fallback for character images.
Add logic to add start, end year in case of multiple characters per person.
Change improve speed getting list in the import view.
Add abort people cast update when show is deleted, also remove show from any queued show item or search item
Support list of names to search for in show search.
Change assist user search terms when the actual title of a show is unknown.
Add support URLs in search.
Change remove year from search term ... year is still used for relevancy order.
Add updating show.nfo when a cast changes.
Change use longest biography available for output.
Add UI requests of details for feb 28 will also return feb 29 in years without feb 29.
Add fetch extra data fallback from TMDB for persons.
technical commit messages (combined commits)
--------------------------------------------
Add tmdb get_trending, get_popular, get_top_rated, discover to tvinfoapi.
Add home/get_persons ajax endpoint, currently supports: birthday, deathday, names.
Change daily-schedule to new get_episode_time - More TODO
Change view-show to use get_episode_time.
Add get show updates list in show updater.
Add get_episode_time to network_timezones.
Add airtime for episode and show to get_episode_time.
Small ep obj load performance improvement.
Add handle special episodes and assign numbers based on airdate.
Add handle tvmaze specials without airdate.
Change during switch tv info source, specials are removed from db because of non-existing generic numbering.
Change add first/latest regular episode, use first_aired_regular_episode in all places that have airdate of first episode.
Add IMDb to person interface.
Add akas to person.
Add IMDb bio parser.
Add TMDB api for people.
Add character role start/end year to IMDb api and tv character.
Fix updating characters with multiple persons, by limiting to one.
Add cache to imdb_api.py.
Add cache to tmdb_api: get_person, _search_person.
Add cache to trakt get_person, _search_person cache.
Improve main execution loop speed https://stackify.com/20-simple-python-performance-tuning-tips/ point: 12
Add network to episode for tvdb_api (from show data).
Add fallback for network/timezone for tv episode to tv show.
Add skip retrieve_exceptions for tv info sources that don't have 'scene_url'.
Change move network load before show load to make sure the tvshow obj timezone can be set (startup).
Add datetime.time to/from integer to sbdatetime (hour, minute only).
Add load all indexer mapping at once from db during startup.
Add load the failed count during startup.
Change move sanitize_filename to sg_helpers.
Change move download_file to sg_helpers.
Add list_tables, list_indexes to db.py.
Add multi db column add function.
Restore backup tables during upgrade.
Use lib.tvinfo_base import everywhere.
Add new properties to tvepisode.
Add show_updates to indexer endpoint.
Add new db schema.
Add Character and Persons tables.
Add tvmaze_api lib.
Add pytvmaze lib.
Add debug __repr__ to people/show queue.
Add crew to show tvinfo_base.
Drop backup tables for now.
Don't save switch refresh, update show queue items (since they are sub queues of switch).
Remove show from switched_shows in case it is in it when deleting the show.
Use switch queue for manual switch
Load/save updated time for person/Character.
Add show_queue table.
Add _get_item_sql, _delete_item_from_db_sql to search search_queue.
Add people_queue type.
Add people scheduler.
Add people queue.
Add tvinfo source switch queue item.
Alternate naming for person/character images.
Add load and save image/thumb urls for persons.
Add load character pics.
Add save images for characters.
Add save image urls for characters to db.
Change limit for person searches to 100 instead of 10 default.
Add person verification.
Add people_url and character_url to sources that support them.
Add save castlist changes.
Add remove old characters from castlist.
Change optimize find_show_by_id.
Change improve debug info for person, character obj.
Add db_support_upsert support flag in db.py.
Add cast list objs and load from db.
Add parse and add additional images to TVInfo.
Add optional loading of images and actors/crew.
Fix _make_timestamp in py2.
Save and load _src_update_time.
Change use update time for show updates.
Add _set_network optimization.
Add src_update_timestamp to tvshow tbl.
Add updated_timestamp to TVInfoShow.
Add _indexer_update_time TVShow obj.
Add support to search for external ids on TV info sources: [TVINFO_TVDB, TVINFO_IMDb, TVINFO_TMDB, TVINFO_TRAKT].
Change show tasks page, keep remove button for failed switches always visible.
Add use get_url for tvmaze_api interface (to support failure handling), without changing original lib.
Add missing settings in switch show.
Add new switch error: TVSWITCH_ID_CONFLICT: 'new id conflicts with existing show'.
Add messages for manual switch id.
Add connection skip handling.
Add get_url failure handling to Trakt lib.
Add real search_person to tvinfo interface.
Change move TMDB api key to tmdb_api.
Add get_url usage via tmdb_api.
Change join/split of akas/join and sql group_concat to `;;;` to prevent issues with names that may contain comma (`,`).
Add Trakt api specific failure times.
Add warning about reassigning MEMCACHE
Add calc_age to sg_helpers for person page to remove dupe code.
Add return age in ajax for persons.
Change format dates on person page to honour config/General.
Add convert_to_inch_fraction_html to sg_helpers.
Change direct assign method instead of wrapper (faster).
Change force disk_pickle_protocol=2 for py2 compatibility in tvinfo cache.
Add episode rename info during switch.
Add save deleted episodes when switching tvinfo source.
Add get_switch_changed page.
Add force=True to QueueItemRefresh during switch of tvinfo to force rewriting of metadata.
Add filter character dupes in tvdb_api only take images for unique character, role combos on tvdb.
Fix humanize lib in py27.
Add diskcache to tvinfo_base.
Add doc files for diskcache lib.
Add clean tvinfo to show_updater.
Add switch_ep_errors table to sickbeard.db
Add debug log message when extra data is fetched for a person.
Change make character loading more efficient.
Add placeholder image for characters and persons.
Change start, end year moved to new extra table to support multiple person per character.
Change replace start_year, end_year with persons_years in Character class.
Add new table character_person_years, change table structure characters.
Add check if show is found for switch pages.
Add missing scheduled to cache.db people queue table.
Change trakt show search now will ignore failure handling, to make sure it's always tried when searching for shows.
Change add/improve tvmaze id cross search.
Change improve search, if only ids are given, resulting seriesnames on source will be used as text search on following tvinfo sources.
Add new parameter: prefer_person to imagecache/character endpoint.
Add if prefer_person is set and person_id is set to valid person and the character has more then 1 person assigned the character image will not be returned, instead the actors image or the placeholder.
Add only take external ids if character is confirmed in logic.
Add match name instead of person id for checking same person in show when adding cast for sources without person id (tvdb)
Add cache tmdb genres directly in dict for performance.
4 years ago
|
|
|
if isinstance(tzinfo, datetime.tzinfo):
|
|
|
|
result = result.astimezone(tzinfo)
|
|
|
|
if not tz_aware:
|
Add support for multiple TV info sources.
Changelog
---------
Change improve loading speed of shows at startup.
Change improve main execution loop speed.
Add force cast update to view show page.
Add person view.
Add character view.
Add characters, person to clean-up cache (30 days).
Add reload person, character images every 7 days.
Add suppress UI notification for scheduled people updates during show updates and during switching ids.
Add resume support of switched shows after restart that switched id but not finished updating.
Add failed TV info switches to show tasks page.
Add remove item from queue and clear queue test buttons to mange/show-tasks and manage/search-tasks.
Change improve show update logic.
Add to view-show page a notification message if a show fails to switch.
Add check for existing show with new id pair before switching.
Change prioritize first episode start year over the start year set at the tv info source.
Change delete non existing episodes when switching indexer.
Change "exists in db" link on search results page to support any info source.
Add TMDB person pics as fallback.
Add use person fallback for character images.
Add logic to add start, end year in case of multiple characters per person.
Change improve speed getting list in the import view.
Add abort people cast update when show is deleted, also remove show from any queued show item or search item
Support list of names to search for in show search.
Change assist user search terms when the actual title of a show is unknown.
Add support URLs in search.
Change remove year from search term ... year is still used for relevancy order.
Add updating show.nfo when a cast changes.
Change use longest biography available for output.
Add UI requests of details for feb 28 will also return feb 29 in years without feb 29.
Add fetch extra data fallback from TMDB for persons.
technical commit messages (combined commits)
--------------------------------------------
Add tmdb get_trending, get_popular, get_top_rated, discover to tvinfoapi.
Add home/get_persons ajax endpoint, currently supports: birthday, deathday, names.
Change daily-schedule to new get_episode_time - More TODO
Change view-show to use get_episode_time.
Add get show updates list in show updater.
Add get_episode_time to network_timezones.
Add airtime for episode and show to get_episode_time.
Small ep obj load performance improvement.
Add handle special episodes and assign numbers based on airdate.
Add handle tvmaze specials without airdate.
Change during switch tv info source, specials are removed from db because of non-existing generic numbering.
Change add first/latest regular episode, use first_aired_regular_episode in all places that have airdate of first episode.
Add IMDb to person interface.
Add akas to person.
Add IMDb bio parser.
Add TMDB api for people.
Add character role start/end year to IMDb api and tv character.
Fix updating characters with multiple persons, by limiting to one.
Add cache to imdb_api.py.
Add cache to tmdb_api: get_person, _search_person.
Add cache to trakt get_person, _search_person cache.
Improve main execution loop speed https://stackify.com/20-simple-python-performance-tuning-tips/ point: 12
Add network to episode for tvdb_api (from show data).
Add fallback for network/timezone for tv episode to tv show.
Add skip retrieve_exceptions for tv info sources that don't have 'scene_url'.
Change move network load before show load to make sure the tvshow obj timezone can be set (startup).
Add datetime.time to/from integer to sbdatetime (hour, minute only).
Add load all indexer mapping at once from db during startup.
Add load the failed count during startup.
Change move sanitize_filename to sg_helpers.
Change move download_file to sg_helpers.
Add list_tables, list_indexes to db.py.
Add multi db column add function.
Restore backup tables during upgrade.
Use lib.tvinfo_base import everywhere.
Add new properties to tvepisode.
Add show_updates to indexer endpoint.
Add new db schema.
Add Character and Persons tables.
Add tvmaze_api lib.
Add pytvmaze lib.
Add debug __repr__ to people/show queue.
Add crew to show tvinfo_base.
Drop backup tables for now.
Don't save switch refresh, update show queue items (since they are sub queues of switch).
Remove show from switched_shows in case it is in it when deleting the show.
Use switch queue for manual switch
Load/save updated time for person/Character.
Add show_queue table.
Add _get_item_sql, _delete_item_from_db_sql to search search_queue.
Add people_queue type.
Add people scheduler.
Add people queue.
Add tvinfo source switch queue item.
Alternate naming for person/character images.
Add load and save image/thumb urls for persons.
Add load character pics.
Add save images for characters.
Add save image urls for characters to db.
Change limit for person searches to 100 instead of 10 default.
Add person verification.
Add people_url and character_url to sources that support them.
Add save castlist changes.
Add remove old characters from castlist.
Change optimize find_show_by_id.
Change improve debug info for person, character obj.
Add db_support_upsert support flag in db.py.
Add cast list objs and load from db.
Add parse and add additional images to TVInfo.
Add optional loading of images and actors/crew.
Fix _make_timestamp in py2.
Save and load _src_update_time.
Change use update time for show updates.
Add _set_network optimization.
Add src_update_timestamp to tvshow tbl.
Add updated_timestamp to TVInfoShow.
Add _indexer_update_time TVShow obj.
Add support to search for external ids on TV info sources: [TVINFO_TVDB, TVINFO_IMDb, TVINFO_TMDB, TVINFO_TRAKT].
Change show tasks page, keep remove button for failed switches always visible.
Add use get_url for tvmaze_api interface (to support failure handling), without changing original lib.
Add missing settings in switch show.
Add new switch error: TVSWITCH_ID_CONFLICT: 'new id conflicts with existing show'.
Add messages for manual switch id.
Add connection skip handling.
Add get_url failure handling to Trakt lib.
Add real search_person to tvinfo interface.
Change move TMDB api key to tmdb_api.
Add get_url usage via tmdb_api.
Change join/split of akas/join and sql group_concat to `;;;` to prevent issues with names that may contain comma (`,`).
Add Trakt api specific failure times.
Add warning about reassigning MEMCACHE
Add calc_age to sg_helpers for person page to remove dupe code.
Add return age in ajax for persons.
Change format dates on person page to honour config/General.
Add convert_to_inch_fraction_html to sg_helpers.
Change direct assign method instead of wrapper (faster).
Change force disk_pickle_protocol=2 for py2 compatibility in tvinfo cache.
Add episode rename info during switch.
Add save deleted episodes when switching tvinfo source.
Add get_switch_changed page.
Add force=True to QueueItemRefresh during switch of tvinfo to force rewriting of metadata.
Add filter character dupes in tvdb_api only take images for unique character, role combos on tvdb.
Fix humanize lib in py27.
Add diskcache to tvinfo_base.
Add doc files for diskcache lib.
Add clean tvinfo to show_updater.
Add switch_ep_errors table to sickbeard.db
Add debug log message when extra data is fetched for a person.
Change make character loading more efficient.
Add placeholder image for characters and persons.
Change start, end year moved to new extra table to support multiple person per character.
Change replace start_year, end_year with persons_years in Character class.
Add new table character_person_years, change table structure characters.
Add check if show is found for switch pages.
Add missing scheduled to cache.db people queue table.
Change trakt show search now will ignore failure handling, to make sure it's always tried when searching for shows.
Change add/improve tvmaze id cross search.
Change improve search, if only ids are given, resulting seriesnames on source will be used as text search on following tvinfo sources.
Add new parameter: prefer_person to imagecache/character endpoint.
Add if prefer_person is set and person_id is set to valid person and the character has more then 1 person assigned the character image will not be returned, instead the actors image or the placeholder.
Add only take external ids if character is confirmed in logic.
Add match name instead of person id for checking same person in show when adding cast for sources without person id (tvdb)
Add cache tmdb genres directly in dict for performance.
4 years ago
|
|
|
return result.replace(tzinfo=None)
|
|
|
|
return result
|
|
|
|
|
|
|
|
@static_or_instance
|
|
|
|
def timestamp_far(self,
|
|
|
|
dt=None, # type: Optional[SGDatetime, datetime.datetime]
|
|
|
|
default=None # type: Optional[float, integer_types]
|
|
|
|
):
|
|
|
|
# type: (...) -> Union[float, integer_types, None]
|
|
|
|
"""
|
|
|
|
Use `timestamp_far` for a timezone aware UTC timestamp in far future or far past
|
|
|
|
"""
|
|
|
|
obj = (dt, self)[self is not None] # type: datetime.datetime
|
|
|
|
if isinstance(obj, datetime.datetime) and not isinstance(getattr(obj, 'tzinfo', None), datetime.tzinfo):
|
|
|
|
from sickbeard.network_timezones import SG_TIMEZONE
|
|
|
|
obj = obj.replace(tzinfo=SG_TIMEZONE)
|
|
|
|
from .network_timezones import EPOCH_START
|
|
|
|
timestamp = default
|
|
|
|
try:
|
|
|
|
timestamp = (obj - EPOCH_START).total_seconds()
|
|
|
|
finally:
|
|
|
|
return (default, timestamp)[isinstance(timestamp, (float, integer_types))]
|
|
|
|
|
|
|
|
|
|
|
|
if PY2:
|
|
|
|
"""
|
|
|
|
Use `timestamp_near` for a timezone aware UTC timestamp in the near future or recent past.
|
|
|
|
|
|
|
|
Under py3, using the faster variable assigned cpython callable, so py2 is set up to mimick the signature types.
|
|
|
|
Note: the py3 callable is limited to datetime.datetime and does not work with datetime.date.
|
|
|
|
"""
|
|
|
|
def _py2timestamp(dt=None):
|
|
|
|
# type: (datetime.datetime) -> float
|
|
|
|
try:
|
|
|
|
import time
|
|
|
|
return int(time.mktime(dt.timetuple()))
|
|
|
|
except (BaseException, Exception):
|
|
|
|
return 0
|
|
|
|
timestamp_near = _py2timestamp # type: Callable[[datetime.datetime], float]
|
|
|
|
else:
|
|
|
|
# py3 native timestamp uses milliseconds
|
|
|
|
timestamp_near = datetime.datetime.timestamp # type: Callable[[datetime.datetime], float]
|