Skip to content

Commit

Permalink
auto handle tempfiles for windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liupold committed Oct 11, 2021
1 parent 61ac2cc commit a26ab96
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fmdpy/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ def main_dl(
directory="./",
silent=0):
"""Main download function for fmdpy."""
to_delete = []
if song_obj.url == "":
return None

with tempfile.NamedTemporaryFile(suffix='.mp4', delete=not (os.name == 'nt')) as tf_song:
with tempfile.NamedTemporaryFile(suffix='.jpg', delete=not (os.name == 'nt')) as tf_thumb:
if os.name == 'nt':
to_delete.append(tf_song.name)
to_delete.append(tf_thumb.name)

output_file = directory + f"/{song_obj.artist}-{song_obj.title}({song_obj.year})"\
.replace(' ', '_').lower()
Expand Down Expand Up @@ -115,4 +119,6 @@ def main_dl(
if not silent:
sys.stdout.write("done\n")
sys.stdout.flush()
if len(to_delete) > 0:
_ = [os.unlink(fname) for fname in to_delete]
return True

0 comments on commit a26ab96

Please sign in to comment.