Skip to content

Commit

Permalink
Add "find public server" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Et0h committed Aug 26, 2015
1 parent f0f2965 commit 411808b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion buildPy2exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def run(self):
'resources/user_key.png', 'resources/lock.png', 'resources/key_go.png', 'resources/page_white_key.png',
'resources/tick.png', 'resources/lock_open.png', 'resources/empty_checkbox.png', 'resources/tick_checkbox.png',
'resources/world_explore.png', 'resources/application_get.png', 'resources/cog.png',
'resources/film_go.png', 'resources/world_go.png'
'resources/film_go.png', 'resources/world_go.png', 'resources/report_magnify.png'
]
resources = ["resources/icon.ico", "resources/syncplay.png"]
resources.extend(guiIcons)
Expand Down
Binary file added resources/report_magnify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion syncplay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@
FILEITEM_SWITCH_STREAM_SWITCH = 2

SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"
SYNCPLAY_PUBLIC_SERVER_LIST_URL = u"http://syncplay.pl/listpublicservers?{}" # Params
15 changes: 15 additions & 0 deletions syncplay/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
"switch-file-not-found-error" : u"Could not switch to file '{0}'. Syncplay looks in the folder of the currently playing file and specified media directories.", # File not found
"folder-search-timeout-error" : u"The search for media in '{}' was aborted as it took too long. This will occur if you select a folder with too many sub-folders in your list of media folders to search through. Until Syncplay is restarted only the directory of the currently open file will be checked.", #Folder

"failed-to-load-server-list-error" : u"Failed to load public server list. Please visit http://www.syncplay.pl/ in your browser.",

# Client arguments
"argument-description" : 'Solution to synchronize playback of multiple MPlayer and MPC-HC instances over the network.',
"argument-epilog" : 'If no options supplied _config values will be used',
Expand Down Expand Up @@ -171,6 +173,7 @@
"media-path-label" : "Path to media file:",
"player-arguments-label" : "Player arguments (if any):",
"browse-label" : "Browse",
"list-servers-label" : u"Find public server",

"more-title" : "Show more settings",
"never-rewind-value" : "Never",
Expand Down Expand Up @@ -275,6 +278,8 @@
"identifyascontroller-msgbox-label" : "Identify as room operator",
"identifyinfo-msgbox-label" : "Enter operator password for this room\r\n(see http://syncplay.pl/guide/ for usage instructions):",

"public-server-msgbox-label" : "Find public server (you must all use the same one!)",

"megabyte-suffix" : " MB",

# Tooltips
Expand Down Expand Up @@ -500,6 +505,8 @@
"switch-file-not-found-error" : u"Невозможно переключиться на файл '{0}'. Syncplay looks in the folder of the currently playing file and specified media directories.", # File not found # TODO: Translate last part into Russian
"folder-search-timeout-error" : u"The search for media in '{}' was aborted as it took too long. This will occur if you select a folder with too many sub-folders in your list of media folders to search through. Until Syncplay is restarted only the directory of the currently open file will be checked.", #Folder # TODO: Translate into Russian

"failed-to-load-server-list-error" : u"Failed to load public server list. Please visit http://www.syncplay.pl/ in your browser.", # TODO: Translate into Russian

# Client arguments
"argument-description" : u'Решение для синхронного воспроизведения в VLC, MPlayer или MPC-HC через Интернет.',
"argument-epilog" : u'Если параметр не будет передан, то будет использоваться значение, указанное в _config.',
Expand Down Expand Up @@ -534,6 +541,7 @@
"media-path-label" : u"Путь к видеофайлу:",
"player-arguments-label" : u"Аргументы для запуска проигрывателя:",
"browse-label" : u"Выбрать",
"list-servers-label" : u"Find public server", # TODO: Translate into Russian

"more-title" : u"Больше настроек",
"never-rewind-value" : u"Никогда",
Expand Down Expand Up @@ -638,6 +646,8 @@
"identifyascontroller-msgbox-label" : u"Войти как оператор комнаты",
"identifyinfo-msgbox-label" : u"Введите пароль оператора комнаты\r\n(см. инструкцию на странице http://syncplay.pl/guide/):",

"public-server-msgbox-label" : "Find public server (you must all use the same one!)", # TODO: Translate into Russian

"megabyte-suffix" : u" МБ", # Technically it is a mebibyte

# Tooltips
Expand Down Expand Up @@ -863,6 +873,8 @@
"switch-file-not-found-error" : u"Could not switch to file '{0}'. Syncplay looks in the folder of the currently playing file and specified media directories.", # File not found, folder it was not found in # TODO: Translate into German
"folder-search-timeout-error" : u"The search for media in '{}' was aborted as it took too long. This will occur if you select a folder with too many sub-folders in your list of media folders to search through. Until Syncplay is restarted only the directory of the currently open file will be checked.", #Folder # TODO: Translate into German

"failed-to-load-server-list-error" : u"Failed to load public server list. Please visit http://www.syncplay.pl/ in your browser.", # TODO: Translate into German

# Client arguments
"argument-description" : u'Syncplay ist eine Anwendung um mehrere MPlayer, MPC-HC und VLC-Instanzen über das Internet zu synchronisieren.',
"argument-epilog" : u'Wenn keine Optionen angegeben sind, werden die _config-Werte verwendet',
Expand Down Expand Up @@ -897,6 +909,7 @@
"media-path-label" : u"Pfad zur Datei:",
"player-arguments-label" : u"Player arguments:", # TODO: Translate into German
"browse-label" : u"Durchsuchen",
"list-servers-label" : u"Find public server", # TODO: Translate into German

