added a safe-filename function so we will be sure the suggested filename won't break anything in the operating system

This commit is contained in:
Manuel Cortez 2019-10-14 17:25:06 -05:00
parent 9e6e72c0a1
commit 0cdfc253d2
3 changed files with 7 additions and 3 deletions

View File

@ -594,7 +594,7 @@ class documentBuffer(feedBuffer):
def download(self, *args, **kwargs): def download(self, *args, **kwargs):
post = self.get_post() post = self.get_post()
filename = post["title"] filename = utils.safe_filename(post["title"])
# If document does not end in .extension we must fix it so the file dialog will save it properly later. # If document does not end in .extension we must fix it so the file dialog will save it properly later.
if filename.endswith(post["ext"]) == False: if filename.endswith(post["ext"]) == False:
filename = filename+ "."+post["ext"] filename = filename+ "."+post["ext"]

View File

@ -73,7 +73,7 @@ class displayAudioPresenter(base.basePresenter):
def get_suggested_filename(self, audio_index): def get_suggested_filename(self, audio_index):
post = self.post[audio_index] post = self.post[audio_index]
return "{0} - {1}.mp3".format(post["title"], post["artist"]) return utils.safe_filename("{0} - {1}.mp3".format(post["title"], post["artist"]))
def download(self, audio_index, path): def download(self, audio_index, path):
post = self.post[audio_index] post = self.post[audio_index]

View File

@ -91,3 +91,7 @@ def transform_audio_url(url):
else: else:
url = url.replace("/"+parts[-3], "") url = url.replace("/"+parts[-3], "")
return url return url
def safe_filename(filename):
allowed_symbols = ["_", ".", ",", "-", "(", ")"]
return "".join([c for c in filename if c.isalpha() or c.isdigit() or c==' ' or c in allowed_symbols]).rstrip()