# Module: KodiHelper
# Created on: 13.01.2017
-import os
-import urllib
import xbmcplugin
import xbmcgui
-import xbmcaddon
import xbmc
import json
-import uuid
+from os.path import join
+from urllib import urlencode
+from xbmcaddon import Addon
+from uuid import uuid4
from UniversalAnalytics import Tracker
try:
import cPickle as pickle
class KodiHelper:
"""Consumes all the configuration data from Kodi as well as turns data into lists of folders and videos"""
- def __init__ (self, plugin_handle, base_url):
+ def __init__ (self, plugin_handle=None, base_url=None):
"""Fetches all needed info from Kodi & configures the baseline of the plugin
Parameters
"""
self.plugin_handle = plugin_handle
self.base_url = base_url
- self.addon = xbmcaddon.Addon()
+ self.addon = Addon()
self.plugin = self.addon.getAddonInfo('name')
self.base_data_path = xbmc.translatePath(self.addon.getAddonInfo('profile'))
self.home_path = xbmc.translatePath('special://home')
self.plugin_path = self.addon.getAddonInfo('path')
self.cookie_path = self.base_data_path + 'COOKIE'
self.data_path = self.base_data_path + 'DATA'
- self.config_path = os.path.join(self.base_data_path, 'config')
+ self.config_path = join(self.base_data_path, 'config')
self.msl_data_path = xbmc.translatePath('special://profile/addon_data/service.msl').decode('utf-8') + '/'
self.verb_log = self.addon.getSetting('logging') == 'true'
self.default_fanart = self.addon.getAddonInfo('fanart')
"""
for video_list_id in video_list:
video = video_list[video_list_id]
- if type != 'queue' or (type == 'queue' and video['in_my_list'] == True):
- li = xbmcgui.ListItem(label=video['title'])
- # add some art to the item
- li = self._generate_art_info(entry=video, li=li)
- # it´s a show, so we need a subfolder & route (for seasons)
- isFolder = True
- url = build_url({'action': actions[video['type']], 'show_id': video_list_id})
- # lists can be mixed with shows & movies, therefor we need to check if its a movie, so play it right away
- if video_list[video_list_id]['type'] == 'movie':
- # it´s a movie, so we need no subfolder & a route to play it
- isFolder = False
- url = build_url({'action': 'play_video', 'video_id': video_list_id})
- # add list item info
- li = self._generate_entry_info(entry=video, li=li)
- li = self._generate_context_menu_items(entry=video, li=li)
- xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=isFolder)
+ li = xbmcgui.ListItem(label=video['title'])
+ # add some art to the item
+ li = self._generate_art_info(entry=video, li=li)
+ # it´s a show, so we need a subfolder & route (for seasons)
+ isFolder = True
+ url = build_url({'action': actions[video['type']], 'show_id': video_list_id})
+ # lists can be mixed with shows & movies, therefor we need to check if its a movie, so play it right away
+ if video_list[video_list_id]['type'] == 'movie':
+ # it´s a movie, so we need no subfolder & a route to play it
+ isFolder = False
+ url = build_url({'action': 'play_video', 'video_id': video_list_id})
+ # add list item info
+ li = self._generate_entry_info(entry=video, li=li)
+ li = self._generate_context_menu_items(entry=video, li=li)
+ xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=isFolder)
xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE)
entry_keys = entry.keys()
# action item templates
- encoded_title = urllib.urlencode({'title': entry['title'].encode('utf-8')}) if 'title' in entry else ''
+ encoded_title = urlencode({'title': entry['title'].encode('utf-8')}) if 'title' in entry else ''
url_tmpl = 'XBMC.RunPlugin(' + self.base_url + '?action=%action%&id=' + str(entry['id']) + '&' + encoded_title + ')'
actions = [
['export_to_library', self.get_local_string(30018), 'export'],
#Get or Create Tracking id
tracking_id = self.addon.getSetting('tracking_id')
if tracking_id is '':
- tracking_id = str(uuid.uuid4())
+ tracking_id = str(uuid4())
self.addon.setSetting('tracking_id', tracking_id)
# Send the tracking event
tracker = Tracker.create('UA-46081640-5', client_id=tracking_id)