Skip to content

Commit

Permalink
Revert^3 "[Autotimer] removed encoding stuff...."""
Browse files Browse the repository at this point in the history
While I don't see the problem, for the sake of happiness ...
  • Loading branch information
Schimmelreiter committed Sep 17, 2015
1 parent b029f8a commit a4b41fb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
8 changes: 8 additions & 0 deletions autotimer/src/AutoTimer.py 100644 → 100755
Expand Up @@ -253,6 +253,14 @@ def parseTimer(self, timer, epgcache, serviceHandler, recordHandler, checkEvtLim
# Precompute timer destination dir
dest = timer.destination or config.usage.default_path.value

# Workaround to allow search for umlauts if we know the encoding
match = timer.match.replace('\xc2\x86', '').replace('\xc2\x87', '')
if timer.encoding != 'UTF-8':
try:
match = match.decode('UTF-8').encode(timer.encoding)
except UnicodeDecodeError:
pass

if timer.searchType == "description":
epgmatches = []
mask = (eServiceReference.isMarker | eServiceReference.isDirectory)
Expand Down
24 changes: 23 additions & 1 deletion autotimer/src/AutoTimerComponent.py
Expand Up @@ -10,6 +10,9 @@
# To get preferred component
from Components.config import config

# Default encoding
from Components.Language import language

class AutoTimerComponent(object):
"""AutoTimer Component which also handles validity checks"""

Expand Down Expand Up @@ -48,7 +51,7 @@ def setValues(self, name, match, enabled, timespan=None, services=None, \
destination=None, include=None, matchCount=0, matchLeft=0, \
matchLimit='', matchFormatString='', lastBegin=0, justplay=False, \
avoidDuplicateDescription=0, searchForDuplicateDescription=2, bouquets=None, \
tags=None, searchType="partial", searchCase="insensitive", \
tags=None, encoding=None, searchType="partial", searchCase="insensitive", \
overrideAlternatives=True, timeframe=None, vps_enabled=False, \
vps_overwrite=False, setEndtime=False, series_labeling=False):
self.name = name
Expand All @@ -72,6 +75,7 @@ def setValues(self, name, match, enabled, timespan=None, services=None, \
self.searchForDuplicateDescription = searchForDuplicateDescription
self.bouquets = bouquets
self.tags = tags or []
self.encoding = encoding or getDefaultEncoding()
self.searchType = searchType
self.searchCase = searchCase
self.overrideAlternatives = overrideAlternatives
Expand Down Expand Up @@ -105,6 +109,16 @@ def setBouquets(self, bouquets):

bouquets = property(lambda self: self._bouquets , setBouquets)

def setEncoding(self, encoding):
if encoding == '(null)':
self._encoding = getDefaultEncoding()
elif encoding:
self._encoding = encoding
elif not self._encoding:
self._encoding = getDefaultEncoding()

encoding = property(lambda self: self._encoding, setEncoding)

def setExclude(self, exclude):
if exclude:
self._exclude = (
Expand Down Expand Up @@ -508,6 +522,7 @@ def __copy__(self):
searchForDuplicateDescription = self.searchForDuplicateDescription,
bouquets = self.bouquets,
tags = self.tags,
encoding = self.encoding,
searchType = self.searchType,
searchCase = self.searchCase,
overrideAlternatives = self.overrideAlternatives,
Expand Down Expand Up @@ -541,6 +556,7 @@ def __deepcopy__(self, memo):
searchForDuplicateDescription = self.searchForDuplicateDescription,
bouquets = self.bouquets[:],
tags = self.tags[:],
encoding = self.encoding,
searchType = self.searchType,
searchCase = self.searchCase,
overrideAlternatives = self.overrideAlternatives,
Expand Down Expand Up @@ -570,6 +586,7 @@ def __repr__(self):
' (',
', '.join((
str(self.match),
str(self.encoding),
str(self.searchCase),
str(self.searchType),
str(self.timespan),
Expand Down Expand Up @@ -697,5 +714,10 @@ def getAlternative(self, override_service):
break
return override_service

def getDefaultEncoding():
#if 'de' in language.getLanguage():
# return 'ISO8859-15'
return 'UTF-8'

# very basic factory ;-)
preferredAutoTimerComponent = lambda *args, **kwargs: AutoTimerFastscanComponent(*args, **kwargs) if config.plugins.autotimer.fastscan.value else AutoTimerComponent(*args, **kwargs)
14 changes: 13 additions & 1 deletion autotimer/src/AutoTimerConfiguration.py
Expand Up @@ -4,7 +4,7 @@
# for localized messages
from . import _

from AutoTimerComponent import preferredAutoTimerComponent
from AutoTimerComponent import preferredAutoTimerComponent, getDefaultEncoding
from RecordTimer import AFTEREVENT
from Tools.XMLTools import stringToXML
from ServiceReference import ServiceReference
Expand Down Expand Up @@ -111,6 +111,9 @@ def parseEntry(element, baseTimer, defaults = False):
baseTimer.series_labeling = True if series_labeling == "yes" else False
del series_labeling

# Read out encoding (won't change if no value is set)
baseTimer.encoding = element.get("encoding")

# Read out search type/case
baseTimer.searchType = element.get("searchType", baseTimer.searchType)
baseTimer.searchCase = element.get("searchCase", baseTimer.searchCase)
Expand Down Expand Up @@ -523,6 +526,7 @@ def buildConfig(defaultTimer, timers, webif = False):
list = ['<?xml version="1.0" ?>\n<autotimer version="', CURRENT_CONFIG_VERSION, '">\n\n']
append = list.append
extend = list.extend
defaultEncoding = getDefaultEncoding()

# This gets deleted afterwards if we do not have set any defaults
append(' <defaults')
Expand Down Expand Up @@ -568,6 +572,10 @@ def buildConfig(defaultTimer, timers, webif = False):
if not defaultTimer.setEndtime:
append(' setEndtime="0"')

# Only display encoding if != utf-8
if defaultTimer.encoding != defaultEncoding or webif:
extend((' encoding="', str(defaultTimer.encoding), '"'))

# SearchType
if defaultTimer.searchType != "partial":
extend((' searchType="', str(defaultTimer.searchType), '"'))
Expand Down Expand Up @@ -712,6 +720,10 @@ def buildConfig(defaultTimer, timers, webif = False):
if not timer.setEndtime:
append(' setEndtime="0"')

# Only display encoding if != utf-8
if timer.encoding != defaultEncoding or webif:
extend((' encoding="', str(timer.encoding), '"'))

# SearchType
if timer.searchType != "partial":
extend((' searchType="', str(timer.searchType), '"'))
Expand Down
12 changes: 12 additions & 0 deletions autotimer/src/AutoTimerEditor.py 100644 → 100755
Expand Up @@ -172,6 +172,13 @@ def createSetup(self, timer):
# Match
self.match = NoSave(ConfigText(default = timer.match, fixed_size = False))

# Encoding
default = timer.encoding
selection = ['UTF-8', 'ISO8859-15']
if default not in selection:
selection.append(default)
self.encoding = NoSave(ConfigSelection(choices = selection, default = default))

# ...
self.searchType = NoSave(ConfigSelection(choices = [("partial", _("partial match")), ("exact", _("exact match")), ("start", _("title starts with")), ("description", _("description match"))], default = timer.searchType))
self.searchCase = NoSave(ConfigSelection(choices = [("sensitive", _("case-sensitive search")), ("insensitive", _("case-insensitive search"))], default = timer.searchCase))
Expand Down Expand Up @@ -516,6 +523,7 @@ def initHelpTexts(self):
self.enabled: _("Set this NO to disable this AutoTimer."),
self.name: _("This is a name you can give the AutoTimer. It will be shown in the Overview and the Preview."),
self.match: _("This is what will be looked for in event titles. Note that looking for e.g. german umlauts can be tricky as you have to know the encoding the channel uses."),
self.encoding: _("Encoding the channel uses for it's EPG data. You only need to change this if you're searching for special characters like the german umlauts."),
self.searchType: _("Select \"exact match\" to enforce \"Match title\" to match exactly, \"partial match\" if you only want to search for a part of the event title or \"description match\" if you only want to search for a part of the event description"),
self.searchCase: _("Select whether or not you want to enforce case correctness."),
self.justplay: _("Add zap timer instead of record timer?"),
Expand Down Expand Up @@ -562,6 +570,7 @@ def refresh(self):
))

list.extend((
getConfigListEntry(_("EPG encoding"), self.encoding),
getConfigListEntry(_("Search type"), self.searchType),
getConfigListEntry(_("Search strictness"), self.searchCase),
getConfigListEntry(_("Timer type"), self.justplay),
Expand Down Expand Up @@ -771,6 +780,9 @@ def save(self):
# Name
self.timer.name = self.name.value.strip() or self.timer.match

# Encoding
self.timer.encoding = self.encoding.value

# ...
self.timer.searchType = self.searchType.value
self.timer.searchCase = self.searchCase.value
Expand Down
3 changes: 3 additions & 0 deletions autotimer/src/AutoTimerResource.py
Expand Up @@ -150,6 +150,9 @@ def get(name, default=None):
elif before == '' or after == '':
timer.timeframe = None

# Encoding
timer.encoding = get("encoding", timer.encoding)

# ...
timer.searchType = get("searchType", timer.searchType)
timer.searchCase = get("searchCase", timer.searchCase)
Expand Down

0 comments on commit a4b41fb

Please sign in to comment.