Skip to content

Instantly share code, notes, and snippets.

@henryjfry
Last active May 8, 2020 19:43
Show Gist options
  • Save henryjfry/f995092ab9b68f217d5879b7798a849e to your computer and use it in GitHub Desktop.
Save henryjfry/f995092ab9b68f217d5879b7798a849e to your computer and use it in GitHub Desktop.
TMDB => Play4/get_collection_tv/build_details => /home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/player.py
###/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/player.py
def play(self, itemtype, tmdb_id, season=None, episode=None, force_dialog=False):
###########
# Attempt to play local file first
is_local = False
# if self.details and self.itemtype == 'movie':
# is_local = self.playmovie()
# if self.details and self.itemtype == 'episode':
# is_local = self.playepisode()
# if is_local:
# return is_local
def build_details(self):
###########
from resources.lib.fanarttv import FanartTV
if self.itemtype == 'episode': # Do some special episode stuff
self.item['plot'] = self.details.get('infolabels', {}).get('plot')
self.item['id'] = self.item.get('tvdb')
self.item['title'] = self.details.get('infolabels', {}).get('title') # Set Episode Title
self.item['name'] = u'{0} S{1:02d}E{2:02d}'.format(self.item.get('showname'), int(self.season), int(self.episode))
self.item['season'] = self.season
self.item['episode'] = self.episode
artwork = FanartTV.get_tvshow_allart(self.fanarttv, self.item['tvdb'])
self.item['banner'] = artwork.get('banner')
self.item['landscape'] =artwork.get('landscape')
self.item['fanart'] = artwork.get('fanart')
self.item['poster'] = artwork.get('poster')
self.item['clearlogo'] = artwork.get('clearlogo')
self.item['clearart'] = artwork.get('clearart')
else:
self.item['plot'] = self.details.get('infolabels', {}).get('plot')
artwork = FanartTV.get_movie_allart(self.fanarttv, self.tmdb_id)
self.item['banner'] = artwork.get('banner')
self.item['landscape'] =artwork.get('landscape')
self.item['fanart'] = artwork.get('fanart')
self.item['poster'] = artwork.get('poster')
self.item['clearlogo'] = artwork.get('clearlogo')
self.item['clearart'] = artwork.get('clearart')
###/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/traktapi.py
def get_recentlywatched(self, userslug, tmdbtype, limit=None, islistitem=True, months=12):
start_at = datetime.date.today() - datetime.timedelta(months * 365 / 12)
history = self.get_response_json('users', userslug, 'history', utils.type_convert(tmdbtype, 'trakt') + 's', page=1, limit=600, start_at=start_at.strftime("%Y-%m-%d"))
return self.get_limitedlist(history, tmdbtype, limit, islistitem)
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)
###/home/osmc/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/container.py
class Container(Plugin):
def __init__(self):
###########
self.trakt_limit = 60 if self.addon.getSettingBool('trakt_extendlimit') else 10
def list_items(self, items=None, url=None, url_tmdb_id=None, get_sortedlist=True):
###########
# i.get_extra_artwork(self.tmdb, self.fanarttv) if len(items) < 22 and self.exp_fanarttv() else None
i.get_extra_artwork(self.tmdb, self.fanarttv)
def router(self):
###########
# ROUTER LIST FUNCTIONS
# if self.params.get('info') == 'play' and not self.play_islocked():
# self.list_getid()
# self.list_play()
if self.params.get('info') == 'textviewer':
###########
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)))
elif self.params.get('info') == 'unlock':
# xbmcgui.Window(10000).setProperty('TMDbHelper.Player.ResolvedUrl', 'false')
xbmc.log('UNLOCK '+'===>TMDBHelper', level=xbmc.LOGNOTICE)
xbmcgui.Window(10000).clearProperty('TMDbHelper.Player.ResolvedUrl')
elif self.params.get('info') == 'play4' or self.params.get('info') == 'play'
#url = plugin://plugin.video.themoviedb.helper?info=play4&amp;type=episode&amp;tmdb_id=95&amp;season=1&amp;episode=1
lock = self.paramstring
cur_lock = xbmcgui.Window(10000).getProperty('TMDbHelper.Player.ResolvedUrl')
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
current_position = playlist.getposition()
xbmc.log(str(playlist.size())+' duration ===SERVICE_NEXT_PLAYLIST', level=xbmc.LOGNOTICE)
# xbmc.log(str(xbmcgui.getCurrentWindowDialogId())+'===>TMDBHelper', level=xbmc.LOGNOTICE)
# xbmc.log(str(cur_lock)+'===>TMDBHelper', level=xbmc.LOGNOTICE)
if cur_lock == 'true':
# xbmc.log('cur_lock Exists Exiting '+'===>TMDBHelper', level=xbmc.LOGNOTICE)
xbmcplugin.endOfDirectory(self.handle, updateListing=False, cacheToDisc=False)
# xbmcplugin.setResolvedUrl(self.handle, True, ListItem().set_listitem())
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 type == 'episode' or type == 'tv':
params = self.params.copy()
params['type'] = 'tv'
tmdb_id_no = self.get_tmdb_id(**params)
if not cur_lock == 'true':
from resources.lib.player import Player
# xbmcgui.Window(10000).setProperty('TMDbHelper.Player.ResolvedUrl', lock)
xbmcgui.Window(10000).setProperty('TMDbHelper.Player.ResolvedUrl', 'true')
xbmc.log('setProperty '+ str(lock) +'||===>TMDBHelper', level=xbmc.LOGNOTICE)
xbmcplugin.endOfDirectory(self.handle, updateListing=False, cacheToDisc=False)
if type == 'episode' or type == 'tv':
action = Player().play(itemtype='episode', tmdb_id=tmdb_id_no, season=season, episode=episode)
if type == 'movie':
action = Player().play(itemtype='movie', tmdb_id=tmdb_id_no)
# xbmcplugin.setResolvedUrl(self.handle, True, ListItem().set_listitem())
xbmc.executebuiltin('Dialog.Close(busydialognocancel)')
xbmc.sleep(5000)
xbmcgui.Window(10000).clearProperty('TMDbHelper.Player.ResolvedUrl') # Clear our lock property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment