Loading registered devices...
diff --git a/plexpy/__init__.py b/plexpy/__init__.py
index a9844c65..f5f3fa46 100644
--- a/plexpy/__init__.py
+++ b/plexpy/__init__.py
@@ -745,7 +745,7 @@ def dbcheck():
c_db.execute(
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT, '
- 'last_seen INTEGER)'
+ 'last_seen INTEGER, official INTEGER DEFAULT 0)'
)
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
@@ -2001,6 +2001,19 @@ def dbcheck():
'ALTER TABLE mobile_devices ADD COLUMN last_seen INTEGER'
)
+ # Upgrade mobile_devices table from earlier versions
+ try:
+ c_db.execute('SELECT official FROM mobile_devices')
+ except sqlite3.OperationalError:
+ logger.debug("Altering database. Updating database table mobile_devices.")
+ c_db.execute(
+ 'ALTER TABLE mobile_devices ADD COLUMN official INTEGER DEFAULT 0'
+ )
+ # Update official mobile device flag
+ for device_id, in c_db.execute('SELECT device_id FROM mobile_devices').fetchall():
+ c_db.execute('UPDATE mobile_devices SET official = ? WHERE device_id = ?',
+ [mobile_app.validate_device_id(device_id), device_id])
+
# Upgrade notifiers table from earlier versions
try:
c_db.execute('SELECT custom_conditions FROM notifiers')
diff --git a/plexpy/api2.py b/plexpy/api2.py
index 37f31a8c..31c26960 100644
--- a/plexpy/api2.py
+++ b/plexpy/api2.py
@@ -416,11 +416,6 @@ class API2(object):
self._api_result_type = 'error'
return
- elif not notifiers.ANDROIDAPP().validate_device_id(device_id=device_id):
- self._api_msg = 'Device registration failed: invalid OneSignal Player ID.'
- self._api_result_type = 'error'
- return
-
result = mobile_app.add_mobile_device(device_id=device_id,
device_name=device_name,
device_token=self._api_apikey,
diff --git a/plexpy/mobile_app.py b/plexpy/mobile_app.py
index 3de44044..96494fff 100644
--- a/plexpy/mobile_app.py
+++ b/plexpy/mobile_app.py
@@ -18,6 +18,7 @@
from __future__ import unicode_literals
from future.builtins import str
+import requests
import threading
import plexpy
@@ -34,6 +35,8 @@ else:
TEMP_DEVICE_TOKEN = None
INVALIDATE_TIMER = None
+_ONESIGNAL_APP_ID = '3b4b666a-d557-4b92-acdf-e2c8c4b95357'
+
def set_temp_device_token(token=None):
global TEMP_DEVICE_TOKEN
@@ -84,7 +87,8 @@ def add_mobile_device(device_id=None, device_name=None, device_token=None, frien
keys = {'device_id': device_id}
values = {'device_name': device_name,
- 'device_token': device_token}
+ 'device_token': device_token,
+ 'official': validate_device_id(device_id=device_id)}
if friendly_name:
values['friendly_name'] = friendly_name
@@ -161,6 +165,14 @@ def set_last_seen(device_token=None):
return
+def validate_device_id(device_id):
+ headers = {'Content-Type': 'application/json'}
+ payload = {'app_id': _ONESIGNAL_APP_ID}
+
+ r = requests.get('https://onesignal.com/api/v1/players/{}'.format(device_id), headers=headers, json=payload)
+ return r.status_code == 200
+
+
def blacklist_logger():
devices = get_mobile_devices()
for d in devices:
diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py
index aa46a08e..dff085a6 100644
--- a/plexpy/notifiers.py
+++ b/plexpy/notifiers.py
@@ -882,16 +882,6 @@ class ANDROIDAPP(Notifier):
'priority': 3
}
- _ONESIGNAL_APP_ID = '3b4b666a-d557-4b92-acdf-e2c8c4b95357'
-
- def validate_device_id(self, device_id):
- headers = {'Content-Type': 'application/json'}
- payload = {'app_id': self._ONESIGNAL_APP_ID}
-
- r = requests.get('https://onesignal.com/api/v1/players/{}'.format(device_id), headers=headers, json=payload)
- if r.status_code == 200:
- return r.json()
-
def agent_notify(self, subject='', body='', action='', notification_id=None, **kwargs):
# Check mobile device is still registered
device = mobile_app.get_mobile_devices(device_id=self.config['device_id'])
@@ -938,7 +928,7 @@ class ANDROIDAPP(Notifier):
#logger.debug("Nonce (base64): {}".format(base64.b64encode(nonce)))
#logger.debug("Salt (base64): {}".format(base64.b64encode(salt)))
- payload = {'app_id': self._ONESIGNAL_APP_ID,
+ payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
'include_player_ids': [self.config['device_id']],
'contents': {'en': 'Tautulli Notification'},
'data': {'encrypted': True,
@@ -951,7 +941,7 @@ class ANDROIDAPP(Notifier):
"Android app notifications will be sent unecrypted. "
"Install the library to encrypt the notifications.")
- payload = {'app_id': self._ONESIGNAL_APP_ID,
+ payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
'include_player_ids': [self.config['device_id']],
'contents': {'en': 'Tautulli Notification'},
'data': {'encrypted': False,
@@ -968,7 +958,7 @@ class ANDROIDAPP(Notifier):
db = database.MonitorDatabase()
try:
- query = 'SELECT * FROM mobile_devices'
+ query = 'SELECT * FROM mobile_devices WHERE official = 1'
result = db.select(query=query)
except Exception as e:
logger.warn("Tautulli Notifiers :: Unable to retrieve Android app devices list: %s." % e)