def run(): log.info("Running service") sync_trakt_episodes = addon.getSetting('sync_trakt_episodes') sync_trakt_watchlist = addon.getSetting('sync_trakt_watchlist') sync_imdb_watchlist = addon.getSetting('sync_imdb_watchlist') if sync_trakt_episodes: sync.trakt_syncEpisodes() if sync_trakt_watchlist: sync.trakt_syncWatchlist() if sync_imdb_watchlist: sync.imdb_syncWatchlist()
def request(self,url,data=None,retry=False,withToken=True): headers = { 'content-type': 'application/json', # 'trakt-api-key': '14b5146e25005b96c03cb8b125d7b5cb452e15e0cfe073685dc92992bbb707f9', # komakino 'trakt-api-key': 'd4161a7a106424551add171e5470112e4afdaf2438e6ef2fe0548edc75924868', # script.trakt # 'trakt-api-key': '90b2bb1a8203e81a0272fb8717fa8b19ec635d8568632e41d1fcf872a2a2d9d0', # stolen ;) 'trakt-api-version': '2' } if withToken: headers.update({ 'trakt-user-login': addon.getSetting("trakt_username"), 'trakt-user-token': self.token }) fullurl = 'https://api-v2launch.trakt.tv/%s' % url log.info("Requesting %s with headers %s" % (fullurl,headers)) req = urllib2.Request(fullurl,data,headers) req.add_header("User-Agent", USER_AGENT) try: response = urllib2.urlopen(req) except urllib2.HTTPError, e: log.error("http error: %s => %d %s" % (url, e.code, e.reason)) return {}
def generateLink(item): action = addon.getSetting('action') if item["type"] is 'show': return "plugin://plugin.video.pulsar/show/%s/season/%s/episode/%s/%s" % (item["id"],item["season"],item["episode"],action) elif item["type"] is 'movie': return "plugin://plugin.video.pulsar/movie/%s/%s" % (item["id"],action)
def requestToken(self): if self.token: return True username = addon.getSetting("trakt_username") password = addon.getSetting("trakt_password") data = """ { "login": "******", "password": "******" } """ % (username,password) response = self.request('auth/login',data=data,retry=True,withToken=False) if "token" in response and response["token"]: self.token = response["token"] return True else: self.token = None return False
def getWatchlist(self): response = self.request("/users/%s/watchlist/movies" % (addon.getSetting("trakt_username"))) result = [] for item in response: result.append({ "type": "movie", "id": item["movie"]["ids"]["imdb"], "title": item["movie"]["title"], "year": item["movie"]["year"], }) return result
def getWatchlist(): userid = addon.getSetting("imdb_userid") if not userid: return None url = "http://rss.imdb.com/user/%s/watchlist" % userid feed = feedparser.parse(url) if feed["status"] is not 200: xbmcgui.Dialog().notification('TraktorBeam','Could not retrieve watchlist. Make sure your watchlist is public!',icon=xbmcgui.NOTIFICATION_ERROR) return False return extractItems(feed.entries)
def createFile(item): typepath = addon.getSetting(item["type"] + '_folder') basepath = xbmc.translatePath(typepath) link = generateLink(item) nfoLink = generateNfoLink(item) item["title"] = clean_title(item["title"]) if item["type"] is 'show': item["episode_title"] = clean_title(item["episode_title"]) titleyear = '%s' % (item["title"]) folder = os.path.join(titleyear,'Season %s' % item["season"]) filename = 'S%02dE%02d' % (item["season"],item["episode"]) elif item["type"] is 'movie': titleyear = '%s (%s)' % (item["title"],item["year"]) folder = titleyear filename = titleyear folderpath = os.path.join(basepath,folder) filepath = os.path.join(basepath,folder,filename) scanpath = os.path.join(typepath) if not os.path.exists(folderpath): try: os.makedirs(folderpath) except: pass if not os.path.isfile(filepath + '.strm'): with open(filepath + '.strm', "w") as strm_file: # create .strm strm_file.write(link) log.info('File created: %s' % filename) with open(filepath + '.nfo', "w") as nfo_file: # create .strm nfo_file.write(nfoLink) log.info('File created: %s' % filename) log.info(item) log.info('Update path: %s' % scanpath) xbmc.executebuiltin('XBMC.UpdateLibrary(video,"%s")' % scanpath); return True else: return False
def getWatchlist(): userid = addon.getSetting("imdb_userid") if not userid: return None url = "http://rss.imdb.com/user/%s/watchlist" % userid feed = feedparser.parse(url) if feed["status"] is not 200: xbmcgui.Dialog().notification( 'TraktorBeam', 'Could not retrieve watchlist. Make sure your watchlist is public!', icon=xbmcgui.NOTIFICATION_ERROR) return False return extractItems(feed.entries)
import sys, os, xbmc sys.path.insert( 0, os.path.join(os.path.dirname(__file__), 'resources', 'site-packages')) from traktorbeam import service, log, addon if __name__ == '__main__': monitor = xbmc.Monitor() frequency = addon.getSetting("frequency") seconds = float(frequency) * 60 * 60 log.info("Starting service. Running every %s seconds" % seconds) while True: service.run() # Sleep/wait for abort if monitor.waitForAbort(seconds): # Abort was requested while waiting. We should exit log.info("Stopping service") break
import sys, os, xbmc sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'site-packages')) from traktorbeam import service, log, addon if __name__ == '__main__': monitor = xbmc.Monitor() frequency = addon.getSetting("frequency") seconds = float(frequency) * 60 * 60 log.info("Starting service. Running every %s seconds" % seconds) while True: service.run() # Sleep/wait for abort if monitor.waitForAbort(seconds): # Abort was requested while waiting. We should exit log.info("Stopping service") break