-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage_downloads.py
More file actions
36 lines (29 loc) · 1.27 KB
/
manage_downloads.py
File metadata and controls
36 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import re
import shutil
download_video_path='/home/brahim/Downloads/Video'
key_words=['Arduino','Django','PUBG','EgyBest','Spring','ENSAM']
pattern = re.compile(r"\((\d+)\)")
def rename_youtube_shity_preffix(download_video_path , pattern=pattern):
os.chdir(path=download_video_path)
for file in os.listdir():
if pattern.findall(file):
new_file=file.replace(f'({pattern.findall(file)[0]})','').strip()
print(new_file)
os.rename(file,new_file)
def create_dirs(dir_name,download_video_path):
if dir_name in os.listdir(download_video_path):
return False
os.mkdir(os.path.join(download_video_path , dir_name))
return True
def move_files(download_video_path,key_words):
os.chdir(path=download_video_path)
for file in os.listdir():
if not os.path.isdir(file):
for key_word in key_words :
if key_word in file :
create_dirs(key_word,download_video_path)
shutil.move(os.path.join(download_video_path,file),os.path.join(download_video_path,key_word,file))
if __name__ == '__main__' :
rename_youtube_shity_preffix(download_video_path=download_video_path)
move_files(download_video_path=download_video_path , key_words=key_words)