Last active
September 15, 2021 20:36
-
-
Save henryjfry/d402418d08c24b08b85f129901ecc3e2 to your computer and use it in GitHub Desktop.
TMDBHelper Library integration: ~/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/container.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kodi-send --action='RunPlugin(plugin://plugin.video.themoviedb.helper?info=trakt_collection_tv)' | |
###~/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/container.py | |
def router(self): | |
# ROUTER LIST FUNCTIONS | |
if self.params.get('info') == 'stream': | |
from resources.lib.player import Player | |
xbmcplugin.setResolvedUrl(self.handle, True, xbmcgui.ListItem(path=str())) | |
params = self.params.copy() | |
Player().play(itemtype='episode', tmdb_id=self.params.get('tmdb_id'), season=self.params.get('season'), episode=self.params.get('episode')) | |
elif self.params.get('info') == 'trakt_collection_tv': | |
items = TraktAPI(tmdb='tv', login=True).get_collection_tv('tv', utils.try_parse_int(self.params.get('page', 1))) | |
if self.params.get('info') == 'play4': | |
#url = plugin://plugin.video.themoviedb.helper?info=play4&type=episode&tmdb_id=95&season=1&episode=1 | |
import os | |
addon_handle = self.handle | |
xbmc.log(str(xbmcgui.getCurrentWindowDialogId())+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
if os.path.exists('/home/osmc/' + self.paramstring): | |
xbmc.log('File Exists Exiting '+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
xbmcplugin.endOfDirectory(addon_handle, updateListing=False, cacheToDisc=False) | |
exit() | |
xbmc.executebuiltin('ActivateWindow(busydialognocancel)') | |
type = self.params.get('type') | |
episode = self.params.get('episode') | |
season = self.params.get('season') | |
year = self.params.get('year') | |
params = self.params | |
if self.params.get('type') == 'episode': | |
params = self.params.copy() | |
params['type'] = 'tv' | |
tmdb_id_no = self.get_tmdb_id(**params) | |
xbmc.log(str('/home/osmc/' + self.paramstring)+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
if not os.path.exists('/home/osmc/' + self.paramstring): | |
from resources.lib.player import Player | |
f= open('/home/osmc/' + self.paramstring,"w+") | |
xbmcplugin.endOfDirectory(addon_handle, updateListing=False, cacheToDisc=False) | |
if type == 'episode': | |
Player().play(itemtype='episode', tmdb_id=tmdb_id_no, season=season, episode=episode) | |
if type == 'movie': | |
Player().play(itemtype='movie', tmdb_id=tmdb_id_no) | |
""" | |
xbmc.log(str('While...')+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
while not 'Play with ' in xbmc.getInfoLabel('System.CurrentControl') or not 'Search ' in xbmc.getInfoLabel('System.CurrentControl'): | |
xbmc.sleep(1000) | |
xbmc.log(str(xbmc.getInfoLabel('System.CurrentControl'))+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
if 'Play with ' in xbmc.getInfoLabel('System.CurrentControl'): | |
break | |
if 'Search ' in xbmc.getInfoLabel('System.CurrentControl'): | |
break | |
xbmc.log(str('After While ')+'===>TMDBHelper', level=xbmc.LOGNOTICE) | |
""" | |
f.close | |
try: | |
os.remove('/home/osmc/' + self.paramstring) | |
except: | |
pass | |
xbmc.executebuiltin('Dialog.Close(busydialognocancel)') | |
return | |
####/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/traktapi.py | |
#kodi-send --action='RunPlugin(plugin://plugin.video.themoviedb.helper?info=trakt_collection_tv)' | |
def get_collection_tv(self, tmdbtype, page=1): | |
xbmc.log('START_SYNC_TRAKT_COLLECTION===>TMDB HELPER', level=xbmc.LOGNOTICE) | |
import xbmcaddon | |
import os | |
__addon__ = xbmcaddon.Addon() | |
__addonid__ = __addon__.getAddonInfo('id') | |
basedir_tv = __addon__.getSettingString('tvshows_library') or 'special://profile/addon_data/plugin.video.themoviedb.helper/tvshows/' | |
file_path = str(xbmc.translatePath('special://userdata/addon_data/'))+str(__addonid__) + '/TVShows' | |
if not os.path.exists(file_path): | |
os.mkdir(file_path) | |
collection = self.sync_collection(utils.type_convert(tmdbtype, 'trakt')) | |
collection = sorted(collection, key=lambda i: i[utils.type_convert(tmdbtype, 'trakt')]['title'], reverse=False) | |
for i in collection: | |
nfo = 'https://thetvdb.com/?tab=series&id=' + str(i['show']['ids']['tvdb']) | |
nfo_path = file_path + '/' + str(i['show']['ids']['tvdb']) + '/' + 'tvshow.nfo' | |
if not os.path.exists(file_path + '/' + str(i['show']['ids']['tvdb'])): | |
os.mkdir(file_path + '/' + str(i['show']['ids']['tvdb'])) | |
if not os.path.exists(nfo_path): | |
file = open(nfo_path, 'w') | |
file.write(nfo) | |
file.close() | |
# xbmc.log(str(nfo)+'||'+str(i['show']['ids']['tvdb'])+'||'+str(i['show']['title'])+'||===>TMDB HELPER', level=xbmc.LOGNOTICE) | |
for s in i['seasons']: | |
if not os.path.exists(file_path + '/' + str(i['show']['ids']['tvdb']) + '/Season ' + str(s['number'])): | |
os.mkdir(file_path + '/' + str(i['show']['ids']['tvdb']) + '/Season ' + str(s['number'])) | |
for e in s['episodes']: | |
url = "plugin://plugin.video.themoviedb.helper?info=play4&type=episode&tmdb_id=" + str(i['show']['ids']['tmdb']) + "&season=" + str(s['number']) + "&episode=" + str(e['number']) | |
# url = "plugin://plugin.video.openmeta/play_stream/info?type=episode&tmdb_id=" + str(i['show']['ids']['tmdb']) + "&season=" + str(s['number']) + "&episode=" + str(e['number']) | |
# url = 'plugin://plugin.video.themoviedb.helper?info=stream&tmdb_id=' + str(i['show']['ids']['tmdb']) + '&type=episode&season=' + str(s['number']) + '&episode=' + str(e['number']) | |
# url = 'plugin://plugin.video.themoviedb.helper?info=play&query=' + str(i['show']['title']) + '&type=episode&season=' + str(s['number']) + '&episode=' + str(e['number']) | |
file_name = str(i['show']['title']) +' - S' + format(s['number'], '02d') + 'E' + format(e['number'], '02d') + '.strm' | |
for c in r'[]/\;,><&*:%=+@!#^()|?^': | |
file_name = file_name.replace(c,'') | |
strm_path = file_path + '/' + str(i['show']['ids']['tvdb']) + '/Season ' + str(s['number']) + '/' + file_name | |
#Overwrite existing strm files. | |
# file = open(strm_path, 'w') | |
# file.write(url) | |
# file.close() | |
if not os.path.exists(strm_path): | |
file = open(strm_path, 'w') | |
file.write(url) | |
file.close() | |
# xbmc.executebuiltin('UpdateLibrary(video, {})'.format(basedir_tv)) | |
xbmc.log('END_SYNC_TRAKT_COLLECTION===>TMDB HELPER', level=xbmc.LOGNOTICE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment