Skip to content

Commit f4916a2

Browse files
committed
Remove invalid characters from file names. Fixes #6
1 parent 7a630d2 commit f4916a2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pvdl.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get_chapters(vid_id, limit_rate):
153153
print_err("Error: Wrong link. No video found.")
154154

155155
title = details["title"]
156-
title = re.sub(r"[<>|/\\?*]", "_" ,title);
156+
title = re.sub(r"[^\w\s\d.,\+\$\%\#\@\!\(\)\[\]\-\{\}]", "_" ,title);
157157
os.makedirs(title, 0o755, exist_ok=True)
158158

159159
url = 'https://static.packt-cdn.com/products/{}/toc'.format(vid_id)
@@ -166,18 +166,19 @@ def get_chapters(vid_id, limit_rate):
166166
all_chapters = details['chapters']
167167
for x,i in enumerate(all_chapters):
168168
section = i['title']
169-
section = re.sub(r"[<>|/\\?*]", "_" , section)
169+
section = re.sub(r"[^\w\s\d.,\+\$\%\#\@\!\(\)\[\]\-\{\}]", "_" , section)
170170
s_path = "{}{}{:02}-{}".format(title, os.sep, x+1, section)
171171
os.makedirs(s_path, 0o755, exist_ok=True)
172-
print(bcolors.OKGREEN + "\nChapter {}/{}:".format(x+1, len(all_chapters)), section, "\n" + bcolors.ENDC)
172+
print(bcolors.OKGREEN + "\nChapter {}/{} ({} videos):".format(x+1, len(all_chapters), len(i['sections'])), section, "\n" + bcolors.ENDC)
173173
for y,c in enumerate(i['sections']):
174174
chapter = c['title']
175-
chapter = re.sub(r"[<>|/\\?*]", "_" , chapter)
175+
chapter = re.sub(r"[^\w\s\d.,\+\$\%\#\@\!\(\)\[\]\-\{\}]", "_" , chapter)
176176
c_path = "{}{}{:02}-{}.mp4".format(s_path, os.sep , y+1, chapter)
177177
video_id = i['id'] + '/' + c['id']
178178
video_url = get_video_url(vid_id, video_id)
179179
download_url(video_url, c_path, limit_rate)
180180

181+
181182

182183
def start_download(username, password, vid_id, limit_rate):
183184
login(username, password)

0 commit comments

Comments
 (0)