Esempio n. 1
0
def scrape_next_episode(tvshowtitle, year, imdb, tvdb, lang, season=None, episode=None):

	from resources.lib.sources import sources
	from resources.lib.indexers import episodes
	
	title = tvshowtitle
	
	next_episode = episodes.seasons().tvdb_list(tvshowtitle, year, imdb, tvdb, 'en', limit='nextepisode', season=season, episode=episode)

	premiered     = next_episode[0]['premiered']
	new_season    = next_episode[0]['season']
	new_episode   = next_episode[0]['episode']
	meta = []
	select = '3'
		
	sources().smartplay(title, year, imdb, tvdb, '0', new_season, new_episode, tvshowtitle, premiered, '', autoplay=False, background=True)
	return next_episode[0]
Esempio n. 2
0
def next_episode(tvshowtitle,
                 year,
                 imdb,
                 tvdb,
                 lang,
                 season=None,
                 episode=None):
    from resources.lib.indexers import episodes
    title = tvshowtitle
    next_episode = episodes.seasons().tvdb_list(tvshowtitle,
                                                year,
                                                imdb,
                                                tvdb,
                                                'en',
                                                limit='nextepisode',
                                                season=season,
                                                episode=episode)
    return next_episode[0]
Esempio n. 3
0
elif action == 'tvCertificates':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().certifications()

elif action == 'tvPersons':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().persons(url)

elif action == 'tvUserlists':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().userlists()

elif action == 'seasons':
    from resources.lib.indexers import episodes
    episodes.seasons().get(tvshowtitle, year, imdb, tvdb)

elif action == 'episodes':
    from resources.lib.indexers import episodes
    episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode)

elif action == 'calendar':
    from resources.lib.indexers import episodes
    episodes.episodes().calendar(url)

elif action == 'tvWidget':
    from resources.lib.indexers import episodes
    episodes.episodes().widget()

elif action == 'calendars':
    from resources.lib.indexers import episodes
Esempio n. 4
0
elif action == 'tvCertificates':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().certifications()

elif action == 'tvPersons':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().persons(url)

elif action == 'tvUserlists':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().userlists()

elif action == 'seasons':
    from resources.lib.indexers import episodes
    episodes.seasons().get(tvshowtitle, year, imdb, tvdb)

elif action == 'episodes':
    from resources.lib.indexers import episodes
    episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode)

elif action == 'calendar':
    from resources.lib.indexers import episodes
    episodes.episodes().calendar(url)

elif action == 'tvWidget':
    from resources.lib.indexers import episodes
    episodes.episodes().widget()

elif action == 'calendars':
    from resources.lib.indexers import episodes
Esempio n. 5
0
elif action == 'tvNetworks':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().networks()

elif action == 'tvCertificates':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().certifications()

elif action == 'tvUserlists':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().userlists()

elif action == 'seasons':
    from resources.lib.indexers import episodes
    episodes.seasons().get(tvshowtitle, year, imdb, tvdb)

elif action == 'episodes':
    from resources.lib.indexers import episodes
    episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode)

elif action == 'calendar':
    from resources.lib.indexers import episodes
    episodes.episodes().calendar(url)

elif action == 'tvWidget':
    from resources.lib.indexers import episodes
    episodes.episodes().widget()

elif action == 'calendars':
    from resources.lib.indexers import episodes
Esempio n. 6
0
elif action == 'tvCertificates':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().certifications()

elif action == 'tvPersons':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().persons(url)

elif action == 'tvUserlists':
    from resources.lib.indexers import tvshows
    tvshows.tvshows().userlists()

elif action == 'seasons':
    from resources.lib.indexers import episodes
    episodes.seasons().get(tvshowtitle, year, imdb, tvdb)

elif action == 'episodes':
    from resources.lib.indexers import episodes
    episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode)

elif action == 'calendar':
    from resources.lib.indexers import episodes
    episodes.episodes().calendar(url)

elif action == 'tvWidget':
    from resources.lib.indexers import episodes
    episodes.episodes().widget()

elif action == 'calendars':
    from resources.lib.indexers import episodes
Esempio n. 7
0
def tvshows(tvshowtitle, imdb, tmdb, season, watched):
    control.busy()
    try:
        import sys, xbmc

        if not trakt.getTraktIndicatorsInfo() == False: raise Exception()

        from resources.lib.indexers import episodes

        name = control.addonInfo('name')

        dialog = control.progressDialogBG
        dialog.create(str(name), str(tvshowtitle))
        dialog.update(0, str(name), str(tvshowtitle))

        #log_utils.log('playcount_season: ' + str(season))
        items = []
        if season:
            items = episodes.episodes().get(tvshowtitle,
                                            '0',
                                            imdb,
                                            tmdb,
                                            meta=None,
                                            season=season,
                                            idx=False)
            items = [
                i for i in items
                if int('%01d' % int(season)) == int('%01d' % int(i['season']))
            ]
            items = [{
                'label':
                '%s S%02dE%02d' %
                (tvshowtitle, int(i['season']), int(i['episode'])),
                'season':
                int('%01d' % int(i['season'])),
                'episode':
                int('%01d' % int(i['episode'])),
                'unaired':
                i['unaired']
            } for i in items]

            for i in range(len(items)):
                if control.monitor.abortRequested(): return sys.exit()

                dialog.update(int((100 / float(len(items))) * i), str(name),
                              str(items[i]['label']))

                _season, _episode, unaired = items[i]['season'], items[i][
                    'episode'], items[i]['unaired']
                if int(watched) == 7:
                    if not unaired == 'true':
                        bookmarks.reset(1, 1, 'episode', imdb, _season,
                                        _episode)
                    else:
                        pass
                else:
                    bookmarks._delete_record('episode', imdb, _season,
                                             _episode)

        else:
            seasons = episodes.seasons().get(tvshowtitle,
                                             '0',
                                             imdb,
                                             tmdb,
                                             meta=None,
                                             idx=False)
            seasons = [i['season'] for i in seasons]
            #log_utils.log('playcount_seasons: ' + str(seasons))
            for s in seasons:
                items = episodes.episodes().get(tvshowtitle,
                                                '0',
                                                imdb,
                                                tmdb,
                                                meta=None,
                                                season=s,
                                                idx=False)
                items = [{
                    'label':
                    '%s S%02dE%02d' %
                    (tvshowtitle, int(i['season']), int(i['episode'])),
                    'season':
                    int('%01d' % int(i['season'])),
                    'episode':
                    int('%01d' % int(i['episode'])),
                    'unaired':
                    i['unaired']
                } for i in items]
                #log_utils.log('playcount_items2: ' + str(items))

                for i in range(len(items)):
                    if control.monitor.abortRequested(): return sys.exit()

                    dialog.update(int((100 / float(len(items))) * i),
                                  str(name), str(items[i]['label']))

                    _season, _episode, unaired = items[i]['season'], items[i][
                        'episode'], items[i]['unaired']
                    if int(watched) == 7:
                        if not unaired == 'true':
                            bookmarks.reset(1, 1, 'episode', imdb, _season,
                                            _episode)
                        else:
                            pass
                    else:
                        bookmarks._delete_record('episode', imdb, _season,
                                                 _episode)

        try:
            dialog.close()
        except:
            pass
    except:
        log_utils.log('playcount_local_shows', 1)
        try:
            dialog.close()
        except:
            pass

    try:
        if trakt.getTraktIndicatorsInfo() == False: raise Exception()

        #log_utils.log('playcount_season: ' + str(season))
        if season:
            from resources.lib.indexers import episodes
            items = episodes.episodes().get(tvshowtitle,
                                            '0',
                                            imdb,
                                            tmdb,
                                            meta=None,
                                            season=season,
                                            idx=False)
            items = [(int(i['season']), int(i['episode'])) for i in items]
            items = [
                i[1] for i in items
                if int('%01d' % int(season)) == int('%01d' % i[0])
            ]
            for i in items:
                if int(watched) == 7:
                    trakt.markEpisodeAsWatched(imdb, season, i)
                else:
                    trakt.markEpisodeAsNotWatched(imdb, season, i)
        else:
            if int(watched) == 7: trakt.markTVShowAsWatched(imdb)
            else: trakt.markTVShowAsNotWatched(imdb)
        trakt.cachesyncTVShows()
    except:
        log_utils.log('playcount_trakt_shows', 1)
        pass

    control.refresh()
    control.idle()
elif action == 'play_library'          : sources().play_library(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, meta, select)
elif action == 'playItem'              : sources().playItem(title, source)
elif action == 'queueItem'             : control.queueItem()
elif action == 'rdAuthorize'           : debrid.rdAuthorize()
elif action == 'refresh'               : control.refresh()
elif action == 'restorewatchlist':
        zipdir = control.setting('remote_restore_path')
        if not zipdir == '':
                with zipfile.ZipFile(zipdir, "r") as z:
                        z.extractall(datapath)
                        dialog.ok('Restore Watchlist', 'Restore complete', '', '')
        else:
                dialog.ok('Restore Watchlist', 'No item found: Please select your zipfile location in the addon settings', '', '')
                xbmc.executebuiltin('RunPlugin(%s?action=openSettings&query=7.1)' % sys.argv[0])