"more-title" : u"Mehr Einstellungen zeigen",
"never-rewind-value" : u"Niemals",
Expand Down Expand Up @@ -999,6 +1012,8 @@
"identifyascontroller-msgbox-label" : u"Als Raumleiter identifizieren",
"identifyinfo-msgbox-label" : u"Passwort des zentral gesteuerten Raums eingeben\r\n(siehe http://syncplay.pl/guide/ für eine Anleitung [Englisch]):",

"public-server-msgbox-label" : "Find public server (you must all use the same one!)", # TODO: Translate into German

"megabyte-suffix" : u" MB",

# Tooltips
Expand Down
36 changes: 33 additions & 3 deletions syncplay/ui/GuiConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,32 @@ def saveMoreState(self, morestate):
settings.setValue("ShowMoreSettings", morestate)
settings.endGroup()


def findPublicServer(self):
try:
servers = utils.getListOfPublicServers()
except IOError as e:
self.showErrorMessage(unicode(e))
return
dialog = QtGui.QInputDialog()
dialog.setOption(QtGui.QInputDialog.UseListViewForComboBoxItems)
dialog.setWindowTitle(getMessage("public-server-msgbox-label"))
dialog.setLabelText(getMessage("public-server-msgbox-label"))
serverTitles = []
serverDict = {}
for server in servers:
serverTitle = server[0]
serverAddress = server[1]
serverTitles.append(serverTitle)
serverDict[serverTitle]=serverAddress
dialog.setComboBoxItems(serverTitles)
ok = dialog.exec_()
if ok:
self.hostTextbox.setText(serverDict[dialog.textValue()])

def showErrorMessage(self, errorMessage):
QtGui.QMessageBox.warning(self, "Syncplay", errorMessage)

def browseMediapath(self):
self.loadMediaBrowseSettings()
options = QtGui.QFileDialog.Options()
Expand Down Expand Up @@ -389,7 +415,10 @@ def addBasicTab(self):
self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("connection-group-title"))
self.hostTextbox = QLineEdit(host, self)
self.hostLabel = QLabel(getMessage("host-label"), self)
self.findServerButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'report_magnify.png'), getMessage("list-servers-label"))
self.findServerButton.clicked.connect(self.findPublicServer)
self.usernameTextbox = QLineEdit(self)

self.usernameTextbox.setObjectName("name")
self.serverpassLabel = QLabel(getMessage("password-label"), self)
self.defaultroomTextbox = QLineEdit(self)
Expand All @@ -409,12 +438,13 @@ def addBasicTab(self):
self.connectionSettingsLayout = QtGui.QGridLayout()
self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0)
self.connectionSettingsLayout.addWidget(self.hostTextbox, 0, 1)
self.connectionSettingsLayout.addWidget(self.findServerButton, 0, 2)
self.connectionSettingsLayout.addWidget(self.serverpassLabel, 1, 0)
self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1)
self.connectionSettingsLayout.addWidget(self.serverpassTextbox, 1, 1, 1, 2)
self.connectionSettingsLayout.addWidget(self.usernameLabel, 2, 0)
self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1)
self.connectionSettingsLayout.addWidget(self.usernameTextbox, 2, 1, 1, 2)
self.connectionSettingsLayout.addWidget(self.defaultroomLabel, 3, 0)
self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1)
self.connectionSettingsLayout.addWidget(self.defaultroomTextbox, 3, 1, 1, 2)
self.connectionSettingsGroup.setLayout(self.connectionSettingsLayout)
self.connectionSettingsGroup.setMaximumHeight(self.connectionSettingsGroup.minimumSizeHint().height())

Expand Down
21 changes: 20 additions & 1 deletion syncplay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import random
import string
import urllib
import ast

folderSearchEnabled = True

Expand Down Expand Up @@ -260,6 +261,23 @@ def findFilenameInDirectories(filename, directoryList):
raise IOError(getMessage("folder-search-timeout-error").format(directory))
return None

def getListOfPublicServers():
try:
import urllib, syncplay, sys, messages, json
params = urllib.urlencode({'version': syncplay.version, 'milestone': syncplay.milestone, 'release_number': syncplay.release_number,
'language': messages.messages["CURRENT"]})
f = urllib.urlopen(constants.SYNCPLAY_PUBLIC_SERVER_LIST_URL.format(params))
response = f.read()
response = response.replace("<p>","").replace("</p>","").replace("<br />","").replace("&#8220;","'").replace("&#8221;","'").replace(":&#8217;","'").replace("&#8217;","'").replace("&#8242;","'").replace("\n","").replace("\r","") # Fix Wordpress
response = ast.literal_eval(response)

if response:
return response
else:
raise IOError
except:
raise IOError(getMessage("failed-to-load-server-list-error"))

class RoomPasswordProvider(object):
CONTROLLED_ROOM_REGEX = re.compile("^\+(.*):(\w{12})$")
PASSWORD_REGEX = re.compile("[A-Z]{2}-\d{3}-\d{3}")
Expand Down Expand Up @@ -319,4 +337,5 @@ def _get_random_numbers(quantity):
return ''.join(random.choice(string.digits) for _ in xrange(quantity))

class NotControlledRoom(Exception):
pass
pass

0 comments on commit 411808b

Please sign in to comment.