Skip to content

Instantly share code, notes, and snippets.

@henryjfry
Last active February 18, 2020 05:27
Show Gist options
  • Save henryjfry/29b303fb5fe4e8895b5effb54a999785 to your computer and use it in GitHub Desktop.
Save henryjfry/29b303fb5fe4e8895b5effb54a999785 to your computer and use it in GitHub Desktop.
TMDBHelper Sync Trakt to library - /home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/traktapi.py
kodi-send --action='RunPlugin(plugin://plugin.video.themoviedb.helper?info=trakt_collection2)'
####/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/container.py
def list_traktcollection2(self):
items = TraktAPI(tmdb='tv', login=True).get_collection2('tv', utils.try_parse_int(self.params.get('page', 1)))
###
def list_play(self):
if not self.params.get('type') or not self.params.get('tmdb_id'):
return
season, episode = self.params.get('season'), self.params.get('episode')
command = 'RunScript(plugin.video.themoviedb.helper,play={0},tmdb_id={1}{{0}})'.format(self.params.get('type'), self.params.get('tmdb_id'))
command = command.format(',season={0},episode={1}'.format(season, episode) if season and episode else '')
xbmc.executebuiltin(command)
xbmc.executebuiltin('ActivateWindow(busydialognocancel)')
if not self.params.get('widget') and not self.params.get('nextpage'):
xbmcplugin.setResolvedUrl(self.handle, True, ListItem().set_listitem())
#ROUTER LIST FUNCTIONS
elif self.params.get('info') == 'trakt_collection2':
# self.list_traktcollection2()
items = TraktAPI(tmdb='tv', login=True).get_collection2('tv', utils.try_parse_int(self.params.get('page', 1)))
####/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/traktapi.py
def get_collection2(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=play&tvdb_id=' + str(i['show']['ids']['tvdb']) + '&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
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