Exemple #1
0
 def validate_password(self, field, value):
     if not value:
         return value
     try:
         MyPlexAccount.signin(self.fields.username.value, value)
         return value
     except Unauthorized:
         raise ValidationError('Invalid username or password.')
Exemple #2
0
 def validate_password(self, field, value):
     if not value:
         return value
     try:
         MyPlexAccount.signin(self.fields.username.value, value)
         return value
     except Unauthorized:
         raise ValidationError('Invalid username or password.')
def plexlogin():
    global plex
    from plexapi.myplex import MyPlexAccount
    from plexapi.server import PlexServer

    PLEXSERVERIP = "SERVERIPGOESHERE"  #plex server ip goes here.
    PLEXSERVERPORT = "32400"  #usually 32400, but if yours is different replace.
    baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
    #note: May need to add your local network as an network authorized without access to use the local access method.
    try:
        LOGGEDIN
    except Exception:
        try:

            plex = PlexServer(baseurl)
        except Exception:
            print("Local Fail. Trying cloud access.")
            #You will need to add your username, password, servername below if your local access fails.
            PLEXUN = "MYPLEXUN"
            PLEXPW = "MYPLEXPW"
            PLEXSVR = "PLEXSERVERNAME"

            user = MyPlexAccount.signin(PLEXUN, PLEXPW)

            plex = user.resource(PLEXSVR).connect()

        LOGGEDIN = "YES"
Exemple #4
0
 def __init__(self, opts):
     self.opts = opts  # command line options
     self.clsnames = [c for c in opts.clsnames.split(',')
                      if c]  # list of clsnames to report (blank=all)
     self.account = MyPlexAccount.signin()  # MyPlexAccount instance
     self.plex = PlexServer()  # PlexServer instance
     self.attrs = defaultdict(dict)  # Attrs result set
Exemple #5
0
def plex_account():
    from plexapi.myplex import MyPlexAccount
    username = test_username
    password = test_password
    assert username and password
    account = MyPlexAccount.signin(username, password)
    assert account
    return account
def fetch_server(args):
    if args.resource and args.username and args.password:
        log(0, 'Signing in as MyPlex account %s..' % args.username)
        account = MyPlexAccount.signin(args.username, args.password)
        log(0, 'Connecting to Plex server %s..' % args.resource)
        return account.resource(args.resource).connect(), account
    elif args.baseurl and args.token:
        log(0, 'Connecting to Plex server %s..' % args.baseurl)
        return server.PlexServer(args.baseurl, args.token), None
    return server.PlexServer(), None
Exemple #7
0
def fetch_plex_instance(pkmeter, username=None, password=None, host=None):
    username = username or pkmeter.config.get('plexserver', 'username', from_keyring=True)
    password = password or pkmeter.config.get('plexserver', 'password', from_keyring=True)
    host = host or pkmeter.config.get('plexserver', 'host', '')
    if username:
        log.info('Logging into MyPlex with user %s', username)
        user = MyPlexAccount.signin(username, password)
        return user.resource(host).connect()
    log.info('Connecting to Plex host: %s', host)
    return PlexServer(host)
Exemple #8
0
def fetch_server(args):
    if args.resource and args.username and args.password:
        log(0, 'Signing in as MyPlex account %s..' % args.username)
        account = MyPlexAccount.signin(args.username, args.password)
        log(0, 'Connecting to Plex server %s..' % args.resource)
        return account.resource(args.resource).connect(), account
    elif args.baseurl and args.token:
        log(0, 'Connecting to Plex server %s..' % args.baseurl)
        return server.PlexServer(args.baseurl, args.token), None
    return server.PlexServer(), None
Exemple #9
0
def fetch_plex_instance(pi_dash, username=None, password=None, host=None):
    username = username or pi_dash.config.get('plexserver', 'username', from_keyring=True)
    password = password or pi_dash.config.get('plexserver', 'password', from_keyring=True)
    host = host or pi_dash.config.get('plexserver', 'host', '')
    if username:
        log.info('Logging into MyPlex with user %s', username)
        user = MyPlexAccount.signin(username, password)
        log.info('Connecting to Plex host: %s', host)
        return user.resource(host).connect()
    log.info('Connecting to Plex host: %s', host)
    return PlexServer(host)
Exemple #10
0
def login():
    error = None
    if request.method == 'POST':
        try:
            account = MyPlexAccount.signin(request.form['username'], request.form['password'])
            session['username'] = account.username
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('show_entries'))
        except:
            print("Login failed")
            return render_template('login.html', error="Login Failed")
    return render_template('login.html', error=error)
