def __init__(self, username, client_id='', client_secret=''): self.username = username self.client_id = client_id self.client_secret = client_secret trakt.init(username, client_id=client_id, client_secret=client_secret) self.trakt = trakt self.trakt_core = trakt.core.Core()
def connectTrakt(): print("Trying (first) authentication, user input required ...") core.AUTH_METHOD = core.OAUTH_AUTH try: init(usernameTrakt, client_id=clientID, client_secret=clientSecret, store=True) return True except: return False
def sign_in(username: str, client_id: str = None, client_secret: str = None, application_id=None, stay_logged_in: bool = True, token_path: str = trakt.core.CONFIG_PATH): if application_id: trakt.APPLICATION_ID = application_id else: trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH get_stored_oauth_token(filename=token_path) if not trakt.core.OAUTH_TOKEN: if client_id and client_secret: trakt.init(username, client_id=client_id, client_secret=client_secret, store=stay_logged_in) else: trakt.init(username, store=stay_logged_in)
def main(): args = get_arguments() FORMAT = '%(asctime)-15s %(levelname)-7s %(name)-30s %(message)s' logging.basicConfig(format=FORMAT, level=logging.DEBUG) if not args.user: print('No username provided') sys.exit(1) if args.login: import trakt trakt.init(store=True) print('Login OK. Info stored in ~/.pytrakt.json') sys.exit(1) shows = get_trakt_tvlist(args.user, args.list) if len(shows) > 0: print('Trakt watchlist ({0} items):'.format(len(shows))) print(json.dumps(shows, sort_keys=True, indent=4))
def link_user(self, plex_username): account = {} account['plex_id'] = self.databases.get_plex_user_id(plex_username) account['plex_username'] = plex_username account['directory_tv'] = os.path.join(self.libraries_base_path, plex_username, 'tv') account['directory_movie'] = os.path.join(self.libraries_base_path, plex_username, 'movie') account['active'] = 1 account['trakt_username'] = input('Trakt.tv username: '******'trakt_username'], client_id=self.trakt_client_id, client_secret=self.trakt_client_secret) account['trakt_oauth'] = trakt.core.OAUTH_TOKEN account['trakt_client_id'] = trakt.core.CLIENT_ID account['trakt_client_secret'] = trakt.core.CLIENT_SECRET if self.databases.verify_tractastic_user_existance(plex_username): self.databases.update_traktastic_user(account) else: self.databases.create_traktastic_user(account)
continue try: token = account.user(name).get_token(plex.machineIdentifier) username = name break except: print("Impossible to find the managed user \'"+name+"\' on this server!") name = "_wrong" with open(env_file, 'w') as txt: txt.write("PLEX_USERNAME="******"\n") txt.write("PLEX_TOKEN=" + token + "\n") txt.write("PLEX_BASEURL=" + plex._baseurl + "\n") print("Plex token and baseurl for {} have been added in .env file:".format(username)) print("PLEX_TOKEN={}".format(token)) print("PLEX_BASEURL={}".format(plex._baseurl)) else: with open(env_file, "w") as txt: txt.write("PLEX_USERNAME=-\n") txt.write("PLEX_TOKEN=-\n") txt.write("PLEX_BASEURL=http://localhost:32400\n") trakt.core.AUTH_METHOD=trakt.core.DEVICE_AUTH print("-- Trakt --") client_id, client_secret = trakt.core._get_client_info() trakt.init(client_id=client_id, client_secret=client_secret, store=True) trakt_user = trakt.users.User('me') with open(env_file, "a") as txt: txt.write("TRAKT_USERNAME="******"\n") print("You are now logged into Trakt. Your Trakt credentials have been added in .env and .pytrakt.json files.") print("You can enjoy sync! \nCheck config.json to adjust settings.") print("If you want to change Plex or Trakt account, just edit or remove .env and .pytrakt.json files.")
from trakt import init import trakt.core import json from collections import OrderedDict def readJson(): json_data = open("vars.json").read() data = json.loads(json_data, object_pairs_hook=OrderedDict) return data #an OrderedDict settings = readJson() trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH my_client_id = settings['Trakt Settings']['client_id'] my_client_secret = settings['Trakt Settings']['secret_id'] init(settings['Users']["Smoothtalk"]['traktUserName'], client_id=my_client_id, client_secret=my_client_secret, store=True) #init("Smoothtalk", client_id='31dc283b13ac16dc6e6f31fccfa0bbdeafbdf2db089c555b7b90ac581fd02daa', client_secret='55e1a69191ed9fd1339f26c41d245be50bec0ce22362645f1180535c14a15f82', store=True)
#!/usr/bin/env python # Generates trakt api_key for authorising with trakt import json import trakt from trakt import init response = raw_input('Please type in your trakt username here: ') api_key = init(response) data = {'api_key': api_key} with open('trakt-config.json', 'w') as config_file: json.dump(data, config_file)
import json import trakt.core from trakt import init from collections import OrderedDict def readJson(): json_data = open("../vars.json").read() data = json.loads(json_data, object_pairs_hook=OrderedDict) return data #an OrderedDict settings = readJson() trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH my_client_id = settings['Trakt Settings']['client_id'] my_client_secret = settings['Trakt Settings']['secret_id'] for user in settings['Users']: if (settings['Users'][user]['traktUserName'] != ""): tracktUserName = settings['Users'][user]['traktUserName'] init(tracktUserName, client_id=my_client_id, client_secret=my_client_secret, store=True)
def auth(username: str) -> None: """Authenticate (or Re-authenticate) - only needs to be done once""" # https://pytrakt.readthedocs.io/en/latest/getstarted.html#oauth-auth # use OAuth and store credentials init(username, store=True)
import trakt from trakt.movies import Movie import sys trakt.init('laputa', client_id='cfe296e5568274da416c68b42577c7719c1236e66fa766bd4a9228c871f851c5', client_secret='68285158542c967a9158118e5dd8accdb45187b61849a1eb6f7ff0ed471241a0') class MovieTrakt: """ Get movie information from trakt api """ def get_trakt_info(self, eiga_movie): logging.debug('search trakt for movie %s', eiga_movie['title_jp']) original_title = eiga_movie['movie_data'].get('原題'.decode('utf8'), None) year = eiga_movie['movie_data'].get('製作年'.decode('utf8'), None) logging.debug('search trakt for movie [%s](%s)', original_title, year) if original_title is None: logging.warning('original title does not exist, skip get trakt info') return None else: if year is not None: year = year[:4] try: result = Movie.search(original_title, year) if len(result) > 0: return result[0] else: return None except TypeError as e:
imdblist = scrapeimdbrss(imdburl, scrapecount) moviecount += writeimdbtags(imdblist, Medialist, newimdbtag) scrapecount = scrapecount + 1 dialog = xbmcgui.Dialog() ok = dialog.ok("Tag Generator", _getstr(30081) + str(moviecount) + _getstr(30930)) sys.exit(_getstr(30076)) elif sys.argv[1] == "trakt_init": dialog = xbmcgui.Dialog() ok = dialog.ok("Tag Generator", _getstr(30923)) dialog = xbmcgui.Dialog() d = dialog.input(_getstr(30924)) if d: try: trakt_token = trakt.init(pin=d, client_id=trakt_client_id, client_secret=trakt_client_secret) __settings__.setSetting("32031", trakt_token) sys.exit(_getstr(30927)) except Exception, e: dialog = xbmcgui.Dialog() ok = dialog.ok("Tag Generator", _getstr(30925) + str(e.message)) sys.exit(_getstr(30927)) else: sys.exit(_getstr(30927)) elif sys.argv[1] == "trakt": if len(c_trakt_token) != 64: dialog = xbmcgui.Dialog() ok = dialog.ok("Tag Generator", _getstr(30925)) xbmc.log(msg=_getstr(30925), level=xbmc.LOGNOTICE)
from collections import OrderedDict from datetime import datetime as DT import datetime import tmdbsimple as tmdb from Objects import mySeason from extract_existing_files import scanPresentFiles, slugifyFolders import ConfigParser from time import sleep #------------------------------------ Init ------------------------------------- config = ConfigParser.ConfigParser() # reading config file config.read('config.ini') today = DT.now() trakt.AUTH_METHOD = trakt.OAUTH_AUTH init(config.get("trakt", "user"), config.get("trakt", "app_id"), config.get("trakt", "app_secret")) tmdb.API_KEY = config.get("tmdb", "api_key") myuser = users.User(config.get("tmdb", "user")) BASE_URL = config.get("main", "path") #--------------------------------------------------------------------------------- #slugify folders for more robust slugifyFolders(BASE_URL) print "Finished slugifying folders" def getWatchedEpisodes(myshow): """ getting watched episodes from trakt API :param myshow: which show
#!/usr/bin/env python3 # irbyjm 20180929 from sys import argv import trakt # make sure username is specified so it's not stored somewhere hard if len(argv) != 2: # dump if username not specified print("Usage: ./trakt_init.py [username]") else: # else go to town username = argv[1] # AUTH_METHOD defaults to PIN which has been deprecated trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH #information stored in ~/.pytrakt.json trakt.init(username, store=True)
def device_auth(client_id: str, client_secret: str): trakt.core.AUTH_METHOD = trakt.core.DEVICE_AUTH return trakt.init(client_id=client_id, client_secret=client_secret, store=True)
from plexapi.myplex import MyPlexAccount import utils import trakt import trakt.core plex_needed = utils.input_yesno( "Are you logged into this server with a Plex account?") if plex_needed: username = input("Please enter your Plex username: "******"Please enter your Plex password: "******"Now enter the server name: ") account = MyPlexAccount(username, password) plex = account.resource( servername).connect() # returns a PlexServer instance print("Copy this Plex token to the .env file:", plex._token) else: print("Add this as the PLEX_TOKEN in the .env file: PLEX_TOKEN=-") trakt.APPLICATION_ID = '65370' trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH trakt_user = input("Please input your Trakt username: "******"You are now logged into Trakt. Add your username in .env: TRAKT_USER="******"Once the PLEX_TOKEN and TRAKT_USER are in your .env file, you can run 'python3 main.py' and enjoy!" )
def start_trakt(user): trakt.core.AUTH_METHOD = trakt.core.OAUTH_AUTH trakt.init(user,client_id=my_client_id, client_secret=my_client_secret, store =True)