Formatted the client.py
This commit is contained in:
parent
d4f4342642
commit
496635848f
@ -1,4 +1,3 @@
|
|||||||
#coding:utf8
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os.path
|
import os.path
|
||||||
import time
|
import time
|
||||||
@ -9,7 +8,7 @@ from syncplay.protocols import SyncClientProtocol
|
|||||||
from syncplay import utils, constants
|
from syncplay import utils, constants
|
||||||
from syncplay.messages import getMessage
|
from syncplay.messages import getMessage
|
||||||
import threading
|
import threading
|
||||||
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE,\
|
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE, \
|
||||||
PRIVACY_HIDDENFILENAME, FILENAME_STRIP_REGEX
|
PRIVACY_HIDDENFILENAME, FILENAME_STRIP_REGEX
|
||||||
# <MAL DISABLE>
|
# <MAL DISABLE>
|
||||||
libMal = None
|
libMal = None
|
||||||
@ -19,8 +18,9 @@ except ImportError:
|
|||||||
libMal = None
|
libMal = None
|
||||||
'''
|
'''
|
||||||
# </MAL DISABLE>
|
# </MAL DISABLE>
|
||||||
|
|
||||||
class SyncClientFactory(ClientFactory):
|
class SyncClientFactory(ClientFactory):
|
||||||
def __init__(self, client, retry = constants.RECONNECT_RETRIES):
|
def __init__(self, client, retry=constants.RECONNECT_RETRIES):
|
||||||
self._client = client
|
self._client = client
|
||||||
self.retry = retry
|
self.retry = retry
|
||||||
self._timesTried = 0
|
self._timesTried = 0
|
||||||
@ -42,7 +42,7 @@ class SyncClientFactory(ClientFactory):
|
|||||||
self._timesTried += 1
|
self._timesTried += 1
|
||||||
self._client.ui.showMessage(getMessage("en", "reconnection-attempt-notification"))
|
self._client.ui.showMessage(getMessage("en", "reconnection-attempt-notification"))
|
||||||
self.reconnecting = True
|
self.reconnecting = True
|
||||||
reactor.callLater(0.1*(2**self._timesTried), connector.connect)
|
reactor.callLater(0.1 * (2 ** self._timesTried), connector.connect)
|
||||||
else:
|
else:
|
||||||
message = getMessage("en", "disconnection-notification")
|
message = getMessage("en", "disconnection-notification")
|
||||||
self._client.ui.showErrorMessage(message)
|
self._client.ui.showErrorMessage(message)
|
||||||
@ -68,7 +68,7 @@ class SyncplayClient(object):
|
|||||||
self._player = None
|
self._player = None
|
||||||
self.givenmalprivacywarning = False
|
self.givenmalprivacywarning = False
|
||||||
if(config['room'] == None or config['room'] == ''):
|
if(config['room'] == None or config['room'] == ''):
|
||||||
config['room'] = config['name'] # ticket #58
|
config['room'] = config['name'] # ticket #58
|
||||||
self.defaultRoom = config['room']
|
self.defaultRoom = config['room']
|
||||||
self.playerPositionBeforeLastSeek = 0.0
|
self.playerPositionBeforeLastSeek = 0.0
|
||||||
self.setUsername(config['name'])
|
self.setUsername(config['name'])
|
||||||
@ -302,7 +302,7 @@ class SyncplayClient(object):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
size = os.path.getsize(path)
|
size = os.path.getsize(path)
|
||||||
except OSError: #file not accessible (stream?)
|
except OSError: # file not accessible (stream?)
|
||||||
size = 0
|
size = 0
|
||||||
rawfilename = filename
|
rawfilename = filename
|
||||||
filename, size = self.__executePrivacySettings(filename, size)
|
filename, size = self.__executePrivacySettings(filename, size)
|
||||||
@ -382,7 +382,7 @@ class SyncplayClient(object):
|
|||||||
reactor.connectTCP(host, port, self.protocolFactory)
|
reactor.connectTCP(host, port, self.protocolFactory)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
||||||
def stop(self, promptForAction = False):
|
def stop(self, promptForAction=False):
|
||||||
if not self._running:
|
if not self._running:
|
||||||
return
|
return
|
||||||
self._running = False
|
self._running = False
|
||||||
@ -434,7 +434,7 @@ class SyncplayClient(object):
|
|||||||
|
|
||||||
def __displayMessageOnOSD(self, warningName):
|
def __displayMessageOnOSD(self, warningName):
|
||||||
if (constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]):
|
if (constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]):
|
||||||
self._ui.showOSDMessage(getMessage("en", warningName ), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL)
|
self._ui.showOSDMessage(getMessage("en", warningName), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL)
|
||||||
self._warnings[warningName]["displayedFor"] += constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL
|
self._warnings[warningName]["displayedFor"] += constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL
|
||||||
else:
|
else:
|
||||||
self._warnings[warningName]["displayedFor"] = 0
|
self._warnings[warningName]["displayedFor"] = 0
|
||||||
@ -443,7 +443,7 @@ class SyncplayClient(object):
|
|||||||
|
|
||||||
|
|
||||||
class SyncplayUser(object):
|
class SyncplayUser(object):
|
||||||
def __init__(self, username = None, room = None, file_ = None, position = 0):
|
def __init__(self, username=None, room=None, file_=None, position=0):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.room = room
|
self.room = room
|
||||||
self.file = file_
|
self.file = file_
|
||||||
@ -509,7 +509,7 @@ class MalUpdater(object):
|
|||||||
if(len(results) > 0):
|
if(len(results) > 0):
|
||||||
result = results[0]
|
result = results[0]
|
||||||
message = "Updating MAL with: \"{}\", episode: {}".format(result.mainTitle, result.episodeBeingWatched)
|
message = "Updating MAL with: \"{}\", episode: {}".format(result.mainTitle, result.episodeBeingWatched)
|
||||||
reactor.callFromThread(self._ui.showMessage,(message),)
|
reactor.callFromThread(self._ui.showMessage, (message),)
|
||||||
options = {"tags": ["syncplay"]}
|
options = {"tags": ["syncplay"]}
|
||||||
manager.updateEntryOnMal(result, options)
|
manager.updateEntryOnMal(result, options)
|
||||||
self._filename = "" # Make sure no updates will be performed until switch
|
self._filename = "" # Make sure no updates will be performed until switch
|
||||||
@ -550,7 +550,7 @@ class SyncplayUserlist(object):
|
|||||||
message = getMessage("en", "file-differences-notification") + ", ".join(differences)
|
message = getMessage("en", "file-differences-notification") + ", ".join(differences)
|
||||||
self.ui.showMessage(message)
|
self.ui.showMessage(message)
|
||||||
|
|
||||||
def addUser(self, username, room, file_, position = 0, noMessage = False):
|
def addUser(self, username, room, file_, position=0, noMessage=False):
|
||||||
if(username == self.currentUser.username):
|
if(username == self.currentUser.username):
|
||||||
self.currentUser.lastPosition = position
|
self.currentUser.lastPosition = position
|
||||||
return
|
return
|
||||||
@ -629,23 +629,26 @@ class SyncplayUserlist(object):
|
|||||||
def clearList(self):
|
def clearList(self):
|
||||||
self._users = {}
|
self._users = {}
|
||||||
|
|
||||||
|
def sortList(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class UiManager(object):
|
class UiManager(object):
|
||||||
def __init__(self, client, ui):
|
def __init__(self, client, ui):
|
||||||
self._client = client
|
self._client = client
|
||||||
self.__ui = ui
|
self.__ui = ui
|
||||||
|
|
||||||
def showMessage(self, message, noPlayer = False, noTimestamp = False):
|
def showMessage(self, message, noPlayer=False, noTimestamp=False):
|
||||||
if(not noPlayer): self.showOSDMessage(message)
|
if(not noPlayer): self.showOSDMessage(message)
|
||||||
self.__ui.showMessage(message, noTimestamp)
|
self.__ui.showMessage(message, noTimestamp)
|
||||||
|
|
||||||
def showUserList(self, currentUser, rooms):
|
def showUserList(self, currentUser, rooms):
|
||||||
self.__ui.showUserList(currentUser, rooms)
|
self.__ui.showUserList(currentUser, rooms)
|
||||||
|
|
||||||
def showOSDMessage(self, message, duration = constants.OSD_DURATION):
|
def showOSDMessage(self, message, duration=constants.OSD_DURATION):
|
||||||
if(self._client._player):
|
if(self._client._player):
|
||||||
self._client._player.displayMessage(message, duration * 1000)
|
self._client._player.displayMessage(message, duration * 1000)
|
||||||
|
|
||||||
def showErrorMessage(self, message, criticalerror = False):
|
def showErrorMessage(self, message, criticalerror=False):
|
||||||
self.__ui.showErrorMessage(message, criticalerror)
|
self.__ui.showErrorMessage(message, criticalerror)
|
||||||
|
|
||||||
def promptFor(self, prompt):
|
def promptFor(self, prompt):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user