aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-07-31 16:44:21 -0700
committerJames Taylor <user234683@users.noreply.github.com>2018-07-31 16:44:21 -0700
commiteea034d5a9d628cad784f2cc81f867447afbbba5 (patch)
treea3131cce8867b9317d66537a9731356aef70ab64
parentc67e22c148d9c4ae148ea9a4409490d2483fc9b4 (diff)
downloadyt-local-eea034d5a9d628cad784f2cc81f867447afbbba5.tar.lz
yt-local-eea034d5a9d628cad784f2cc81f867447afbbba5.tar.xz
yt-local-eea034d5a9d628cad784f2cc81f867447afbbba5.zip
fix errors when data directory doesn't exist already
-rw-r--r--youtube/local_playlist.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 5da3b4d..3c62134 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -9,6 +9,8 @@ with open('yt_local_playlist_template.html', 'r', encoding='utf-8') as file:
local_playlist_template = Template(file.read())
def add_to_playlist(name, video_info_list):
+ if not os.path.exists(playlists_directory):
+ os.makedirs(playlists_directory)
with open(os.path.join(playlists_directory, name + ".txt"), "a", encoding='utf-8') as file:
for info in video_info_list:
file.write(info + "\n")
@@ -35,7 +37,11 @@ def get_local_playlist_page(name):
)
def get_playlist_names():
- for item in os.listdir(playlists_directory):
+ try:
+ items = os.listdir(playlists_directory)
+ except FileNotFoundError:
+ return
+ for item in items:
name, ext = os.path.splitext(item)
if ext == '.txt':
yield name