elif action == 'searchNavigator'       : navigator.navigator().search()
elif action == 'seasons'               : episodes.seasons().get(tvshowtitle, year, imdb, tvdb)
elif action == 'ShowChangelog'         : changelog.get()
elif action == 'showsProgress'         : episodes.episodes().in_progress()
elif action == 'similar_movies'        : movies.movies().similar_movies(imdb)
elif action == 'similar_shows'         : tvshows.tvshows().similar_shows(imdb)
elif action == 'soullessliteNavigator' : navigator.navigator().soulless(lite=True)
elif action == 'soullessNavigator'     : navigator.navigator().soulless()
elif action == 'toolNavigator'         : navigator.navigator().tools()
elif action == 'trailer'               : trailer.trailer().play(name, url)
elif action == 'traktManager':
    from resources.lib.modules import trakt
    trakt.manager(name, imdb, tvdb, content)
elif action == 'authTrakt':
    from resources.lib.modules import trakt
    trakt.authTrakt()
elif action == 'tvCertificates'        : tvshows.tvshows().certifications()
Esempio n. 9
0
def routing(_argv):

    params = dict(urllib_parse.parse_qsl(_argv.replace('?', '')))

    action = params.get('action')

    name = params.get('name')

    title = params.get('title')

    year = params.get('year')

    imdb = params.get('imdb')

    tvdb = params.get('tvdb')

    tmdb = params.get('tmdb')

    season = params.get('season')

    episode = params.get('episode')

    tvshowtitle = params.get('tvshowtitle')

    premiered = params.get('premiered')

    url = params.get('url')

    image = params.get('image')

    meta = params.get('meta')

    select = params.get('select')

    query = params.get('query')

    source = params.get('source')

    content = params.get('content')

    status = params.get('status')

    rtype = params.get('rtype')

    windowedtrailer = params.get('windowedtrailer')
    windowedtrailer = int(windowedtrailer) if windowedtrailer in ('0',
                                                                  '1') else 0

    if action == None:
        from resources.lib.indexers import navigator
        from resources.lib.modules import cache
        cache.cache_version_check()
        navigator.navigator().root()

    elif action == 'furkNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().furk()

    elif action == 'furkMetaSearch':
        from resources.lib.indexers import furk
        furk.furk().furk_meta_search(url)

    elif action == 'furkSearch':
        from resources.lib.indexers import furk
        furk.furk().search()

    elif action == 'furkUserFiles':
        from resources.lib.indexers import furk
        furk.furk().user_files()

    elif action == 'furkSearchNew':
        from resources.lib.indexers import furk
        furk.furk().search_new()

    elif action == 'movieNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().movies()

    elif action == 'movieliteNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().movies(lite=True)

    elif action == 'mymovieNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().mymovies()

    elif action == 'mymovieliteNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().mymovies(lite=True)

    elif action == 'tvNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().tvshows()

    elif action == 'tvliteNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().tvshows(lite=True)

    elif action == 'mytvNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().mytvshows()

    elif action == 'mytvliteNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().mytvshows(lite=True)

    elif action == 'downloadNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().downloads()

    elif action == 'libraryNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().library()

    elif action == 'toolNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().tools()

    elif action == 'searchNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().search()

    elif action == 'viewsNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().views()

    elif action == 'cacheNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().cache_functions()

    elif action == 'logNavigator':
        from resources.lib.indexers import navigator
        navigator.navigator().log_functions()

    elif action == 'clearCache':
        from resources.lib.indexers import navigator
        navigator.navigator().clearCache()

    elif action == 'clearCacheProviders':
        from resources.lib.indexers import navigator
        navigator.navigator().clearCacheProviders()

    elif action == 'clearDebridCheck':
        from resources.lib.indexers import navigator
        navigator.navigator().clearDebridCheck()

    elif action == 'clearCacheSearch':
        from resources.lib.indexers import navigator
        navigator.navigator().clearCacheSearch(select)

    elif action == 'clearAllCache':
        from resources.lib.indexers import navigator
        navigator.navigator().clearCacheAll()

    elif action == 'infoCheck':
        from resources.lib.indexers import navigator
        navigator.navigator().infoCheck('')

    elif action == 'uploadLog':
        from resources.lib.indexers import navigator
        navigator.navigator().uploadLog()

    elif action == 'emptyLog':
        from resources.lib.indexers import navigator
        navigator.navigator().emptyLog()

    elif action == 'viewLog':
        from resources.lib.modules import log_utils
        log_utils.view_log()

    elif action == 'movies':
        from resources.lib.indexers import movies
        movies.movies().get(url)

    elif action == 'moviePage':
        from resources.lib.indexers import movies
        movies.movies().get(url)

    elif action == 'movieWidget':
        from resources.lib.indexers import movies
        movies.movies().widget()

    elif action == 'movieSearch':
        from resources.lib.indexers import movies
        movies.movies().search()

    elif action == 'movieSearchnew':
        from resources.lib.indexers import movies
        movies.movies().search_new()

    elif action == 'movieSearchterm':
        from resources.lib.indexers import movies
        movies.movies().search_term(name)

    elif action == 'movieMosts':
        from resources.lib.indexers import movies
        movies.movies().mosts()

    elif action == 'movieGenres':
        from resources.lib.indexers import movies
        movies.movies().genres()

    elif action == 'movieLanguages':
        from resources.lib.indexers import movies
        movies.movies().languages()

    elif action == 'movieCertificates':
        from resources.lib.indexers import movies
        movies.movies().certifications()

    elif action == 'movieYears':
        from resources.lib.indexers import movies
        movies.movies().years()

    elif action == 'movieDecades':
        from resources.lib.indexers import movies
        movies.movies().decades()

    elif action == 'movieKeywords':
        from resources.lib.indexers import movies
        movies.movies().keywords()

    elif action == 'movieKeywords2':
        from resources.lib.indexers import movies
        movies.movies().keywords2()

    elif action == 'movieCustomLists':
        from resources.lib.indexers import movies
        movies.movies().custom_lists()

    elif action == 'movieUserlists':
        from resources.lib.indexers import movies
        movies.movies().userlists()

    elif action == 'channels':
        from resources.lib.indexers import channels
        channels.channels().get()

    elif action == 'tvshows':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().get(url)

    elif action == 'tvshowPage':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().get(url)

    elif action == 'tvSearch':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().search()

    elif action == 'tvSearchnew':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().search_new()

    elif action == 'tvSearchterm':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().search_term(name)

    elif action == 'tvMosts':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().mosts()

    elif action == 'tvGenres':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().genres()

    elif action == 'tvNetworks':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().networks()

    elif action == 'tvLanguages':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().languages()

    elif action == 'tvCertificates':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().certifications()

    elif action == 'tvUserlists':
        from resources.lib.indexers import tvshows
        tvshows.tvshows().userlists()

    elif action == 'peopleSearch':
        from resources.lib.indexers import people
        people.People().search(content)

    elif action == 'peopleSearchnew':
        from resources.lib.indexers import people
        people.People().search_new(content)

    elif action == 'peopleSearchterm':
        from resources.lib.indexers import people
        people.People().search_term(name, content)

    elif action == 'persons':
        from resources.lib.indexers import people
        people.People().persons(url, content)

    elif action == 'moviePerson':
        from resources.lib.indexers import people
        people.People().persons(url, content='movies')

    elif action == 'tvPerson':
        from resources.lib.indexers import people
        people.People().persons(url, content='tvshows')

    elif action == 'personsSelect':
        from resources.lib.indexers import people
        people.People().getPeople(name, url)

    elif action == 'seasons':
        from resources.lib.indexers import episodes
        episodes.seasons().get(tvshowtitle, year, imdb, tmdb, meta)

    elif action == 'episodes':
        from resources.lib.indexers import episodes
        episodes.episodes().get(tvshowtitle, year, imdb, tmdb, meta, season,
                                episode)

    elif action == 'calendar':
        from resources.lib.indexers import episodes
        episodes.episodes().calendar(url)

    elif action == 'tvWidget':
        from resources.lib.indexers import episodes
        episodes.episodes().widget()

    elif action == 'calendars':
        from resources.lib.indexers import episodes
        episodes.episodes().calendars()

    elif action == 'episodeUserlists':
        from resources.lib.indexers import episodes
        episodes.episodes().userlists()

    elif action == 'refresh':
        from resources.lib.modules import control
        control.refresh()

    elif action == 'queueItem':
        from resources.lib.modules import control
        control.queueItem()

    elif action == 'openSettings':
        from resources.lib.modules import control
        control.openSettings(query)

    elif action == 'artwork':
        from resources.lib.modules import control
        control.artwork()

    elif action == 'addView':
        from resources.lib.modules import views
        views.addView(content)

    elif action == 'moviePlaycount':
        from resources.lib.modules import playcount
        playcount.movies(imdb, query)

    elif action == 'episodePlaycount':
        from resources.lib.modules import playcount
        playcount.episodes(imdb, tmdb, season, episode, query)

    elif action == 'tvPlaycount':
        from resources.lib.modules import playcount
        playcount.tvshows(name, imdb, tmdb, season, query)

    elif action == 'yt_trailer':
        from resources.lib.modules import control, trailer
        if not control.condVisibility('System.HasAddon(plugin.video.youtube)'):
            control.installAddon('plugin.video.youtube')
        trailer.YT_trailer().play(name, url, tmdb, imdb, season, episode,
                                  windowedtrailer)

    elif action == 'tmdb_trailer':
        from resources.lib.modules import control, trailer
        if not control.condVisibility('System.HasAddon(plugin.video.youtube)'):
            control.installAddon('plugin.video.youtube')
        trailer.TMDb_trailer().play(tmdb, imdb, season, episode,
                                    windowedtrailer)

    elif action == 'imdb_trailer':
        from resources.lib.modules import trailer
        trailer.IMDb_trailer().play(imdb, name, tmdb, season, episode,
                                    windowedtrailer)

    elif action == 'traktManager':
        from resources.lib.modules import trakt
        trakt.manager(name, imdb, tmdb, content)

    elif action == 'authTrakt':
        from resources.lib.modules import trakt
        trakt.authTrakt()

    elif action == 'smuSettings':
        try:
            import resolveurl
            resolveurl.display_settings()
        except:
            pass

    elif action == 'oathscrapersettings':
        from resources.lib.modules import control
        control.openSettings('0.0', 'script.module.oathscrapers')

    elif action == 'installOrion':
        from resources.lib.modules import control
        control.installAddon('script.module.orion')
        control.sleep(200)
        control.refresh()

    elif action == 'orionsettings':
        from resources.lib.modules import control
        control.openSettings('0.0', 'script.module.orion')

    elif action == 'download':
        import simplejson as json
        from resources.lib.modules import sources
        from resources.lib.modules import downloader
        try:
            downloader.download(
                name, image,
                sources.sources().sourcesResolve(json.loads(source)[0], True))
        except:
            pass

    elif action == 'play':
        from resources.lib.modules import control
        control.busy()
        from resources.lib.modules import sources
        sources.sources().play(title,
                               year,
                               imdb,
                               tmdb,
                               season,
                               episode,
                               tvshowtitle,
                               premiered,
                               meta,
                               select,
                               unfiltered=False)

    elif action == 'playUnfiltered':
        from resources.lib.modules import control
        control.busy()
        from resources.lib.modules import sources
        sources.sources().play(title,
                               year,
                               imdb,
                               tmdb,
                               season,
                               episode,
                               tvshowtitle,
                               premiered,
                               meta,
                               select,
                               unfiltered=True)

    elif action == 'addItem':
        from resources.lib.modules import sources
        sources.sources().addItem(title)

    elif action == 'playItem':
        from resources.lib.modules import sources
        sources.sources().playItem(title, source)

    elif action == 'alterSources':
        from resources.lib.modules import sources
        sources.sources().alterSources(url, meta)

    elif action == 'clearSources':
        from resources.lib.modules import sources
        sources.sources().clearSources()

    elif action == 'random':
        from sys import argv
        if rtype == 'movie':
            from resources.lib.indexers import movies
            rlist = movies.movies().get(url, create_directory=False)
            r = argv[0] + '?action=play'
        elif rtype == 'episode':
            from resources.lib.indexers import episodes
            rlist = episodes.episodes().get(tvshowtitle,
                                            year,
                                            imdb,
                                            tmdb,
                                            meta,
                                            season,
                                            create_directory=False)
            r = argv[0] + '?action=play'
        elif rtype == 'season':
            from resources.lib.indexers import episodes
            rlist = episodes.seasons().get(tvshowtitle,
                                           year,
                                           imdb,
                                           tmdb,
                                           None,
                                           create_directory=False)
            r = argv[0] + '?action=random&rtype=episode'
        elif rtype == 'show':
            from resources.lib.indexers import tvshows
            rlist = tvshows.tvshows().get(url, create_directory=False)
            r = argv[0] + '?action=random&rtype=season'
        from random import randint
        import simplejson as json
        try:
            from resources.lib.modules import control
            rand = randint(1, len(rlist)) - 1
            for p in [
                    'title', 'year', 'imdb', 'tmdb', 'season', 'episode',
                    'tvshowtitle', 'premiered', 'select'
            ]:
                if rtype == 'show' and p == 'tvshowtitle':
                    try:
                        r += '&' + p + '=' + urllib_parse.quote_plus(
                            rlist[rand]['title'])
                    except:
                        pass
                else:
                    if rtype == 'movie':
                        rlist[rand]['title'] = rlist[rand]['originaltitle']
                    elif rtype == 'episode':
                        rlist[rand]['tvshowtitle'] = urllib_parse.unquote_plus(
                            rlist[rand]['tvshowtitle'])
                    try:
                        r += '&' + p + '=' + urllib_parse.quote_plus(
                            rlist[rand][p])
                    except:
                        pass
            try:
                r += '&meta=' + urllib_parse.quote_plus(json.dumps(
                    rlist[rand]))
            except:
                r += '&meta={}'
            if rtype == 'movie':
                try:
                    control.infoDialog(
                        '%s (%s)' %
                        (rlist[rand]['title'], rlist[rand]['year']),
                        control.lang(32536),
                        time=20000)
                except:
                    pass
            elif rtype == 'episode':
                try:
                    control.infoDialog(
                        '%s - %01dx%02d . %s' %
                        (urllib_parse.unquote_plus(rlist[rand]['tvshowtitle']),
                         int(rlist[rand]['season']), int(
                             rlist[rand]['episode']), rlist[rand]['title']),
                        control.lang(32536),
                        time=20000)
                except:
                    pass
            control.execute('RunPlugin(%s)' % r)
        except:
            from resources.lib.modules import control
            control.infoDialog(control.lang(32537), time=8000)

    elif action == 'movieToLibrary':
        from resources.lib.modules import libtools
        libtools.libmovies().add(name, title, year, imdb, tmdb)

    elif action == 'moviesToLibrary':
        from resources.lib.modules import libtools
        libtools.libmovies().range(url)

    elif action == 'moviesToLibrarySilent':
        from resources.lib.modules import libtools
        libtools.libmovies().silent(url)

    elif action == 'tvshowToLibrary':
        from resources.lib.modules import libtools
        libtools.libtvshows().add(tvshowtitle, year, imdb, tmdb)

    elif action == 'tvshowsToLibrary':
        from resources.lib.modules import libtools
        libtools.libtvshows().range(url)

    elif action == 'tvshowsToLibrarySilent':
        from resources.lib.modules import libtools
        libtools.libtvshows().silent(url)

    elif action == 'updateLibrary':
        from resources.lib.modules import libtools
        libtools.libepisodes().update(query)

    elif action == 'service':
        from resources.lib.modules import libtools
        libtools.libepisodes().service()

    elif action == 'syncTraktStatus':
        from resources.lib.modules import trakt
        trakt.syncTraktStatus()

    elif action == 'changelog':
        from resources.lib.modules import changelog
        changelog.get()

    elif action == 'cleanSettings':
        from resources.lib.modules import control
        control.clean_settings()

    elif action == 'tvcredits':
        from resources.lib.modules import credits
        credits.Credits().get_tv(tmdb, status)

    elif action == 'moviecredits':
        from resources.lib.modules import credits
        credits.Credits().get_movies(tmdb, status)
