-
Notifications
You must be signed in to change notification settings - Fork 2
/
move_vids.py
33 lines (25 loc) · 1 KB
/
move_vids.py
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
## Move video files downloaded with youtube-dl from Documents => Documents/VIDEO
import os
import os.path as path
VIDEO_EXTENSIONS = [
".mp4", ".m4a", ".webm"
]
def get_vid_names(dir="~/Documents", fullpath=False):
assert path.isdir(path.expanduser(dir))
filez = [f for f in os.listdir(path.expanduser(dir)) if path.isfile(f)]
ret = [x for x in filez if path.splitext(x)[-1] in VIDEO_EXTENSIONS]
return ret if not fullpath else map(lambda x: path.join(path.expanduser(dir), x)[8:], ret)
def move_vids(fromdir='~/Documents', todir='~/Documents/VIDEO'):
os.chdir(path.expanduser(fromdir))
vidlist = get_vid_names(fromdir)
for f in vidlist:
try:
os.rename(
path.join(path.expanduser(fromdir), f)[8:],
path.join(path.expanduser(todir), f)[8:]
)
print("==> {0}/{1}".format(todir, f))
except:
print("Could not move file:\t {fn}".format(fn=f))
if __name__ == "__main__":
move_vids()