Exemple #11
0
def plexlogin():
    global PLEXUN
    global PLEXSVR
    global PLEXCLIENT
    global plex
    global client
    global LOGGEDIN
    try:
        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXUN\'')
        PLEXUN = cur.fetchone()
        PLEXUN = PLEXUN[0]
        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXPW\'')
        PLEXPW = cur.fetchone()
        PLEXPW = PLEXPW[0]
        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSVR\'')
        PLEXSVR = cur.fetchone()
        PLEXSVR = PLEXSVR[0]
        cur.execute(
            'SELECT setting FROM settings WHERE item LIKE \'PLEXCLIENT\'')
        PLEXCLIENT = cur.fetchone()
        PLEXCLIENT = PLEXCLIENT[0]
        try:
            cur.execute(
                'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERIP\''
            )
            PLEXSERVERIP = cur.fetchone()
            PLEXSERVERIP = PLEXSERVERIP[0]
            cur.execute(
                'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERPORT\''
            )
            PLEXSERVERPORT = cur.fetchone()
            PLEXSERVERPORT = PLEXSERVERPORT[0]
        except Exception:
            print("Local Variables not set. Run setup to use local access.")
        from plexapi.myplex import MyPlexAccount
        try:
            LOGGEDIN
        except Exception:
            try:
                from plexapi.server import PlexServer
                baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
                plex = PlexServer(baseurl)
            except Exception:
                print("Local Fail. Trying cloud access.")
                user = MyPlexAccount.signin(PLEXUN, PLEXPW)
                plex = user.resource(PLEXSVR).connect()
            client = plex.client(PLEXCLIENT)
            LOGGEDIN = "YES"
    except IndexError:
        print(
            "Error getting necessary plex api variables. Run system_setup.py.")
Exemple #12
0
def playstatus():

    sql = sqlite3.connect(MYDB)
    cur = sql.cursor()
    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXUN\'')
    PLEXUN = cur.fetchone()
    PLEXUN = PLEXUN[0]

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXPW\'')
    PLEXPW = cur.fetchone()
    PLEXPW = PLEXPW[0]

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSVR\'')
    PLEXSVR = cur.fetchone()
    PLEXSVR = PLEXSVR[0]

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXCLIENT\'')
    PLEXCLIENT = cur.fetchone()
    PLEXCLIENT = PLEXCLIENT[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERIP\'')
    PLEXSERVERIP = cur.fetchone()
    PLEXSERVERIP = PLEXSERVERIP[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERPORT\'')
    PLEXSERVERPORT = cur.fetchone()
    PLEXSERVERPORT = PLEXSERVERPORT[0]

    from plexapi.myplex import MyPlexAccount
    try:
        from plexapi.server import PlexServer
        baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT

        plex = PlexServer(baseurl, token)
    except Exception:
        user = MyPlexAccount.signin(PLEXUN, PLEXPW)
        print("Local Fail. Trying cloud access.")

    plex = user.resource(PLEXSVR).connect()
    client = plex.client(PLEXCLIENT)

    pstatus = client.isPlayingMedia()
    sql.close()
    #print (pstatus)

    if pstatus is True:
        return ("Playing")
    else:
        return ("Stopped")
Exemple #13
0
 def __init__(self, config, audio):
     super(PlexBackend, self).__init__(audio=audio)
     self.config = config
     self.session = get_requests_session(proxy_config=config['proxy'],
                                         user_agent='%s/%s' % (mopidy_plex.Extension.dist_name,
                                                               mopidy_plex.__version__)
                                        )
     self.account = MyPlexAccount.signin(config['plex']['username'], config['plex']['password'])
     self.plex = self.account.resource(config['plex']['server']).connect()
     self.music = [s for s in self.plex.library.sections() if s.TYPE == MusicSection.TYPE][0]
     logger.debug('Found music section on plex server %s: %s', self.plex, self.music)
     self.uri_schemes = ['plex', ]
     self.library = PlexLibraryProvider(backend=self)
     self.playback = PlexPlaybackProvider(audio=audio, backend=self)
     self.playlists = PlexPlaylistsProvider(backend=self)
def get_servers_from_account():
    if SECRETS is None:
        return {}
    try:
        account = MyPlexAccount.signin(*SECRETS)
        account_servers = {
            resource.clientIdentifier: resource for resource in account.resources() if "server" in resource.provides
        }
        return account_servers
    except Unauthorized:
        LOGGER.error("Could not authorize your account with the given " "credentials.")
        return {}
    except BadRequest:
        LOGGER.error("Blabla")
        # TODO: retry
        return {}
