Fix browsing the Live TV programs menu (#145)
* Convert server times to local timezone * Fix naming format of programs * Simplify string formatting * Remove unneeded space
This commit is contained in:
@@ -404,7 +404,7 @@ def add_gui_item(url, item_details, display_options, folder=True, default_sort=F
|
||||
end_time = datetime_from_string(item_details.program_end_date)
|
||||
|
||||
duration = (end_time - start_time).total_seconds()
|
||||
time_done = (datetime.now() - start_time).total_seconds()
|
||||
time_done = (datetime.now().astimezone() - start_time).total_seconds()
|
||||
percentage_done = (float(time_done) / float(duration)) * 100.0
|
||||
capped_percentage = int(percentage_done)
|
||||
|
||||
@@ -414,10 +414,14 @@ def add_gui_item(url, item_details, display_options, folder=True, default_sort=F
|
||||
item_details.duration = int(duration)
|
||||
item_details.resume_time = int(time_done)
|
||||
|
||||
list_item_name = (item_details.program_channel_name +
|
||||
" - " + list_item_name +
|
||||
" - " + start_time_string + " to " + end_time_string +
|
||||
" (" + str(int(percentage_done)) + "%)")
|
||||
if item_details.program_channel_name:
|
||||
list_item_name = '{} - {} - {} to {} ({}%)'.format(
|
||||
item_details.program_channel_name, list_item_name,
|
||||
start_time_string, end_time_string, capped_percentage)
|
||||
else:
|
||||
list_item_name = '{} - {} to {} ({}%)'.format(
|
||||
list_item_name, start_time_string, end_time_string,
|
||||
capped_percentage)
|
||||
|
||||
time_info = "Start : " + start_time_string + "\n"
|
||||
time_info += "End : " + end_time_string + "\n"
|
||||
|
||||
@@ -16,6 +16,8 @@ import math
|
||||
import os
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
from dateutil import tz
|
||||
import time
|
||||
import re
|
||||
from uuid import uuid4
|
||||
from six import ensure_text, ensure_binary, text_type
|
||||
@@ -97,9 +99,20 @@ def datetime_from_string(time_string):
|
||||
elif time_string[-6:] == "+00:00":
|
||||
time_string = re.sub("[0-9]{1}\+00:00", " UTC", time_string)
|
||||
|
||||
dt = datetime.strptime(time_string, "%Y-%m-%dT%H:%M:%S.%f %Z")
|
||||
try:
|
||||
dt = datetime.strptime(time_string, "%Y-%m-%dT%H:%M:%S.%f %Z")
|
||||
except TypeError:
|
||||
# https://bugs.python.org/issue27400
|
||||
dt = datetime(*(time.strptime(time_string, "%Y-%m-%dT%H:%M:%S.%f %Z")[0:6]))
|
||||
|
||||
return dt
|
||||
# Convert server dates from UTC to local time
|
||||
utc = tz.tzutc()
|
||||
local = tz.tzlocal()
|
||||
|
||||
utc_dt = dt.replace(tzinfo=utc)
|
||||
local_dt = utc_dt.astimezone(local)
|
||||
|
||||
return local_dt
|
||||
|
||||
|
||||
def convert_size(size_bytes):
|
||||
|
||||
Reference in New Issue
Block a user