From 3467ee3e394f21e32d89ad06a5689772914d2412 Mon Sep 17 00:00:00 2001 From: skipmodea1 Date: Sat, 27 Jan 2018 05:02:26 +0100 Subject: [plugin.video.hak5] 1.0.3 --- plugin.video.hak5/addon.py | 14 ++-- plugin.video.hak5/addon.xml | 12 +-- plugin.video.hak5/changelog.txt | 13 ++- plugin.video.hak5/resources/lib/hak5_const.py | 41 ++++++++- .../resources/lib/hak5_list_episodes.py | 98 ++++++++-------------- .../resources/lib/hak5_list_seasons.py | 62 +++++++------- plugin.video.hak5/resources/lib/hak5_main.py | 25 +++--- plugin.video.hak5/resources/lib/hak5_play.py | 51 ++++++----- plugin.video.hak5/resources/settings.xml | 3 + 9 files changed, 172 insertions(+), 147 deletions(-) diff --git a/plugin.video.hak5/addon.py b/plugin.video.hak5/addon.py index 3a82ed6..3089509 100644 --- a/plugin.video.hak5/addon.py +++ b/plugin.video.hak5/addon.py @@ -4,14 +4,12 @@ # # Imports # -import os +from future import standard_library +standard_library.install_aliases() +from builtins import str import sys -import urlparse +import urllib.parse import xbmc -import xbmcaddon - -reload(sys) -sys.setdefaultencoding('utf8') from resources.lib.hak5_const import ADDON, DATE, VERSION @@ -25,7 +23,7 @@ if len(sys.argv[2]) == 0: xbmc.LOGDEBUG) from resources.lib import hak5_main as plugin else: - action = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['action'][0] + action = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['action'][0] # # List Episodes # @@ -42,4 +40,4 @@ else: elif action == 'play': from resources.lib import hak5_play as plugin -plugin.Main() +plugin.Main() \ No newline at end of file diff --git a/plugin.video.hak5/addon.xml b/plugin.video.hak5/addon.xml index efafba7..8871285 100644 --- a/plugin.video.hak5/addon.xml +++ b/plugin.video.hak5/addon.xml @@ -1,13 +1,15 @@  - - - - + + + + + + video diff --git a/plugin.video.hak5/changelog.txt b/plugin.video.hak5/changelog.txt index 213d41d..7a0005c 100644 --- a/plugin.video.hak5/changelog.txt +++ b/plugin.video.hak5/changelog.txt @@ -1,9 +1,14 @@ +v1.0.3 (2018-01-20) +- Fixed settings.xml +- addon now works in kode python 2 and should also work in python 3 (!!) once all dependencies work in python 3. +Kudo's to the python future package for making this possible. Kudo's to RomanVM for the help. + v1.0.2 (2017-11-12) -Fixes due to website changes +- Fixes due to website changes v1.0.1 (2017-10-11) -Fixes due to website changes -Removed Pinapple University videos +- Fixes due to website changes +- Removed Pinapple University videos v1.0.0 (2017-07-09) -initial version \ No newline at end of file +- initial version \ No newline at end of file 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 diff --git a/plugin.video.hak5/resources/lib/hak5_list_episodes.py b/plugin.video.hak5/resources/lib/hak5_list_episodes.py index fe8192f..b7d2860 100644 --- a/plugin.video.hak5/resources/lib/hak5_list_episodes.py +++ b/plugin.video.hak5/resources/lib/hak5_list_episodes.py @@ -4,24 +4,26 @@ # # Imports # +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import object import os import requests import sys -import urllib -import urlparse +import urllib.request, urllib.parse, urllib.error import re -import HTMLParser -import xbmc +import html.parser import xbmcgui import xbmcplugin -from BeautifulSoup import BeautifulSoup -from hak5_const import ADDON, LANGUAGE, IMAGES_PATH, HEADERS, DATE, VERSION +from .hak5_const import ADDON, LANGUAGE, IMAGES_PATH, HEADERS, convertToUnicodeString, log, getSoup # # Main class # -class Main: +class Main(object): # # Init # @@ -32,18 +34,15 @@ class Main: # Get the plugin handle as an integer number self.plugin_handle = int(sys.argv[1]) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % ( - ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGDEBUG) + log("ARGV", repr(sys.argv)) # Parse parameters - self.video_list_page_url = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['url'][0] - self.next_page_possible = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['next_page_possible'][0] + self.video_list_page_url = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['url'][0] + self.next_page_possible = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['next_page_possible'][0] self.video_list_page_url = str(self.video_list_page_url).replace('https', 'http') - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "self.video_list_page_url", str(self.video_list_page_url)), - xbmc.LOGDEBUG) + log("self.video_list_page_url", self.video_list_page_url) if self.next_page_possible == 'True': # Determine current item number, next item number, next_url @@ -61,9 +60,7 @@ class Main: page_number_next_str = '00' + str(page_number_next) self.next_url = str(self.video_list_page_url).replace(page_number_str, page_number_next_str) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "self.next_url", str(urllib.unquote_plus(self.next_url))), - xbmc.LOGDEBUG) + log("self.next_url", self.next_url) # # Get the videos... @@ -86,14 +83,14 @@ class Main: # Get HTML page # response = requests.get(self.video_list_page_url, headers=HEADERS) + html_source = response.text - html_source = html_source.encode('utf-8', 'ignore') + html_source = convertToUnicodeString(html_source) # Parse response - soup = BeautifulSoup(html_source) + soup = getSoup(html_source) - # xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - # ADDON, VERSION, DATE, "html_source", str(html_source)), xbmc.LOGDEBUG) + # log("html_source", html_source) #
#
@@ -120,37 +117,27 @@ class Main: episodes = soup.findAll('div', attrs={'id': re.compile("^" + 'post')}) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "len(episodes)", str(len(episodes))), xbmc.LOGDEBUG) + log("len(episodes", len(episodes)) for episode in episodes: - # xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - # ADDON, VERSION, DATE, "episode", str(episode)), xbmc.LOGDEBUG) + # log("episode", episode) video_page_url = episode.a['href'] - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "video_page_url", str(video_page_url)), xbmc.LOGDEBUG) + log("video_page_url", video_page_url) try: thumbnail_url = episode.img['src'] except: thumbnail_url = '' - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "thumbnail_url", str(thumbnail_url)), xbmc.LOGDEBUG) + log("thumbnail_url", thumbnail_url) pos_of_title_start = str(episode).find('title="') + len('title="') pos_of_title_end = str(episode).find('"', pos_of_title_start) title = str(episode)[pos_of_title_start:pos_of_title_end] - # Clean up title - try: - title = title.encode('utf-8') - except: - pass - title = title.replace('-', ' ') title = title.replace('/', ' ') title = title.replace(' i ', ' I ') @@ -184,21 +171,8 @@ class Main: title = title.replace(' xxix ', ' XXIX ') title = title.replace(' xxx ', ' XXX ') title = title.replace(' ', ' ') - # welcome to unescaping-hell - title = title.replace(''', "'") - title = title.replace(''', "'") - title = title.replace('"', '"') - title = title.replace("'", "'") - title = title.replace("'", "'") - title = title.replace('&', '&') - title = title.replace('&', '&') - title = title.replace('"', '"') - title = title.replace('“', '"') - title = title.replace('”', '"') - title = title.replace('’', "'") - - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "title", str(title)), xbmc.LOGDEBUG) + + log("title", title) # lets find the blog date month and year search_for_string = 'https://www.hak5.org/wp-content/uploads/' @@ -208,15 +182,13 @@ class Main: blog_date_year_end_pos = blog_date.find('/', blog_date_year_start_pos) blog_date_year = blog_date[blog_date_year_start_pos: blog_date_year_end_pos] - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "blog_date_year", str(blog_date_year)), xbmc.LOGDEBUG) + log("blog_data_year", blog_date_year) blog_date_month_start_pos = blog_date_year_end_pos + 1 blog_date_month_end_pos = blog_date_month_start_pos + 2 blog_date_month = blog_date[blog_date_month_start_pos:blog_date_month_end_pos] - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "blog_date_month", str(blog_date_month)), xbmc.LOGDEBUG) + log("blog_date_month", blog_date_month) # lets find the blog date day blog_date = episode.findAll('span', attrs={'class': re.compile("^" + 'item-date')}) @@ -229,21 +201,20 @@ class Main: blog_date_day_end_pos = blog_date_day_start_pos + 2 blog_date_day = blog_date[blog_date_day_start_pos:blog_date_day_end_pos] - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "blog_date_day", str(blog_date_day)), xbmc.LOGDEBUG) + log("blog_date_day", blog_date_day) video_date = blog_date_year + '-' + blog_date_month + '-' + blog_date_day + ' 00:00:01' - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "video_date", str(video_date)), xbmc.LOGDEBUG) + log("video_date", video_date) # Unescaping the plot try: - plot = HTMLParser.HTMLParser().unescape(episode.p.text) + plot = html.parser.HTMLParser().unescape(episode.p.text) except: plot = title - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "plot", str(plot)), xbmc.LOGDEBUG) + + log("plot", plot) add_sort_methods() @@ -261,8 +232,8 @@ class Main: list_item.setArt({'thumb': thumbnail_url, 'icon': thumbnail_url, 'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) list_item.setProperty('IsPlayable', 'true') - parameters = {"action": "play", "video_page_url": video_page_url, "title": title} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + parameters = {"action": "play", "video_page_url": video_page_url} + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) is_folder = False # Adding context menu items to context menu list_item.addContextMenuItems(context_menu_items, replaceItems=False) @@ -276,7 +247,7 @@ class Main: list_item.setProperty('IsPlayable', 'false') parameters = {"action": "list-episodes", "url": str(self.next_url), "next_page_possible": self.next_page_possible} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) is_folder = True # Adding context menu items to context menu list_item.addContextMenuItems(context_menu_items, replaceItems=False) @@ -292,6 +263,7 @@ class Main: # Finish creating a virtual folder. xbmcplugin.endOfDirectory(self.plugin_handle) + def add_sort_methods(): sort_methods = [xbmcplugin.SORT_METHOD_UNSORTED,xbmcplugin.SORT_METHOD_LABEL,xbmcplugin.SORT_METHOD_DATE,xbmcplugin.SORT_METHOD_DURATION,xbmcplugin.SORT_METHOD_EPISODE] for method in sort_methods: diff --git a/plugin.video.hak5/resources/lib/hak5_list_seasons.py b/plugin.video.hak5/resources/lib/hak5_list_seasons.py index f2d37dc..0edabb6 100644 --- a/plugin.video.hak5/resources/lib/hak5_list_seasons.py +++ b/plugin.video.hak5/resources/lib/hak5_list_seasons.py @@ -4,23 +4,25 @@ # # Imports # +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import object import os import requests import sys -import urllib -import urlparse +import urllib.request, urllib.parse, urllib.error import re -import xbmc import xbmcgui import xbmcplugin -from BeautifulSoup import BeautifulSoup -from hak5_const import ADDON, DATE, VERSION, IMAGES_PATH, HEADERS, HAK5SEASONSURLHTTPS, LANGUAGE +from .hak5_const import IMAGES_PATH, HEADERS, LANGUAGE, convertToUnicodeString, log, getSoup # # Main class # -class Main: +class Main(object): def __init__(self): # Get the command line arguments # Get the plugin url in plugin:// notation @@ -28,19 +30,16 @@ class Main: # Get the plugin handle as an integer number self.plugin_handle = int(sys.argv[1]) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % ( - ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGDEBUG) + log("ARGV", repr(sys.argv)) # Parse parameters... - self.plugin_category = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['plugin_category'][0] - self.video_list_page_url = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['url'][0] - self.next_page_possible = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['next_page_possible'][0] + self.plugin_category = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['plugin_category'][0] + self.video_list_page_url = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['url'][0] + self.next_page_possible = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['next_page_possible'][0] self.video_list_page_url = str(self.video_list_page_url).replace('https', 'http') - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "self.video_list_page_url", str(self.video_list_page_url)), - xbmc.LOGDEBUG) + log("self.video_list_page_url", self.video_list_page_url) # # Get the videos... @@ -58,41 +57,43 @@ class Main: listing = [] # - # Get HTML page... + # Get HTML page # response = requests.get(self.video_list_page_url, headers=HEADERS) + html_source = response.text - html_source = html_source.encode('utf-8', 'ignore') + html_source = convertToUnicodeString(html_source) - # Season 22 + # Parse response + soup = getSoup(html_source) - # Parse response... - soup = BeautifulSoup(html_source) + # Season 22 - # xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - # ADDON, VERSION, DATE, "html_source", str(html_source)), xbmc.LOGDEBUG) + # log("html_source", html_source) #Season 1 seasons = soup.findAll('a', attrs={'href': re.compile("^" + "https://www.hak5.org/category/episodes/season")}) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "len(seasons)", str(len(seasons))), xbmc.LOGDEBUG) + log("len(seasons", len(seasons)) for season in seasons: - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "season", str(season)), xbmc.LOGDEBUG) + # log("season", season) # let's skip these links # Season 22 if str(season).find("class=") > 0: - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "skipped season that contains class=", str(season)), xbmc.LOGDEBUG) + + log("skipped season that contains class=", season) + continue # let's skip these links # Season 22 if str(season).find("rel=") > 0: - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % (ADDON, VERSION, DATE, "skipped season that contains rel=", str(season)), xbmc.LOGDEBUG) + + log("skipped season that contains rel=", season) + continue # let's skip links that don't contain the word season @@ -100,8 +101,9 @@ class Main: if str(season).find("season") > 0: pass else: - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "skipped season that does not contain the word season", str(season)), xbmc.LOGDEBUG) + + log("skipped season that does not contain the word season", season) + continue url = season['href'] @@ -121,7 +123,7 @@ class Main: list_item.setProperty('IsPlayable', 'false') parameters = {"action": "list-episodes", "season_name": title, "url": url, "next_page_possible": "False", "title": title} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) is_folder = True # Adding context menu items to context menu list_item.addContextMenuItems(context_menu_items, replaceItems=False) diff --git a/plugin.video.hak5/resources/lib/hak5_main.py b/plugin.video.hak5/resources/lib/hak5_main.py index f1c2105..510c3d4 100644 --- a/plugin.video.hak5/resources/lib/hak5_main.py +++ b/plugin.video.hak5/resources/lib/hak5_main.py @@ -4,19 +4,22 @@ # # Imports # +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() +from builtins import object import sys -import urllib +import urllib.request, urllib.parse, urllib.error import xbmcgui import xbmcplugin import os -from hak5_const import LANGUAGE, IMAGES_PATH, HAK5RECENTLYADDEDURL, HAK5SEASONSURLHTTPS, \ - HAKTIKRECENTLYADDEDURL, THREATWIRERECENTLYADDEDURL, TEKTHINGRECENTLYADDEDURL, PINEAPPLEUNIVERSITYRECENTLYADDEDURL, \ - METASPLOITRECENTLYADDEDURL +from .hak5_const import LANGUAGE, IMAGES_PATH, HAK5RECENTLYADDEDURL, HAK5SEASONSURLHTTPS, \ + HAKTIKRECENTLYADDEDURL, THREATWIRERECENTLYADDEDURL, TEKTHINGRECENTLYADDEDURL, METASPLOITRECENTLYADDEDURL # # Main class # -class Main: +class Main(object): def __init__(self): # Get the command line arguments # Get the plugin url in plugin:// notation @@ -29,7 +32,7 @@ class Main: # parameters = {"action": "list-episodes", "plugin_category": LANGUAGE(30301), "url": HAK5RECENTLYADDEDURL, "next_page_possible": "False"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30301)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) @@ -41,7 +44,7 @@ class Main: # parameters = {"action": "list-seasons", "plugin_category": LANGUAGE(30302), "url": HAK5SEASONSURLHTTPS, "next_page_possible": "False"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30302)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) @@ -54,7 +57,7 @@ class Main: parameters = {"action": "list-episodes", "plugin_category": LANGUAGE(30303), "url": HAKTIKRECENTLYADDEDURL, "next_page_possible": "True"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30303)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) @@ -66,7 +69,7 @@ class Main: # parameters = {"action": "list-episodes", "plugin_category": LANGUAGE(30304), "url": THREATWIRERECENTLYADDEDURL, "next_page_possible": "True"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30304)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) @@ -78,7 +81,7 @@ class Main: # parameters = {"action": "list-episodes", "plugin_category": LANGUAGE(30305), "url": TEKTHINGRECENTLYADDEDURL, "next_page_possible": "True"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30305)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) @@ -90,7 +93,7 @@ class Main: # parameters = {"action": "list-episodes", "plugin_category": LANGUAGE(30307), "url": METASPLOITRECENTLYADDEDURL, "next_page_possible": "False"} - url = self.plugin_url + '?' + urllib.urlencode(parameters) + url = self.plugin_url + '?' + urllib.parse.urlencode(parameters) list_item = xbmcgui.ListItem(LANGUAGE(30307)) is_folder = True list_item.setArt({'fanart': os.path.join(IMAGES_PATH, 'fanart-blur.jpg')}) diff --git a/plugin.video.hak5/resources/lib/hak5_play.py b/plugin.video.hak5/resources/lib/hak5_play.py index 7e0f93d..6798c11 100644 --- a/plugin.video.hak5/resources/lib/hak5_play.py +++ b/plugin.video.hak5/resources/lib/hak5_play.py @@ -4,19 +4,24 @@ # # Imports # +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import object import requests import sys -import urlparse +import urllib.parse import xbmc import xbmcgui import xbmcplugin -from hak5_const import ADDON, LANGUAGE, HEADERS, DATE, VERSION +from .hak5_const import LANGUAGE, HEADERS, convertToUnicodeString, log, getSoup # # Main class # -class Main: +class Main(object): # # Init # @@ -27,18 +32,12 @@ class Main: # Get the plugin handle as an integer number self.plugin_handle = int(sys.argv[1]) - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s, %s = %s" % ( - ADDON, VERSION, DATE, "ARGV", repr(sys.argv), "File", str(__file__)), xbmc.LOGDEBUG) + log("ARGV", repr(sys.argv)) # Parse parameters... - self.video_page_url = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['video_page_url'][0] - # Get the title. - self.title = urlparse.parse_qs(urlparse.urlparse(sys.argv[2]).query)['title'][0] - self.title = str(self.title) - - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "self.video_page_url", str(self.video_page_url)), xbmc.LOGDEBUG) + self.video_page_url = urllib.parse.parse_qs(urllib.parse.urlparse(sys.argv[2]).query)['video_page_url'][0] + log("self.video_page_url", self.video_page_url) # # Play video... # @@ -59,8 +58,8 @@ class Main: # title = unicode(xbmc.getInfoLabel("listitem.Title"), "utf-8") thumbnail_url = xbmc.getInfoImage("list_item.Thumb") # studio = unicode(xbmc.getInfoLabel("list_item.Studio"), "utf-8") - plot = unicode(xbmc.getInfoLabel("list_item.Plot"), "utf-8") - genre = unicode(xbmc.getInfoLabel("list_item.Genre"), "utf-8") + plot = xbmc.getInfoLabel("list_item.Plot") + genre = xbmc.getInfoLabel("list_item.Genre") reply = '' session = '' @@ -70,13 +69,19 @@ class Main: # get the page that contains the video self.video_page_url = str(self.video_page_url).replace('https','http') - reply = requests.get(self.video_page_url, headers=HEADERS) - html_source = reply.text - html_source = html_source.encode('utf-8', 'ignore') + # + # Get HTML page + # + response = requests.get(self.video_page_url, headers=HEADERS) + + html_source = response.text + html_source = convertToUnicodeString(html_source) - # xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - # ADDON, VERSION, DATE, "html_source", str(html_source)), xbmc.LOGDEBUG) + # Parse response + soup = getSoup(html_source) + + # log("html_source", html_source) video_url = '' no_url_found = True @@ -94,15 +99,14 @@ class Main: end_pos_youtube_id = html_source.find(search_for_string, start_pos_youtube_id) if end_pos_youtube_id > 0: youtube_id = html_source[start_pos_youtube_id:end_pos_youtube_id] - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "youtube_id", str(youtube_id)), xbmc.LOGDEBUG) + + log("youtube_id", youtube_id) video_url = makeYouTubePluginUrl(youtube_id) no_url_found = False have_valid_url = True - xbmc.log("[ADDON] %s v%s (%s) debug mode, %s = %s" % ( - ADDON, VERSION, DATE, "video_url", str(video_url)), xbmc.LOGDEBUG) + log("video_url", video_url) # Play video... if have_valid_url: @@ -114,5 +118,6 @@ class Main: elif no_url_found: xbmcgui.Dialog().ok(LANGUAGE(30000), LANGUAGE(30107)) + def makeYouTubePluginUrl(youtube_id): return 'plugin://plugin.video.youtube/play/?video_id=%s' % youtube_id \ No newline at end of file diff --git a/plugin.video.hak5/resources/settings.xml b/plugin.video.hak5/resources/settings.xml index e69de29..fb5aafd 100644 --- a/plugin.video.hak5/resources/settings.xml +++ b/plugin.video.hak5/resources/settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file -- cgit v1.2.3