Skip to content

Commit

Permalink
Merge pull request #173 from zsprackett/master
Browse files Browse the repository at this point in the history
Improve search, add guide offset, expose guide format string
  • Loading branch information
Cigaras authored Feb 4, 2018
2 parents 29d5c1c + 2eebcb2 commit 58295db
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
37 changes: 33 additions & 4 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,25 @@ def ListItems(group = unicode('All'), query = '', page = 1):

# Filter
if query:
items_list = filter(lambda d: query.lower() in d['title'].lower(), items_list)
raw_items_list = items_list
ql = query.lower()
items_list = filter(lambda d: ql in d['title'].lower(), items_list)

guide = Dict['guide']
if guide:
current_datetime = Datetime.Now()
try:
guide_hours = int(Prefs['guide_hours'])
except:
guide_hours = 8
crop_time = current_datetime + Datetime.Delta(hours = guide_hours)
for key in guide.keys():
# crop anything outside of our window first to limit the second search
shows = filter(lambda d: d['start'] <= crop_time and d['stop'] > current_datetime, guide[key].values())
# now look for matches in the result set
shows = filter(lambda d: ql in d['title'].lower(), shows)
for show in shows:
items_list = items_list + filter(lambda d: show['channel_id'] == d['id'], raw_items_list)

# Sort
if Prefs['sort_lists']:
Expand Down Expand Up @@ -416,10 +434,21 @@ def GetSummary(id, name, title, default = ''):
guide_hours = 8
for item in items_list:
if item['start'] <= current_datetime + Datetime.Delta(hours = guide_hours) and item['stop'] > current_datetime:
try:
guide_offset_seconds = int(Prefs['guide_offset_seconds'])
except:
guide_offset_seconds = 0

try:
guide_format_string = Prefs['guide_format_string']
except:
guide_format_string = '%H:%M'

start = (item['start'] + Datetime.Delta(seconds = guide_offset_seconds)).strftime(guide_format_string)
if summary:
summary = summary + '\n' + item['start'].strftime('%H:%M') + ' ' + item['title']
summary = summary + '\n' + start + ' ' + item['title']
else:
summary = item['start'].strftime('%H:%M') + ' ' + item['title']
summary = start + ' ' + item['title']
if item['desc']:
summary = summary + ' - ' + item['desc']

Expand All @@ -431,4 +460,4 @@ def GetSummary(id, name, title, default = ''):
####################################################################################################
def ValidatePrefs():

pass
pass
3 changes: 2 additions & 1 deletion Contents/Code/xmltv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def LoadGuide():
'stop': stop,
'title': title,
'desc': desc,
'channel_id': channel,
'order': count
}
guide.setdefault(channel, {})[count] = item
Expand Down Expand Up @@ -144,4 +145,4 @@ def GuideReloader():
next_load_datetime = Datetime.ParseDate(str(current_datetime.date()) + ' ' + Prefs['xmltv_reload_time'] + ':00')
if current_datetime > next_load_datetime and next_load_datetime > Dict['last_guide_load_datetime']:
LoadGuide()
Thread.Sleep(10)
Thread.Sleep(10)
14 changes: 13 additions & 1 deletion Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
"type": "text",
"default": ""
},
{
"id": "guide_offset_seconds",
"label": "Number of seconds by which to offset the XMLTV guide start time",
"type": "text",
"default": "0"
},
{
"id": "guide_format_string",
"label": "Format string to use for displaying times",
"type": "text",
"default": "%H:%M"
},
{
"id": "images_path",
"label": "Local path (experimental) or URL where images are located, if left empty images will be loaded from Resources folder",
Expand Down Expand Up @@ -129,4 +141,4 @@
"type": "bool",
"default": "true"
}
]
]

0 comments on commit 58295db

Please sign in to comment.