From 411808b3483ecbe9dbb7a17a2d3a84805c456dac Mon Sep 17 00:00:00 2001 From: Et0h Date: Wed, 26 Aug 2015 19:25:07 +0100 Subject: [PATCH] Add "find public server" feature --- buildPy2exe.py | 2 +- resources/report_magnify.png | Bin 0 -> 738 bytes syncplay/constants.py | 3 ++- syncplay/messages.py | 15 +++++++++++++ syncplay/ui/GuiConfiguration.py | 36 +++++++++++++++++++++++++++++--- syncplay/utils.py | 21 ++++++++++++++++++- 6 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 resources/report_magnify.png diff --git a/buildPy2exe.py b/buildPy2exe.py index 3b3a375..24175c1 100644 --- a/buildPy2exe.py +++ b/buildPy2exe.py @@ -654,7 +654,7 @@ guiIcons = ['resources/accept.png', 'resources/arrow_undo.png', 'resources/clock '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) diff --git a/resources/report_magnify.png b/resources/report_magnify.png new file mode 100644 index 0000000000000000000000000000000000000000..aeaa889534234e156bdcec30b73b591b10d8a019 GIT binary patch literal 738 zcmV<80v-K{P)JgP zpi~!%ir7|Bt5jR6QQK0ZCTW`7b7ovzy|oJBfwLHx`JHcmbH-6s1_lOpm2RKDZl(&D z@ey|9hdTJbGvW02_pi6sK9F!G?O~ZbbC_*sU;J0K@B1Bo5ClV=ot;M-U-ssk7Xk`l z7|ux)5ma?foJyr4k?!v9)z;cm(zYKD!}oiAf4$_oE+P`gj^o6FF+uWKZ$8teAW;Iq z$xGvifI?ItAi#;e+1WN?g4X?bj^W##yRm=>tXZ1+DG=Sk(Fy?8+PMV&;I({9R#DYi z0ac!lP9uPdqGAz^JaAoC{vbGj=NO8&@5Viz+?V6gn+Yb%HOjRH8WKt7r34#RF(y$3 z>@304tNBc8#Hp%?2p8^uV8Q$rHmu0vCp;#;)hU*0JbqhZQ+rDq@O~pWh=-wgt1ouC zF_or0*F>@AV5$~%JQlZQcrjd|P$=Mep6dodFjOcMj*R!7qx|GNVu?pouGUE=6BsLq zC^L1TZosHdE|k}>@gRw+&tz7K`>;DS-0`kjdx88QmDen$Oy(5j4`A|Se4f3J2wko zOJhvGAEb5pTDmrm9dmve*0XA1*Rtm1)<{9 literal 0 HcmV?d00001 diff --git a/syncplay/constants.py b/syncplay/constants.py index 59b406f..fc7836b 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -173,4 +173,5 @@ FILEITEM_SWITCH_FILE_SWITCH = 1 FILEITEM_SWITCH_STREAM_SWITCH = 2 SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params -SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/" \ No newline at end of file +SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/" +SYNCPLAY_PUBLIC_SERVER_LIST_URL = u"http://syncplay.pl/listpublicservers?{}" # Params \ No newline at end of file diff --git a/syncplay/messages.py b/syncplay/messages.py index 2e9f336..42df2a4 100755 --- a/syncplay/messages.py +++ b/syncplay/messages.py @@ -137,6 +137,8 @@ en = { "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', @@ -171,6 +173,7 @@ en = { "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", @@ -275,6 +278,8 @@ en = { "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 @@ -500,6 +505,8 @@ ru = { "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.', @@ -534,6 +541,7 @@ ru = { "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"Никогда", @@ -638,6 +646,8 @@ ru = { "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 @@ -863,6 +873,8 @@ de = { "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', @@ -897,6 +909,7 @@ de = { "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", @@ -999,6 +1012,8 @@ de = { "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 diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 12996f6..a3fdb3d 100644 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -226,6 +226,32 @@ class ConfigDialog(QtGui.QDialog): 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() @@ -389,7 +415,10 @@ class ConfigDialog(QtGui.QDialog): 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) @@ -409,12 +438,13 @@ class ConfigDialog(QtGui.QDialog): 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()) diff --git a/syncplay/utils.py b/syncplay/utils.py index 2e76541..1e7263d 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -10,6 +10,7 @@ import hashlib import random import string import urllib +import ast folderSearchEnabled = True @@ -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("

","").replace("

","").replace("
","").replace("“","'").replace("”","'").replace(":’","'").replace("’","'").replace("′","'").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}") @@ -319,4 +337,5 @@ class RandomStringGenerator(object): return ''.join(random.choice(string.digits) for _ in xrange(quantity)) class NotControlledRoom(Exception): - pass \ No newline at end of file + pass +