Exemple #15
0
def runtests(args):
    # Get username and password from environment
    username = args.username or CONFIG.get('authentication.username')
    password = args.password or CONFIG.get('authentication.password')
    resource = args.resource or CONFIG.get('authentication.resource')
    # Register known tests
    for loader, name, ispkg in pkgutil.iter_modules(
        [dirname(abspath(__file__))]):
        if name.startswith('test_'):
            log(0, 'Registering tests from %s.py' % name)
            loader.find_module(name).load_module(name)
    # Create Account and Plex objects
    log(0, 'Logging into MyPlex as %s' % username)
    account = MyPlexAccount.signin(username, password)
    log(0, 'Signed into MyPlex as %s (%s)' % (account.username, account.email))
    if resource:
        plex = account.resource(resource).connect()
        log(0, 'Connected to PlexServer resource %s' % plex.friendlyName)
    else:
        plex = PlexServer(args.baseurl, args.token)
        log(0, 'Connected to PlexServer %s' % plex.friendlyName)
    log(0, '')
    # Run all specified tests
    tests = {'passed': 0, 'failed': 0}
    for test in itertests(args.query):
        starttime = time.time()
        log(0, test['name'], 'green')
        try:
            test['func'](account, plex)
            runtime = time.time() - starttime
            log(2, 'PASS! (runtime: %.3fs)' % runtime, 'blue')
            tests['passed'] += 1
        except Exception as err:
            errstr = str(err)
            errstr += '\n%s' % traceback.format_exc() if args.verbose else ''
            log(2, 'FAIL: %s' % errstr, 'red')
            tests['failed'] += 1
        log(0, '')
    # Log a final report
    log(0, 'Tests Run:    %s' % sum(tests.values()))
    log(0, 'Tests Passed: %s' % tests['passed'])
    if tests['failed']:
        log(0, 'Tests Failed: %s' % tests['failed'], 'red')
    if not tests['failed']:
        log(0, '')
        log(0, 'EVERYTHING OK!! :)')
    raise SystemExit(tests['failed'])
Exemple #16
0
    def __init__(self, name, plex_url, plex_user, plex_password, plex_server):
        """Initialize the sensor."""
        from plexapi.utils import NA
        from plexapi.myplex import MyPlexAccount
        from plexapi.server import PlexServer

        self._na_type = NA
        self._name = name
        self._state = 0
        self._now_playing = []

        if plex_user and plex_password:
            user = MyPlexAccount.signin(plex_user, plex_password)
            server = plex_server if plex_server else user.resources()[0].name
            self._server = user.resource(server).connect()
        else:
            self._server = PlexServer(plex_url)
Exemple #17
0
    def __init__(self, name, plex_url, plex_user, plex_password, plex_server):
        """Initialize the sensor."""
        from plexapi.utils import NA
        from plexapi.myplex import MyPlexAccount
        from plexapi.server import PlexServer

        self._na_type = NA
        self._name = name
        self._state = 0
        self._now_playing = []

        if plex_user and plex_password:
            user = MyPlexAccount.signin(plex_user, plex_password)
            server = plex_server if plex_server else user.resources()[0].name
            self._server = user.resource(server).connect()
        else:
            self._server = PlexServer(plex_url)

        self.update()
Exemple #18
0
 def __init__(self, config, audio):
     super(PlexBackend, self).__init__(audio=audio)
     self.config = config
     self.session = get_requests_session(
         proxy_config=config['proxy'],
         user_agent='%s/%s' %
         (mopidy_plex.Extension.dist_name, mopidy_plex.__version__))
     self.account = MyPlexAccount.signin(config['plex']['username'],
                                         config['plex']['password'])
     self.plex = self.account.resource(config['plex']['server']).connect()
     self.music = [
         s for s in self.plex.library.sections()
         if s.TYPE == MusicSection.TYPE
     ][0]
     logger.debug('Found music section on plex server %s: %s', self.plex,
                  self.music)
     self.uri_schemes = [
         'plex',
     ]
     self.library = PlexLibraryProvider(backend=self)
     self.playback = PlexPlaybackProvider(audio=audio, backend=self)
     self.playlists = PlexPlaylistsProvider(backend=self)
Exemple #19
0
plex_tv = ''

#Discord
client_code = ''
game_list = []