Esempio n. 10
0
    def update(self, query=None, info='true'):
        if not query == None: control.idle()

        try:

            items = []
            season, episode = [], []
            show = [
                os.path.join(self.library_folder, i)
                for i in control.listDir(self.library_folder)[0]
            ]
            for s in show:
                try:
                    season += [
                        os.path.join(s, i) for i in control.listDir(s)[0]
                    ]
                except:
                    pass
            for s in season:
                try:
                    episode.append([
                        os.path.join(s, i) for i in control.listDir(s)[1]
                        if i.endswith('.strm')
                    ][-1])
                except:
                    pass

            for file in episode:
                try:
                    file = control.openFile(file)
                    read = file.read()
                    read = six.ensure_str(read)
                    file.close()

                    if not read.startswith(sys.argv[0]): raise Exception()

                    params = dict(urllib_parse.parse_qsl(read.replace('?',
                                                                      '')))

                    try:
                        tvshowtitle = params['tvshowtitle']
                    except:
                        tvshowtitle = None
                    try:
                        tvshowtitle = params['show']
                    except:
                        pass
                    if tvshowtitle == None or tvshowtitle == '':
                        raise Exception()

                    year, imdb, tmdb = params['year'], params[
                        'imdb'], params.get('tmdb', '0')

                    imdb = 'tt' + re.sub('[^0-9]', '', str(imdb))

                    items.append({
                        'tvshowtitle': tvshowtitle,
                        'year': year,
                        'imdb': imdb,
                        'tmdb': tmdb
                    })
                except:
                    log_utils.log('lib_ep_upd0', 1)
                    pass

            items = [i for x, i in enumerate(items) if i not in items[x + 1:]]
            if len(items) == 0: raise Exception()
        except:
            log_utils.log('lib_ep_upd1', 1)
            return

        try:
            lib = control.jsonrpc(
                '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}'
            )
            lib = six.ensure_text(lib, errors='ignore')
            lib = json.loads(lib)['result']['tvshows']
        except:
            return

        if info == 'true' and not control.condVisibility(
                'Window.IsVisible(infodialog)') and not control.condVisibility(
                    'Player.HasVideo'):
            control.infoDialog(control.lang(32553), time=10000000)
            self.infoDialog = True

        try:
            control.makeFile(control.dataPath)
            dbcon = database.connect(control.libcacheFile)
            dbcur = dbcon.cursor()
            dbcur.execute("CREATE TABLE IF NOT EXISTS tvshows ("
                          "id TEXT, "
                          "items TEXT, "
                          "UNIQUE(id)"
                          ");")
        except:
            #log_utils.log('lib_ep_upd2', 1)
            return

        try:
            from resources.lib.indexers import episodes
        except:
            return

        files_added = 0

        # __init__ doesn't get called from services so self.date never gets updated and new episodes are not added to the library
        self.datetime = datetime.datetime.utcnow()
        if control.setting('library.importdelay') != 'true':
            self.date = self.datetime.strftime('%Y%m%d')
        else:
            self.date = (self.datetime -
                         datetime.timedelta(hours=24)).strftime('%Y%m%d')

        for item in items:
            it = None

            if control.monitor.abortRequested(): return sys.exit()

            try:
                dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" %
                              item['imdb'])
                fetch = dbcur.fetchone()
                it = eval(six.ensure_str(fetch[1]))
            except:
                pass

            try:
                if not it == None: raise Exception()

                seasons = episodes.seasons().get(item['tvshowtitle'],
                                                 item['year'],
                                                 item['imdb'],
                                                 item['tmdb'],
                                                 meta=None,
                                                 idx=False)
                season = [i['season'] for i in seasons]
                for s in season:
                    #log_utils.log('lib_seasons: ' + str(s))
                    it = episodes.episodes().get(item['tvshowtitle'],
                                                 item['year'],
                                                 item['imdb'],
                                                 item['tmdb'],
                                                 meta=None,
                                                 season=s,
                                                 idx=False)
                    #log_utils.log('lib_it: ' + str(it))

                    status = seasons[0]['status'].lower()

                    it = [{
                        'title': i['title'],
                        'year': i['year'],
                        'imdb': i['imdb'],
                        'tmdb': i['tmdb'],
                        'season': i['season'],
                        'episode': i['episode'],
                        'tvshowtitle': i['tvshowtitle'],
                        'premiered': i['premiered']
                    } for i in it]

                if status in ['continuing', 'returning series']:
                    raise Exception()
                dbcur.execute("INSERT INTO tvshows Values (?, ?)",
                              (item['imdb'], repr(it)))
                dbcon.commit()
            except:
                #log_utils.log('lib_ep_upd3', 1)
                pass

            try:
                id = [item['imdb'], item['tmdb']]

                ep = [
                    six.ensure_str(x['title']) for x in lib
                    if str(x['imdbnumber']) in id or (
                        six.ensure_str(x['title']) == item['tvshowtitle']
                        and str(x['year']) == item['year'])
                ][0]
                ep = control.jsonrpc(
                    '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}'
                    % ep)
                #if six.PY2: ep = unicode(ep, 'utf-8', errors='ignore')
                ep = json.loads(ep).get('result', {}).get('episodes', {})
                ep = [{
                    'season': int(i['season']),
                    'episode': int(i['episode'])
                } for i in ep]
                ep = sorted(ep, key=lambda x: (x['season'], x['episode']))[-1]
                #log_utils.log('lib_ep: ' + str(ep))

                num = [
                    x for x, y in enumerate(it)
                    if str(y['season']) == str(ep['season'])
                    and str(y['episode']) == str(ep['episode'])
                ][-1]
                it = [y for x, y in enumerate(it) if x > num]
                #log_utils.log('lib_it: ' + str(it))
                if len(it) == 0: continue
            except:
                #log_utils.log('lib_ep_upd4', 1)
                continue

            for i in it:
                try:
                    if control.monitor.abortRequested(): return sys.exit()

                    premiered = i.get('premiered', '0')
                    #log_utils.log('date: ' + repr(self.date) + ' - premiered: ' + repr(premiered) + ' - tvshowtitle: ' + repr(i.get('tvshowtitle', '')))
                    if (premiered != '0'
                            and int(re.sub('[^0-9]', '', premiered)) > int(
                                self.date)) or (premiered == '0'
                                                and not self.include_unknown):
                        continue

                    if i.get('season'
                             ) == '0' and self.include_special == 'false':
                        continue

                    libtvshows().strmFile(i)
                    files_added += 1
                except:
                    log_utils.log('lib_ep_upd5', 1)
                    pass

        if self.infoDialog == True:
            control.infoDialog(control.lang(32554), time=1)

        if self.library_setting == 'true' and not control.condVisibility(
                'Library.IsScanningVideo') and files_added > 0:
            control.execute('UpdateLibrary(video)')
