diff options
author | skipmodea1 <skipmodea1@outlook.com> | 2018-01-27 05:02:26 +0100 |
---|---|---|
committer | Martijn Kaijser <martijn@xbmc.org> | 2018-01-27 07:02:45 +0100 |
commit | 3467ee3e394f21e32d89ad06a5689772914d2412 (patch) | |
tree | 3ede4ce094b02f83dab153ade1660e4d0b2d321d /plugin.video.hak5/resources/lib/hak5_const.py | |
parent | 17a5d64cdca39bef090ba77c2a46b24e819179db (diff) |
[plugin.video.hak5] 1.0.3
Diffstat (limited to 'plugin.video.hak5/resources/lib/hak5_const.py')
-rw-r--r-- | plugin.video.hak5/resources/lib/hak5_const.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/plugin.video.hak5/resources/lib/hak5_const.py b/plugin.video.hak5/resources/lib/hak5_const.py index 0334942..16361e0 100644 --- a/plugin.video.hak5/resources/lib/hak5_const.py +++ b/plugin.video.hak5/resources/lib/hak5_const.py @@ -1,12 +1,15 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- +import sys import os +import xbmc import xbmcaddon +from bs4 import BeautifulSoup # # Constants -# +# ADDON = "plugin.video.hak5" SETTINGS = xbmcaddon.Addon() LANGUAGE = SETTINGS.getLocalizedString @@ -19,5 +22,37 @@ TEKTHINGRECENTLYADDEDURL = 'http://www.hak5.org/category/episodes/tekthing/page/ PINEAPPLEUNIVERSITYRECENTLYADDEDURL = 'http://www.hak5.org/category/episodes/pineapple-university' METASPLOITRECENTLYADDEDURL = 'http://www.hak5.org/category/episodes/metasploit-minute/page/001' HEADERS = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'} -DATE = "2017-11-12" -VERSION = "1.0.2"
\ No newline at end of file +DATE = "2018-01-20" +VERSION = "1.0.3" + +if sys.version_info[0] > 2: + unicode = str + + +def convertToUnicodeString(s, encoding='utf-8'): + """Safe decode byte strings to Unicode""" + if isinstance(s, bytes): # This works in Python 2.7 and 3+ + s = s.decode(encoding) + return s + + +def convertToByteString(s, encoding='utf-8'): + """Safe encode Unicode strings to bytes""" + if isinstance(s, unicode): + s = s.encode(encoding) + return s + + +def log(name_object, object): + try: + xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( + ADDON, VERSION, DATE, name_object, convertToUnicodeString(object)), xbmc.LOGDEBUG) + except: + xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( + ADDON, VERSION, DATE, name_object, + "Unable to log the object due to an error while converting it to an unicode string"), xbmc.LOGDEBUG) + + +def getSoup(html, default_parser="html5lib"): + soup = BeautifulSoup(html, default_parser) + return soup
\ No newline at end of file |