rewrite smb url with credentials to url without credentials in windows (#84)

* rewrite media url with credentials
* use pathlib for extra safety

Co-authored-by: Antonio Zhu <antoniozhu@outlook.de>
This commit is contained in:
Antonio Zhu 2020-07-10 23:04:32 +02:00 committed by GitHub
parent 8776143d5f
commit 308dcffedf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,9 @@ import logging
import uuid
import urllib.parse
import os.path
import re
import pathlib
from sys import platform
from .conf import settings
from .utils import is_local_domain, get_profile, get_seq
@ -134,7 +137,16 @@ class Video(object):
if urllib.parse.urlparse(self.media_source['Path']).scheme:
self.is_transcode = False
log.debug("Using remote direct path.")
return self.media_source['Path']
# translate path for windows
# if path is smb path in credential format for kodi and maybe linux \\username:password@mediaserver\foo,
# translate it to mediaserver/foo
if sys.platform.startswith("win32") or sys.platform.startswith("cygwin"):
# matches on SMB scheme
match = re.search('(?:\\\\).+:.*@(.+)', self.media_source['Path'])
if match:
# replace forward slash to backward slashes
return pathlib.Path('\\\\' + match.groups()[0]
return pathlib.Path(self.media_source['Path'])
else:
# If there's no uri scheme, check if the file exixsts because it might not be mounted
if os.path.isfile(self.media_source['Path']):