Esempio n. 11
0
    def add(self, tvshowtitle, year, imdb, tmdb, range=False):
        try:
            if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo')\
                    and self.silentDialog is False:
                control.infoDialog(control.lang(32552), time=10000000)
                self.infoDialog = True

            from resources.lib.indexers import episodes
            seasons = episodes.seasons().get(tvshowtitle,
                                             year,
                                             imdb,
                                             tmdb,
                                             meta=None,
                                             idx=False)
            seasons = [i['season'] for i in seasons]
            for s in seasons:
                items = episodes.episodes().get(tvshowtitle,
                                                year,
                                                imdb,
                                                tmdb,
                                                meta=None,
                                                season=s,
                                                idx=False)

                try:
                    items = [{
                        'title': i['title'],
                        'year': i['year'],
                        'imdb': i['imdb'],
                        'tvdb': i['tvdb'],
                        'tmdb': i['tmdb'],
                        'season': i['season'],
                        'episode': i['episode'],
                        'tvshowtitle': i['tvshowtitle'],
                        'premiered': i['premiered']
                    } for i in items]
                except:
                    items = []

                try:
                    if not self.dupe_setting == 'true': raise Exception()
                    if items == []: raise Exception()

                    id = [items[0]['imdb'], items[0]['tmdb']]

                    lib = control.jsonrpc(
                        '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}'
                    )
                    lib = six.ensure_text(lib, errors='ignore')
                    lib = json.loads(lib)['result']['tvshows']
                    lib = [
                        six.ensure_str(i['title']) for i in lib
                        if str(i['imdbnumber']) in id or
                        (six.ensure_str(i['title']) == items[0]['tvshowtitle']
                         and str(i['year']) == items[0]['year'])
                    ][0]

                    lib = control.jsonrpc(
                        '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}'
                        % lib)
                    lib = six.ensure_text(lib, errors='ignore')
                    lib = json.loads(lib)['result']['episodes']
                    lib = [
                        'S%02dE%02d' % (int(i['season']), int(i['episode']))
                        for i in lib
                    ]

                    items = [
                        i for i in items if not 'S%02dE%02d' %
                        (int(i['season']), int(i['episode'])) in lib
                    ]

                    if self.include_special == 'false':
                        items = [
                            i for i in items if not str(i['season']) == '0'
                        ]
                except:
                    pass

                files_added = 0

                for i in items:
                    try:
                        if control.monitor.abortRequested(): return sys.exit()

                        # if self.check_setting == 'true':
                        # if i['episode'] == '1':
                        # self.block = True
                        # src = lib_tools.check_sources(i['title'], i['year'], i['imdb'], i['tvdb'], i['season'], i['episode'], i['tvshowtitle'], i['premiered'])
                        # if src: self.block = False
                        # if self.block == True: raise Exception()

                        premiered = i.get('premiered', '0')
                        if (premiered != '0'
                                and int(re.sub('[^0-9]', '', str(premiered))) >
                                int(self.date)) or (premiered == '0' and
                                                    not self.include_unknown):
                            continue

                        self.strmFile(i)
                        files_added += 1
                    except:
                        pass

            if range == True: return

            if self.infoDialog is True:
                control.infoDialog(control.lang(32554), time=1)

            if self.library_setting == 'true' and not control.condVisibility(
                    'Library.IsScanningVideo') and files_added > 0:
                control.execute('UpdateLibrary(video)')
        except:
            log_utils.log('lib_tv_add', 1)