#TVDB.com
tvdb_code = ''

#SickBeard
sickbeard_url = ''
sickbeard_api = ''
#############################################################################

#Connect to Plex Server
account = MyPlexAccount.signin(plex_username,plex_password)
plex = account.resource(plex_servername).connect()

#Connect to TVDB API
db = api.TVDB(tvdb_code)

#Connect to the sqlite3 database
conn = sqlite3.connect('request.db')
c = conn.cursor()

#Create the sqlite3 Table
c.execute('''CREATE TABLE IF NOT EXISTS requests
                (request text not null, tvdbid integer not null)''')

#Create a constraint so dupes cannot be added
c.execute('''CREATE unique index IF NOT EXISTS request_tvdbid on requests (request, tvdbid)''')
Exemple #20
0
def plexlogin():
    global PLEXUN
    global PLEXSVR
    global PLEXCLIENT
    global plex
    global client
    try:

        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXUN\'')
        PLEXUN = cur.fetchone()
        PLEXUN = PLEXUN[0]

        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXPW\'')
        PLEXPW = cur.fetchone()
        PLEXPW = PLEXPW[0]

        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSVR\'')
        PLEXSVR = cur.fetchone()
        PLEXSVR = PLEXSVR[0]

        cur.execute(
            'SELECT setting FROM settings WHERE item LIKE \'PLEXCLIENT\'')
        PLEXCLIENT = cur.fetchone()
        PLEXCLIENT = PLEXCLIENT[0]

        try:
            cur.execute(
                'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERTOKEN\''
            )
            PLEXTOKEN = cur.fetchone()
            PLEXTOKEN = PLEXTOKEN[0]
        except TypeError:
            print(
                "Error getting server Token. Local Access will fail. Try running system_setup.py to correct."
            )

        cur.execute(
            'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERIP\'')
        PLEXSERVERIP = cur.fetchone()
        PLEXSERVERIP = PLEXSERVERIP[0]

        cur.execute(
            'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERPORT\'')
        PLEXSERVERPORT = cur.fetchone()
        PLEXSERVERPORT = PLEXSERVERPORT[0]

        from plexapi.myplex import MyPlexAccount

        try:
            from plexapi.server import PlexServer
            baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
            token = PLEXTOKEN
            plex = PlexServer(baseurl, token)
            #print ("using local access.")
        except Exception:
            print("Local Fail. Trying cloud access.")
            user = MyPlexAccount.signin(PLEXUN, PLEXPW)
            plex = user.resource(PLEXSVR).connect()
        client = plex.client(PLEXCLIENT)

    except TypeError:
        print(
            "Error getting necessary plex api variables. Run system_setup.py.")
Exemple #21
0
#!/usr/bin/env python2
import os, sys, datetime
from plexapi.server import PlexServer
from plexapi.myplex import MyPlexAccount

account = MyPlexAccount.signin('****', '*****')
#plex = PlexServer()
plex = account.resource('****').connect()

keep = []
simFiles = ['.srt', '.nfo', '.tbn', '.nzb', '.nfo-orig', '.sfv', '.srr', '.jpg', '.png', '.jpeg', '.txt', '.idx', '.sub']
kept=0
deleted=0
print '-----------------------------------------------'
print 'Running Plex Cleaner on '+datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
print ''

section = plex.library.section('TV Shows')
recentlyViewed = section.search(sort='lastViewedAt:desc', libtype='episode', maxresults=100)

for entry in recentlyViewed:
    tvFile = entry.media[0].parts[0].file
    if entry.grandparentTitle not in keep:
        if entry not in plex.library.onDeck():
        if os.path.isfile(tvFile):
                print 'Deleting '+entry.grandparentTitle+' - '+entry.title+' ::: '+tvFile
                deleted += 1
                os.remove(tvFile)
            for sim in simFiles:
                simFile = os.path.splitext(tvFile)[0]+sim
                if os.path.isfile(simFile):
    pass
else:
    cur.execute('DELETE FROM settings WHERE item LIKE \'PLEXPW\'')
    sql.commit()
    print(
        "Found Old stored password. Scrubbing from DB. You will be prompted for it, when needed, like now.\n"
    )

print(
    "Your Plex Password is needed to proceed. Note: This password is not stored, and if needed in the future you will be prompted for it."
)
PLEXPW = str(getpass.getpass('Plex Password: '))

from plexapi.myplex import MyPlexAccount

user = MyPlexAccount.signin(PLEXUN, PLEXPW)

