2 # -*- coding: utf-8 -*-
4 # Created on: 13.01.2017
14 import cPickle as pickle
19 """Consumes all the configuration data from Kodi as well as turns data into lists of folders and videos"""
21 def __init__ (self, plugin_handle, base_url):
22 """Fetches all needed info from Kodi & configures the baseline of the plugin
26 plugin_handle : :obj:`int`
32 self.plugin_handle = plugin_handle
33 self.base_url = base_url
34 self.addon = xbmcaddon.Addon()
35 self.plugin = self.addon.getAddonInfo('name')
36 self.base_data_path = xbmc.translatePath(self.addon.getAddonInfo('profile'))
37 self.home_path = xbmc.translatePath('special://home')
38 self.plugin_path = self.addon.getAddonInfo('path')
39 self.cookie_path = self.base_data_path + 'COOKIE'
40 self.data_path = self.base_data_path + 'DATA'
41 self.config_path = os.path.join(self.base_data_path, 'config')
42 self.msl_data_path = xbmc.translatePath('special://profile/addon_data/service.msl').decode('utf-8') + '/'
43 self.verb_log = self.addon.getSetting('logging') == 'true'
44 self.default_fanart = self.addon.getAddonInfo('fanart')
45 self.win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
50 """Refrsh the current list"""
51 return xbmc.executebuiltin('Container.Refresh')
53 def show_rating_dialog (self):
54 """Asks the user for a movie rating
59 Movie rating between 0 & 10
61 dlg = xbmcgui.Dialog()
62 return dlg.numeric(heading=self.get_local_string(string_id=30019) + ' ' + self.get_local_string(string_id=30022), type=0)
64 def show_search_term_dialog (self):
65 """Asks the user for a term to query the netflix search for
72 dlg = xbmcgui.Dialog()
73 term = dlg.input(self.get_local_string(string_id=30003), type=xbmcgui.INPUT_ALPHANUM)
78 def show_add_to_library_title_dialog (self, original_title):
79 """Asks the user for an alternative title for the show/movie that gets exported to the local library
83 original_title : :obj:`str`
84 Original title of the show (as suggested by the addon)
91 dlg = xbmcgui.Dialog()
92 return dlg.input(heading=self.get_local_string(string_id=30031), defaultt=original_title, type=xbmcgui.INPUT_ALPHANUM)
94 def show_password_dialog (self):
95 """Asks the user for its Netflix password
102 dlg = xbmcgui.Dialog()
103 return dlg.input(self.get_local_string(string_id=30004), type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
105 def show_email_dialog (self):
106 """Asks the user for its Netflix account email
111 Netflix account email
113 dlg = xbmcgui.Dialog()
114 return dlg.input(self.get_local_string(string_id=30005), type=xbmcgui.INPUT_ALPHANUM)
116 def show_login_failed_notification (self):
117 """Shows notification that the login failed
124 dialog = xbmcgui.Dialog()
125 dialog.notification(self.get_local_string(string_id=30008), self.get_local_string(string_id=30009), xbmcgui.NOTIFICATION_ERROR, 5000)
128 def show_missing_inputstream_addon_notification (self):
129 """Shows notification that the inputstream addon couldn't be found
136 dialog = xbmcgui.Dialog()
137 dialog.notification(self.get_local_string(string_id=30028), self.get_local_string(string_id=30029), xbmcgui.NOTIFICATION_ERROR, 5000)
140 def show_no_search_results_notification (self):
141 """Shows notification that no search results could be found
148 dialog = xbmcgui.Dialog()
149 dialog.notification(self.get_local_string(string_id=30011), self.get_local_string(string_id=30013))
152 def show_no_seasons_notification (self):
153 """Shows notification that no seasons be found
160 dialog = xbmcgui.Dialog()
161 dialog.notification(self.get_local_string(string_id=30010), self.get_local_string(string_id=30012))
164 def set_setting (self, key, value):
165 """Public interface for the addons setSetting method
170 Setting could be set or not
172 return self.addon.setSetting(key, value)
174 def get_credentials (self):
175 """Returns the users stored credentials
179 :obj:`dict` of :obj:`str`
180 The users stored account data
183 'email': self.addon.getSetting('email'),
184 'password': self.addon.getSetting('password')
187 def get_custom_library_settings (self):
188 """Returns the settings in regards to the custom library folder(s)
192 :obj:`dict` of :obj:`str`
193 The users library settings
196 'enablelibraryfolder': self.addon.getSetting('enablelibraryfolder'),
197 'customlibraryfolder': self.addon.getSetting('customlibraryfolder')
200 def get_ssl_verification_setting (self):
201 """Returns the setting that describes if we should verify the ssl transport when loading data
208 return self.addon.getSetting('ssl_verification') == 'true'
210 def set_main_menu_selection (self, type):
211 """Persist the chosen main menu entry in memory
218 self.win.setProperty('main_menu_selection', type)
220 def get_main_menu_selection (self):
221 """Gets the persisted chosen main menu entry from memory
226 The last chosen main menu entry
228 return self.win.getProperty('main_menu_selection')
230 def setup_memcache (self):
231 """Sets up the memory cache if not existant"""
232 cached_items = self.win.getProperty('memcache')
233 # no cache setup yet, create one
234 if len(cached_items) < 1:
235 self.win.setProperty('memcache', pickle.dumps({}))
237 def invalidate_memcache (self):
238 """Invalidates the memory cache"""
239 self.win.setProperty('memcache', pickle.dumps({}))
241 def has_cached_item (self, cache_id):
242 """Checks if the requested item is in memory cache
246 cache_id : :obj:`str`
247 ID of the cache entry
254 cached_items = pickle.loads(self.win.getProperty('memcache'))
255 return cache_id in cached_items.keys()
257 def get_cached_item (self, cache_id):
258 """Returns an item from the in memory cache
262 cache_id : :obj:`str`
263 ID of the cache entry
268 Contents of the requested cache item or none
270 cached_items = pickle.loads(self.win.getProperty('memcache'))
271 if self.has_cached_item(cache_id) != True:
273 return cached_items[cache_id]
275 def add_cached_item (self, cache_id, contents):
276 """Adds an item to the in memory cache
280 cache_id : :obj:`str`
281 ID of the cache entry
286 cached_items = pickle.loads(self.win.getProperty('memcache'))
287 cached_items.update({cache_id: contents})
288 self.win.setProperty('memcache', pickle.dumps(cached_items))
290 def build_profiles_listing (self, profiles, action, build_url):
291 """Builds the profiles list Kodi screen
295 profiles : :obj:`dict` of :obj:`str`
296 List of user profiles
299 Action paramter to build the subsequent routes
301 build_url : :obj:`fn`
302 Function to build the subsequent routes
309 for profile_id in profiles:
310 profile = profiles[profile_id]
311 url = build_url({'action': action, 'profile_id': profile_id})
312 li = xbmcgui.ListItem(label=profile['profileName'], iconImage=profile['avatar'])
313 li.setProperty('fanart_image', self.default_fanart)
314 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=True)
315 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
316 xbmcplugin.endOfDirectory(self.plugin_handle)
319 def build_main_menu_listing (self, video_list_ids, user_list_order, actions, build_url):
320 """Builds the video lists (my list, continue watching, etc.) Kodi screen
324 video_list_ids : :obj:`dict` of :obj:`str`
327 user_list_order : :obj:`list` of :obj:`str`
328 Ordered user lists, to determine what should be displayed in the main menue
330 actions : :obj:`dict` of :obj:`str`
331 Dictionary of actions to build subsequent routes
333 build_url : :obj:`fn`
334 Function to build the subsequent routes
342 for category in user_list_order:
343 for video_list_id in video_list_ids['user']:
344 if video_list_ids['user'][video_list_id]['name'] == category:
345 label = video_list_ids['user'][video_list_id]['displayName']
346 if category == 'netflixOriginals':
347 label = label.capitalize()
348 li = xbmcgui.ListItem(label=label)
349 li.setProperty('fanart_image', self.default_fanart)
350 # determine action route
351 action = actions['default']
352 if category in actions.keys():
353 action = actions[category]
354 # determine if the item should be selected
355 preselect_items.append((False, True)[category == self.get_main_menu_selection()])
356 url = build_url({'action': action, 'video_list_id': video_list_id, 'type': category})
357 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=True)
359 # add recommendations/genres as subfolders (save us some space on the home page)
361 'recommendations': self.get_local_string(30001),
362 'genres': self.get_local_string(30010)
364 for type in i18n_ids.keys():
365 # determine if the lists have contents
366 if len(video_list_ids[type]) > 0:
367 # determine action route
368 action = actions['default']
369 if type in actions.keys():
370 action = actions[type]
371 # determine if the item should be selected
372 preselect_items.append((False, True)[type == self.get_main_menu_selection()])
373 li_rec = xbmcgui.ListItem(label=i18n_ids[type])
374 li_rec.setProperty('fanart_image', self.default_fanart)
375 url_rec = build_url({'action': action, 'type': type})
376 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url_rec, listitem=li_rec, isFolder=True)
378 # add search as subfolder
379 action = actions['default']
380 if 'search' in actions.keys():
381 action = actions[type]
382 li_rec = xbmcgui.ListItem(label=self.get_local_string(30011))
383 li_rec.setProperty('fanart_image', self.default_fanart)
384 url_rec = build_url({'action': action, 'type': 'search'})
385 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url_rec, listitem=li_rec, isFolder=True)
388 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_UNSORTED)
389 xbmcplugin.endOfDirectory(self.plugin_handle)
391 # (re)select the previously selected main menu entry
393 for item in preselect_items:
395 preselected_list_item = idx if item else None
396 preselected_list_item = idx + 1 if self.get_main_menu_selection() == 'search' else preselected_list_item
397 if preselected_list_item != None:
398 xbmc.executebuiltin('ActivateWindowAndFocus(%s, %s)' % (str(self.win.getFocusId()), str(preselected_list_item)))
401 def build_video_listing (self, video_list, actions, type, build_url):
402 """Builds the video lists (my list, continue watching, etc.) contents Kodi screen
406 video_list_ids : :obj:`dict` of :obj:`str`
409 actions : :obj:`dict` of :obj:`str`
410 Dictionary of actions to build subsequent routes
413 None or 'queue' f.e. when it´s a special video lists
415 build_url : :obj:`fn`
416 Function to build the subsequent routes
423 for video_list_id in video_list:
424 video = video_list[video_list_id]
425 if type != 'queue' or (type == 'queue' and video['in_my_list'] == True):
426 li = xbmcgui.ListItem(label=video['title'])
427 # add some art to the item
428 li = self._generate_art_info(entry=video, li=li)
429 # it´s a show, so we need a subfolder & route (for seasons)
431 url = build_url({'action': actions[video['type']], 'show_id': video_list_id})
432 # lists can be mixed with shows & movies, therefor we need to check if its a movie, so play it right away
433 if video_list[video_list_id]['type'] == 'movie':
434 # it´s a movie, so we need no subfolder & a route to play it
436 url = build_url({'action': 'play_video', 'video_id': video_list_id})
438 li = self._generate_entry_info(entry=video, li=li)
439 li = self._generate_context_menu_items(entry=video, li=li)
440 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=isFolder)
442 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
443 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE)
444 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_VIDEO_YEAR)
445 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_GENRE)
446 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LASTPLAYED)
447 xbmcplugin.endOfDirectory(self.plugin_handle)
450 def build_search_result_listing (self, video_list, actions, build_url):
451 """Builds the search results list Kodi screen
455 video_list : :obj:`dict` of :obj:`str`
456 List of videos or shows
458 actions : :obj:`dict` of :obj:`str`
459 Dictionary of actions to build subsequent routes
461 build_url : :obj:`fn`
462 Function to build the subsequent routes
469 return self.build_video_listing(video_list=video_list, actions=actions, type='search', build_url=build_url)
471 def build_no_seasons_available (self):
472 """Builds the season list screen if no seasons could be found
479 self.show_no_seasons_notification()
480 xbmcplugin.endOfDirectory(self.plugin_handle)
483 def build_no_search_results_available (self, build_url, action):
484 """Builds the search results screen if no matches could be found
489 Action paramter to build the subsequent routes
491 build_url : :obj:`fn`
492 Function to build the subsequent routes
499 self.show_no_search_results_notification()
500 return xbmcplugin.endOfDirectory(self.plugin_handle)
502 def build_user_sub_listing (self, video_list_ids, type, action, build_url):
503 """Builds the video lists screen for user subfolders (genres & recommendations)
507 video_list_ids : :obj:`dict` of :obj:`str`
511 List type (genre or recommendation)
514 Action paramter to build the subsequent routes
516 build_url : :obj:`fn`
517 Function to build the subsequent routes
524 for video_list_id in video_list_ids:
525 li = xbmcgui.ListItem(video_list_ids[video_list_id]['displayName'])
526 li.setProperty('fanart_image', self.default_fanart)
527 url = build_url({'action': action, 'video_list_id': video_list_id})
528 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=True)
530 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
531 xbmcplugin.endOfDirectory(self.plugin_handle)
534 def build_season_listing (self, seasons_sorted, season_list, build_url):
535 """Builds the season list screen for a show
539 seasons_sorted : :obj:`list` of :obj:`str`
540 Sorted season indexes
542 season_list : :obj:`dict` of :obj:`str`
543 List of season entries
545 build_url : :obj:`fn`
546 Function to build the subsequent routes
553 for index in seasons_sorted:
554 for season_id in season_list:
555 season = season_list[season_id]
556 if int(season['idx']) == index:
557 li = xbmcgui.ListItem(label=season['text'])
558 # add some art to the item
559 li = self._generate_art_info(entry=season, li=li)
561 li = self._generate_entry_info(entry=season, li=li, base_info={'mediatype': 'season'})
562 li = self._generate_context_menu_items(entry=season, li=li)
563 url = build_url({'action': 'episode_list', 'season_id': season_id})
564 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=True)
566 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
567 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_VIDEO_YEAR)
568 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
569 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LASTPLAYED)
570 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE)
571 xbmcplugin.endOfDirectory(self.plugin_handle)
574 def build_episode_listing (self, episodes_sorted, episode_list, build_url):
575 """Builds the episode list screen for a season of a show
579 episodes_sorted : :obj:`list` of :obj:`str`
580 Sorted episode indexes
582 episode_list : :obj:`dict` of :obj:`str`
583 List of episode entries
585 build_url : :obj:`fn`
586 Function to build the subsequent routes
593 for index in episodes_sorted:
594 for episode_id in episode_list:
595 episode = episode_list[episode_id]
596 if int(episode['episode']) == index:
597 li = xbmcgui.ListItem(label=episode['title'])
598 # add some art to the item
599 li = self._generate_art_info(entry=episode, li=li)
601 li = self._generate_entry_info(entry=episode, li=li, base_info={'mediatype': 'episode'})
602 li = self._generate_context_menu_items(entry=episode, li=li)
603 url = build_url({'action': 'play_video', 'video_id': episode_id, 'start_offset': episode['bookmark']})
604 xbmcplugin.addDirectoryItem(handle=self.plugin_handle, url=url, listitem=li, isFolder=False)
606 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_EPISODE)
607 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_NONE)
608 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_VIDEO_YEAR)
609 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LABEL)
610 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_LASTPLAYED)
611 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_TITLE)
612 xbmcplugin.addSortMethod(handle=self.plugin_handle, sortMethod=xbmcplugin.SORT_METHOD_DURATION)
613 xbmcplugin.endOfDirectory(self.plugin_handle)
616 def play_item (self, esn, video_id, start_offset=-1):
622 ESN needed for Widevine/Inputstream
624 video_id : :obj:`str`
625 ID of the video that should be played
627 start_offset : :obj:`str`
628 Offset to resume playback from (in seconds)
635 inputstream_addon = self.get_inputstream_addon()
636 if inputstream_addon == None:
637 self.show_missing_inputstream_addon_notification()
638 self.log(msg='Inputstream addon not found')
641 # inputstream addon properties
642 msl_service_url = 'http://localhost:' + str(self.addon.getSetting('msl_service_port'))
643 play_item = xbmcgui.ListItem(path=msl_service_url + '/manifest?id=' + video_id)
644 play_item.setProperty(inputstream_addon + '.license_type', 'com.widevine.alpha')
645 play_item.setProperty(inputstream_addon + '.manifest_type', 'mpd')
646 play_item.setProperty(inputstream_addon + '.license_key', msl_service_url + '/license?id=' + video_id + '||b{SSM}!b{SID}|')
647 play_item.setProperty(inputstream_addon + '.server_certificate', 'Cr0CCAMSEOVEukALwQ8307Y2+LVP+0MYh/HPkwUijgIwggEKAoIBAQDm875btoWUbGqQD8eAGuBlGY+Pxo8YF1LQR+Ex0pDONMet8EHslcZRBKNQ/09RZFTP0vrYimyYiBmk9GG+S0wB3CRITgweNE15cD33MQYyS3zpBd4z+sCJam2+jj1ZA4uijE2dxGC+gRBRnw9WoPyw7D8RuhGSJ95OEtzg3Ho+mEsxuE5xg9LM4+Zuro/9msz2bFgJUjQUVHo5j+k4qLWu4ObugFmc9DLIAohL58UR5k0XnvizulOHbMMxdzna9lwTw/4SALadEV/CZXBmswUtBgATDKNqjXwokohncpdsWSauH6vfS6FXwizQoZJ9TdjSGC60rUB2t+aYDm74cIuxAgMBAAE6EHRlc3QubmV0ZmxpeC5jb20SgAOE0y8yWw2Win6M2/bw7+aqVuQPwzS/YG5ySYvwCGQd0Dltr3hpik98WijUODUr6PxMn1ZYXOLo3eED6xYGM7Riza8XskRdCfF8xjj7L7/THPbixyn4mULsttSmWFhexzXnSeKqQHuoKmerqu0nu39iW3pcxDV/K7E6aaSr5ID0SCi7KRcL9BCUCz1g9c43sNj46BhMCWJSm0mx1XFDcoKZWhpj5FAgU4Q4e6f+S8eX39nf6D6SJRb4ap7Znzn7preIvmS93xWjm75I6UBVQGo6pn4qWNCgLYlGGCQCUm5tg566j+/g5jvYZkTJvbiZFwtjMW5njbSRwB3W4CrKoyxw4qsJNSaZRTKAvSjTKdqVDXV/U5HK7SaBA6iJ981/aforXbd2vZlRXO/2S+Maa2mHULzsD+S5l4/YGpSt7PnkCe25F+nAovtl/ogZgjMeEdFyd/9YMYjOS4krYmwp3yJ7m9ZzYCQ6I8RQN4x/yLlHG5RH/+WNLNUs6JAZ0fFdCmw=')
648 # TODO: Change when Kodi can handle/trnsfer defaults in hidden values in settings
649 #play_item.setProperty(inputstream_addon + '.server_certificate', self.addon.getSetting('msl_service_certificate'))
650 play_item.setProperty('inputstreamaddon', inputstream_addon)
652 # check if we have a bookmark e.g. start offset position
653 if int(start_offset) > 0:
654 play_item.setProperty('StartOffset', str(start_offset) + '.0')
655 return xbmcplugin.setResolvedUrl(self.plugin_handle, True, listitem=play_item)
657 def _generate_art_info (self, entry, li):
658 """Adds the art info from an entry to a Kodi list item
662 entry : :obj:`dict` of :obj:`str`
663 Entry that should be turned into a list item
665 li : :obj:`XMBC.ListItem`
666 Kodi list item instance
671 Kodi list item instance
673 art = {'fanart': self.default_fanart}
674 if 'boxarts' in dict(entry).keys():
676 'poster': entry['boxarts']['big'],
677 'landscape': entry['boxarts']['big'],
678 'thumb': entry['boxarts']['small'],
679 'fanart': entry['boxarts']['big']
681 if 'interesting_moment' in dict(entry).keys():
683 'poster': entry['interesting_moment'],
684 'fanart': entry['interesting_moment']
686 if 'thumb' in dict(entry).keys():
687 art.update({'thumb': entry['thumb']})
688 if 'fanart' in dict(entry).keys():
689 art.update({'fanart': entry['fanart']})
690 if 'poster' in dict(entry).keys():
691 art.update({'poster': entry['poster']})
695 def _generate_entry_info (self, entry, li, base_info={}):
696 """Adds the item info from an entry to a Kodi list item
700 entry : :obj:`dict` of :obj:`str`
701 Entry that should be turned into a list item
703 li : :obj:`XMBC.ListItem`
704 Kodi list item instance
706 base_info : :obj:`dict` of :obj:`str`
707 Additional info that overrules the entry info
712 Kodi list item instance
715 entry_keys = entry.keys()
716 if 'cast' in entry_keys and len(entry['cast']) > 0:
717 infos.update({'cast': entry['cast']})
718 if 'creators' in entry_keys and len(entry['creators']) > 0:
719 infos.update({'writer': entry['creators'][0]})
720 if 'directors' in entry_keys and len(entry['directors']) > 0:
721 infos.update({'director': entry['directors'][0]})
722 if 'genres' in entry_keys and len(entry['genres']) > 0:
723 infos.update({'genre': entry['genres'][0]})
724 if 'maturity' in entry_keys:
725 if 'mpaa' in entry_keys:
726 infos.update({'mpaa': entry['mpaa']})
728 infos.update({'mpaa': str(entry['maturity']['board']) + '-' + str(entry['maturity']['value'])})
729 if 'rating' in entry_keys:
730 infos.update({'rating': int(entry['rating']) * 2})
731 if 'synopsis' in entry_keys:
732 infos.update({'plot': entry['synopsis']})
733 if 'plot' in entry_keys:
734 infos.update({'plot': entry['plot']})
735 if 'runtime' in entry_keys:
736 infos.update({'duration': entry['runtime']})
737 if 'duration' in entry_keys:
738 infos.update({'duration': entry['duration']})
739 if 'seasons_label' in entry_keys:
740 infos.update({'season': entry['seasons_label']})
741 if 'season' in entry_keys:
742 infos.update({'season': entry['season']})
743 if 'title' in entry_keys:
744 infos.update({'title': entry['title']})
745 if 'type' in entry_keys:
746 if entry['type'] == 'movie' or entry['type'] == 'episode':
747 li.setProperty('IsPlayable', 'true')
748 if 'mediatype' in entry_keys:
749 if entry['mediatype'] == 'movie' or entry['mediatype'] == 'episode':
750 li.setProperty('IsPlayable', 'true')
751 infos.update({'mediatype': entry['mediatype']})
752 if 'watched' in entry_keys:
753 infos.update({'playcount': (1, 0)[entry['watched']]})
754 if 'index' in entry_keys:
755 infos.update({'episode': entry['index']})
756 if 'episode' in entry_keys:
757 infos.update({'episode': entry['episode']})
758 if 'year' in entry_keys:
759 infos.update({'year': entry['year']})
760 if 'quality' in entry_keys:
761 quality = {'width': '960', 'height': '540'}
762 if entry['quality'] == '720':
763 quality = {'width': '1280', 'height': '720'}
764 if entry['quality'] == '1080':
765 quality = {'width': '1920', 'height': '1080'}
766 li.addStreamInfo('video', quality)
767 li.setInfo('video', infos)
770 def _generate_context_menu_items (self, entry, li):
771 """Adds context menue items to a Kodi list item
775 entry : :obj:`dict` of :obj:`str`
776 Entry that should be turned into a list item
778 li : :obj:`XMBC.ListItem`
779 Kodi list item instance
783 Kodi list item instance
787 entry_keys = entry.keys()
789 # action item templates
790 encoded_title = urllib.urlencode({'title': entry['title'].encode('utf-8')}) if 'title' in entry else ''
791 url_tmpl = 'XBMC.RunPlugin(' + self.base_url + '?action=%action%&id=' + str(entry['id']) + '&' + encoded_title + ')'
793 ['export_to_library', self.get_local_string(30018), 'export'],
794 ['remove_from_library', self.get_local_string(30030), 'remove'],
795 ['rate_on_netflix', self.get_local_string(30019), 'rating'],
796 ['remove_from_my_list', self.get_local_string(30020), 'remove_from_list'],
797 ['add_to_my_list', self.get_local_string(30021), 'add_to_list']
800 # build concrete action items
801 for action_item in actions:
802 action.update({action_item[0]: [action_item[1], url_tmpl.replace('%action%', action_item[2])]})
804 # add or remove the movie/show/season/episode from & to the users "My List"
805 if 'in_my_list' in entry_keys:
806 items.append(action['remove_from_my_list']) if entry['in_my_list'] else items.append(action['add_to_my_list'])
807 elif 'queue' in entry_keys:
808 items.append(action['remove_from_my_list']) if entry['queue'] else items.append(action['add_to_my_list'])
809 elif 'my_list' in entry_keys:
810 items.append(action['remove_from_my_list']) if entry['my_list'] else items.append(action['add_to_my_list'])
811 # rate the movie/show/season/episode on Netflix
812 items.append(action['rate_on_netflix'])
814 # add possibility to export this movie/show/season/episode to a static/local library (and to remove it)
815 if 'type' in entry_keys:
817 if entry['type'] == 'movie':
818 action_type = 'remove_from_library' if self.library.movie_exists(title=entry['title'], year=entry['year']) else 'export_to_library'
819 items.append(action[action_type])
821 if entry['type'] == 'show' and 'title' in entry_keys:
822 action_type = 'remove_from_library' if self.library.show_exists(title=entry['title']) else 'export_to_library'
823 items.append(action[action_type])
826 li.addContextMenuItems(items)
829 def log (self, msg, level=xbmc.LOGDEBUG):
830 """Adds a log entry to the Kodi log
835 Entry that should be turned into a list item
840 if isinstance(msg, unicode):
841 msg = msg.encode('utf-8')
842 xbmc.log('[%s] %s' % (self.plugin, msg.__str__()), level)
844 def get_local_string (self, string_id):
845 """Returns the localized version of a string
849 string_id : :obj:`int`
850 ID of the string that shoudl be fetched
855 Requested string or empty string
857 src = xbmc if string_id < 30000 else self.addon
858 locString = src.getLocalizedString(string_id)
859 if isinstance(locString, unicode):
860 locString = locString.encode('utf-8')
863 def get_inputstream_addon (self):
864 """Checks if the inputstream addon is installed & enabled.
865 Returns the type of the inputstream addon used or None if not found
870 Inputstream addon or None
872 type = 'inputstream.adaptive'
876 'method': 'Addons.GetAddonDetails',
879 'properties': ['enabled']
882 response = xbmc.executeJSONRPC(json.dumps(payload))
883 data = json.loads(response)
884 if not 'error' in data.keys():
885 if data['result']['addon']['enabled'] == True:
889 def set_library (self, library):
890 """Adds an instance of the Library class
894 library : :obj:`Library`
895 instance of the Library class
897 self.library = library