fix(my-list): Fixes that not all videos have been shown on the list
[plugin.video.netflix.git] / resources / lib / KodiHelper.py
index 94516caf1868718b68f920efa3e572d7594d334a..7519c99fa9b78166ff5409bc8a17d6e4c6385fa4 100644 (file)
@@ -3,14 +3,14 @@
 # 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
@@ -20,7 +20,7 @@ except:
 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
@@ -33,14 +33,14 @@ class KodiHelper:
         """
         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')
@@ -430,22 +430,21 @@ class KodiHelper:
         """
         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)
@@ -801,7 +800,7 @@ class KodiHelper:
         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'],
@@ -922,7 +921,7 @@ class KodiHelper:
             #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)