print("\rSuccessfully Logged In.\n")

resces = user.resources()
servers = []
for item in resces:
    if "Plex Media Server" in item.product:
        servers.append(item.name)
server = worklist(servers)
for item in resces:
    if "Plex Media Server" in item.product:
        servers.append(item.name)
        if item.name == server:
            PLEXSVR = item.name
            PLEXSERVERIP = str(item.connections[0].address)
def playstatus():
    sql = sqlite3.connect(MYDB)
    cur = sql.cursor()

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSVR\'')
    PLEXSVR = cur.fetchone()
    PLEXSVR = PLEXSVR[0]

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXCLIENT\'')
    PLEXCLIENT = cur.fetchone()
    PLEXCLIENT = PLEXCLIENT[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERIP\'')
    PLEXSERVERIP = cur.fetchone()
    PLEXSERVERIP = PLEXSERVERIP[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERPORT\'')
    PLEXSERVERPORT = cur.fetchone()
    PLEXSERVERPORT = PLEXSERVERPORT[0]

    #cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERTOKEN\'')
    #PLEXSERVERTOKEN = cur.fetchone()
    #PLEXSERVERTOKEN = PLEXSERVERTOKEN[0]

    from plexapi.myplex import MyPlexAccount
    try:
        from plexapi.server import PlexServer
        baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
        #token = PLEXSERVERTOKEN

        #plex = PlexServer(baseurl, token)
        plex = PlexServer(baseurl)
    except Exception:
        cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXUN\'')
        PLEXUN = cur.fetchone()
        PLEXUN = PLEXUN[0]

        try:
            cur.execute(
                'SELECT setting FROM settings WHERE item LIKE \'PLEXPW\'')
            PLEXPW = cur.fetchone()
            PLEXPW = PLEXPW[0]
            import base64
            PLEXPW = str(base64.b64decode(PLEXPW))
        except Exception:
            print("Your Plex Password is temporarly needed to proceed:\n")
            PLEXPW = str(getpass.getpass("Password: "******"Local Fail. Trying cloud access.")
        plex = user.resource(PLEXSVR).connect()
    client = plex.client(PLEXCLIENT)

    pstatus = client.isPlayingMedia()
    sql.close()
    #print (pstatus)

    if pstatus is True:
        return ("Playing")
    else:
        return ("Stopped")
Exemple #24
0
def sessionstatus():
    sql = sqlite3.connect(MYDB)
    cur = sql.cursor()
    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXUN\'')
    PLEXUN = cur.fetchone()
    PLEXUN = str(PLEXUN[0]).strip()

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXPW\'')
    PLEXPW = cur.fetchone()
    PLEXPW = str(PLEXPW[0]).strip()

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXSVR\'')
    PLEXSVR = cur.fetchone()
    PLEXSVR = PLEXSVR[0]

    cur.execute('SELECT setting FROM settings WHERE item LIKE \'PLEXCLIENT\'')
    PLEXCLIENT = cur.fetchone()
    PLEXCLIENT = PLEXCLIENT[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERIP\'')
    PLEXSERVERIP = cur.fetchone()
    PLEXSERVERIP = PLEXSERVERIP[0]

    cur.execute(
        'SELECT setting FROM settings WHERE item LIKE \'PLEXSERVERPORT\'')
    PLEXSERVERPORT = cur.fetchone()
    PLEXSERVERPORT = PLEXSERVERPORT[0]

    from plexapi.myplex import MyPlexAccount
    try:
        from plexapi.server import PlexServer
        baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
        plex = PlexServer(baseurl)
        print("using local access.")
    except Exception:
        print("Local Fail. Trying cloud access.")
        user = MyPlexAccount.signin(PLEXUN, PLEXPW)
        plex = user.resource(PLEXSVR).connect()
    client = plex.client(PLEXCLIENT)
    psess = plex.sessions()
    if not psess:
        return ("Stopped")
    else:
        cur.execute(
            'SELECT State FROM States WHERE Option LIKE \'Nowplaying\'')
        nowp = cur.fetchone()
        nowp = nowp[0]
        if "TV Show:" in nowp:
            nowp = nowp.split("Episode: ")
            nowp = nowp[1]
        elif "Movie:" in nowp:
            nowp = nowp.split("Movie: ")
            nowp = nowp[1]
        for sess in psess:
            sess = sess.title

            if nowp in sess:
                #print ("Go")
                return ("Playing")
        print("Fail")
        return ("Unknown")