mirror of
https://github.com/jellyfin/jellycon.git
synced 2024-11-23 14:09:55 +00:00
add connection speet test
This commit is contained in:
parent
ffafac6abf
commit
83993f4304
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<addon id="plugin.video.embycon"
|
||||
name="EmbyCon"
|
||||
version="1.9.93"
|
||||
version="1.9.94"
|
||||
provider-name="Team B">
|
||||
<requires>
|
||||
<import addon="xbmc.python" version="2.25.0"/>
|
||||
|
@ -311,7 +311,7 @@ msgid "Episodes"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30236"
|
||||
msgid "Force transcode h265(hevc)"
|
||||
msgid "Force transcode h265 (hevc)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30237"
|
||||
@ -327,7 +327,7 @@ msgid "Force transcode mpeg2"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30240"
|
||||
msgid "Force transcode msmpeg4v3(divx)"
|
||||
msgid "Force transcode msmpeg4v3 (divx)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30241"
|
||||
@ -1050,3 +1050,10 @@ msgctxt "#30434"
|
||||
msgid "Force transcode stream bitrate (Kbits)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30435"
|
||||
msgid "Connection speed test"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30436"
|
||||
msgid "Speed test data size (MB)"
|
||||
msgstr ""
|
||||
|
@ -19,7 +19,7 @@ from .utils import get_art, send_event_notification, convert_size
|
||||
from .kodi_utils import HomeWindow
|
||||
from .clientinfo import ClientInformation
|
||||
from .datamanager import DataManager, clear_cached_server_data
|
||||
from .server_detect import check_server
|
||||
from .server_detect import check_server, check_connection_speed
|
||||
from .simple_logging import SimpleLogging
|
||||
from .menu_functions import display_main_menu, display_menu, show_movie_alpha_list, show_tvshow_alpha_list, show_genre_list, show_search, show_movie_pages
|
||||
from .translation import string_load
|
||||
@ -91,6 +91,8 @@ def main_entry_point():
|
||||
check_server(force=True, notify=True)
|
||||
elif mode == "DETECT_SERVER_USER":
|
||||
check_server(force=True, change_user=True, notify=False)
|
||||
elif mode == "DETECT_CONNECTION_SPEED":
|
||||
check_connection_speed()
|
||||
elif mode == "playTrailer":
|
||||
item_id = params["id"]
|
||||
play_item_trailer(item_id)
|
||||
@ -552,7 +554,7 @@ def show_menu(params):
|
||||
if selected_transcode_value > 0:
|
||||
settings.setSetting("force_max_stream_bitrate", str(selected_transcode_value))
|
||||
|
||||
play_action(params)
|
||||
play_action(params)
|
||||
|
||||
elif selected_action == "add_to_playlist":
|
||||
params["action"] = "add_to_playlist"
|
||||
|
@ -583,6 +583,7 @@ def display_addon_menu(params):
|
||||
add_menu_directory_item(string_load(30017), "plugin://plugin.video.embycon/?mode=SHOW_SERVER_SESSIONS")
|
||||
add_menu_directory_item(string_load(30012), "plugin://plugin.video.embycon/?mode=CHANGE_USER")
|
||||
add_menu_directory_item(string_load(30011), "plugin://plugin.video.embycon/?mode=DETECT_SERVER_USER")
|
||||
add_menu_directory_item(string_load(30435), "plugin://plugin.video.embycon/?mode=DETECT_CONNECTION_SPEED")
|
||||
add_menu_directory_item(string_load(30254), "plugin://plugin.video.embycon/?mode=SHOW_SETTINGS")
|
||||
add_menu_directory_item(string_load(30395), "plugin://plugin.video.embycon/?mode=CLEAR_CACHE")
|
||||
add_menu_directory_item(string_load(30293), "plugin://plugin.video.embycon/?mode=CACHE_ARTWORK")
|
||||
|
@ -3,6 +3,8 @@
|
||||
import socket
|
||||
import json
|
||||
from urlparse import urlparse
|
||||
import httplib
|
||||
import ssl
|
||||
import time
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
@ -16,6 +18,7 @@ from .downloadutils import DownloadUtils, save_user_details, load_user_details
|
||||
from .simple_logging import SimpleLogging
|
||||
from .translation import string_load
|
||||
from .utils import datetime_from_string
|
||||
from .clientinfo import ClientInformation
|
||||
|
||||
log = SimpleLogging(__name__)
|
||||
|
||||
@ -23,6 +26,95 @@ __addon__ = xbmcaddon.Addon()
|
||||
__addon_name__ = __addon__.getAddonInfo('name')
|
||||
|
||||
|
||||
def check_connection_speed():
|
||||
log.debug("check_connection_speed")
|
||||
|
||||
settings = xbmcaddon.Addon()
|
||||
verify_cert = settings.getSetting('verify_cert') == 'true'
|
||||
http_timeout = int(settings.getSetting("http_timeout"))
|
||||
speed_test_data_size = int(settings.getSetting("speed_test_data_size"))
|
||||
test_data_size = speed_test_data_size * 1000000
|
||||
|
||||
du = DownloadUtils()
|
||||
server = du.get_server()
|
||||
|
||||
url = server + "/emby/playback/bitratetest?size=%s" % test_data_size
|
||||
|
||||
url_bits = urlparse(url.strip())
|
||||
|
||||
protocol = url_bits.scheme
|
||||
host_name = url_bits.hostname
|
||||
port = url_bits.port
|
||||
# user_name = url_bits.username
|
||||
# user_password = url_bits.password
|
||||
url_path = url_bits.path
|
||||
url_puery = url_bits.query
|
||||
|
||||
server = "%s:%s" % (host_name, port)
|
||||
url_path = url_path + "?" + url_puery
|
||||
|
||||
local_use_https = False
|
||||
if protocol.lower() == "https":
|
||||
local_use_https = True
|
||||
|
||||
if local_use_https and verify_cert:
|
||||
log.debug("Connection: HTTPS, Cert checked")
|
||||
conn = httplib.HTTPSConnection(server, timeout=http_timeout)
|
||||
elif local_use_https and not verify_cert:
|
||||
log.debug("Connection: HTTPS, Cert NOT checked")
|
||||
conn = httplib.HTTPSConnection(server, timeout=http_timeout, context=ssl._create_unverified_context())
|
||||
else:
|
||||
log.debug("Connection: HTTP")
|
||||
conn = httplib.HTTPConnection(server, timeout=http_timeout)
|
||||
|
||||
head = du.get_auth_header(True)
|
||||
head["User-Agent"] = "EmbyCon-" + ClientInformation().get_version()
|
||||
|
||||
conn.request(method="GET", url=url_path, headers=head)
|
||||
|
||||
progress_dialog = xbmcgui.DialogProgress()
|
||||
message = 'Testing with {0} MB of data'.format(speed_test_data_size)
|
||||
progress_dialog.create("EmbyCon connection speed test", message)
|
||||
total_data_read = 0
|
||||
total_time = time.time()
|
||||
|
||||
log.debug("Starting Connection Speed Test")
|
||||
response = conn.getresponse()
|
||||
last_percentage_done = 0
|
||||
if int(response.status) == 200:
|
||||
data = response.read(10240)
|
||||
while len(data) > 0:
|
||||
total_data_read += len(data)
|
||||
percentage_done = int(float(total_data_read) / float(test_data_size) * 100.0)
|
||||
if last_percentage_done != percentage_done:
|
||||
progress_dialog.update(percentage_done)
|
||||
last_percentage_done = percentage_done
|
||||
data = response.read(10240)
|
||||
else:
|
||||
log.error("HTTP response error: {0} {1}", response.status, response.reason)
|
||||
error_message = "HTTP response error: %s\n%s" % (response.status, response.reason)
|
||||
xbmcgui.Dialog().ok("Speed Test Error", error_message)
|
||||
return -1
|
||||
|
||||
total_data_read_kbits = (total_data_read * 8) / 1000
|
||||
total_time = time.time() - total_time
|
||||
speed = int(total_data_read_kbits / total_time)
|
||||
log.debug("Finished Connection Speed Test, speed: {0} total_data: {1}, total_time: {2}", speed, total_data_read, total_time)
|
||||
|
||||
progress_dialog.close()
|
||||
del progress_dialog
|
||||
|
||||
heading = "Speed Test Result : {0:,} Kbs".format(speed)
|
||||
message = "Do you want to set this speed as your max stream bitrate for playback?\n"
|
||||
message += "{0:,} MB over {1} sec".format(int((total_data_read / 1000000)), total_time)
|
||||
|
||||
response = xbmcgui.Dialog().yesno(heading, message)
|
||||
if response:
|
||||
settings.setSetting("max_stream_bitrate", str(speed))
|
||||
|
||||
return speed
|
||||
|
||||
|
||||
def check_safe_delete_available():
|
||||
log.debug("check_safe_delete_available")
|
||||
|
||||
|
@ -123,6 +123,7 @@
|
||||
<setting id="use_cache" type="bool" label="30345" default="true" visible="true" enable="true" />
|
||||
<setting id="showLoadProgress" type="bool" label="30120" default="false" visible="true" enable="true" />
|
||||
<setting id="suppressErrors" type="bool" label="30315" default="false" visible="true" enable="true" />
|
||||
<setting id="speed_test_data_size" type="slider" label="30436" default="15" range="5,1,100" option="int" visible="true"/>
|
||||
|
||||
</category>
|
||||
<category label="30421">
|
||||
|
17
service.py
17
service.py
@ -16,7 +16,7 @@ from resources.lib.widgets import set_background_image, set_random_movies
|
||||
from resources.lib.websocket_client import WebSocketClient
|
||||
from resources.lib.menu_functions import set_library_window_values
|
||||
from resources.lib.context_monitor import ContextMonitor
|
||||
from resources.lib.server_detect import check_server, check_safe_delete_available
|
||||
from resources.lib.server_detect import check_server, check_safe_delete_available, check_connection_speed
|
||||
from resources.lib.library_change_monitor import LibraryChangeMonitor
|
||||
from resources.lib.datamanager import clear_old_cache_data
|
||||
from resources.lib.tracking import set_timing_enabled
|
||||
@ -109,6 +109,7 @@ if enable_logging:
|
||||
# the service to exit when a user cancels an addon load action. This is a bug in Kodi.
|
||||
# I am switching back to xbmc.abortRequested approach until kodi is fixed or I find a work arround
|
||||
prev_user_id = home_window.get_property("userid")
|
||||
first_run = True
|
||||
|
||||
while not xbmc.abortRequested:
|
||||
|
||||
@ -130,6 +131,19 @@ while not xbmc.abortRequested:
|
||||
prev_user_id = home_window.get_property("userid")
|
||||
user_changed = True
|
||||
|
||||
if user_changed or first_run:
|
||||
server_speed_check_data = settings.getSetting("server_speed_check_data")
|
||||
server_host = download_utils.get_server()
|
||||
if server_host != "" and server_host != "<none>" and server_host not in server_speed_check_data:
|
||||
message = "This is the first time you have connected to this server.\nDo you want to run a connection speed test?"
|
||||
response = xbmcgui.Dialog().yesno("First Connection", message)
|
||||
if response:
|
||||
speed = check_connection_speed()
|
||||
if speed > 0:
|
||||
settings.setSetting("server_speed_check_data", server_host + "-" + str(speed))
|
||||
else:
|
||||
settings.setSetting("server_speed_check_data", server_host + "-skipped")
|
||||
|
||||
if user_changed or (random_movie_list_interval != 0 and (time.time() - last_random_movie_update) > random_movie_list_interval):
|
||||
last_random_movie_update = time.time()
|
||||
set_random_movies()
|
||||
@ -162,6 +176,7 @@ while not xbmc.abortRequested:
|
||||
log.error("Exception in Playback Monitor: {0}", error)
|
||||
log.error("{0}", traceback.format_exc())
|
||||
|
||||
first_run = False
|
||||
xbmc.sleep(1000)
|
||||
|
||||
image_server.stop()
|
||||
|
Loading…
Reference in New Issue
Block a user