Skip to content

Commit

Permalink
Remove invalid characters from file names. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWeirdDev committed Dec 6, 2022
1 parent 7a630d2 commit f4916a2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pvdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_chapters(vid_id, limit_rate):
print_err("Error: Wrong link. No video found.")

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

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



def start_download(username, password, vid_id, limit_rate):
login(username, password)
Expand Down

0 comments on commit f4916a2

Please sign in to comment.