Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sanitize_path_1():
path = "te%st"
result = helpers.sanitize_path(path)
assert result == "te_st"
def test_sanitize_path_hyphen():
path = "te-st"
result = helpers.sanitize_path(path)
assert result == "te-st"
def test_sanitize_path_0():
path = "test"
result = helpers.sanitize_path(path)
assert result == "test"
This method currently only supports downloading from an external URL.
In the future, it may be worthwhile to determine whether the episode's
source is a local file and simply copy it instead.
Args:
download_queue: the download_queue overseeing this download
display: (optional) the display to write status updates to
"""
if self._enclosure is None:
if display is not None:
display.change_status("Download failed: episode does not have"
" a valid media source")
return
feed_directory = self._feed_directory()
episode_partial_filename = helpers.sanitize_path(str(self))
extension = os.path.splitext(self._enclosure)[1].split('?')[0]
output_path = os.path.join(feed_directory,
episode_partial_filename + str(extension))
DataFile.ensure_path(output_path)
if display is not None:
display.change_status("Starting episode download...")
t = threading.Thread(
target=DataFile.download_to_file,
args=[
self._enclosure, output_path, str(self),
download_queue, display
],
name="download_%s" % str(self)
)
def get_playable(self) -> str:
"""Gets a playable path for this episode.
This method checks whether the episode is available on the disk, giving
the path to that file if so. Otherwise, simply return the episode's
enclosure, which is probably a URL.
Returns:
str: a path to a playable file for this episode
"""
playable = self.enclosure
episode_partial_filename = helpers.sanitize_path(str(self))
feed_directory = self._feed_directory()
if os.path.exists(feed_directory):
for File in os.listdir(feed_directory):
if File.startswith(episode_partial_filename + '.'):
playable = os.path.join(feed_directory, File)
return playable