summaryrefslogtreecommitdiff
path: root/download-videos.py
blob: 194edf1e0ffb68884acc3b052de4685a62bba727 (plain)
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
#! /bin/python
import os
from shutil import copyfile
import sys
if os.path.exists(sys.argv[1]):
    path = os.path.abspath(sys.argv[1])
else:
    print("Cannot find " + sys.argv[1])
    exit()
with open('/home/lxf/.videocopyrc', 'r') as f:
    lastfile = str(f.readline().rstrip())
sorter = []
for (dirname, dirs, files) in os.walk(path):
    dirn = os.path.abspath(dirname)
    for filename in files:
        if int(filename.split('.MTS')[0]) > int(lastfile.split('.MTS')[0]):
            sorter.append([int(filename.split('.MTS')[0]), filename])
for f in sorted(sorter):
    dest = '/home/lxf/videos/inbox/'
    if not os.path.exists(dest):
        os.makedirs(dest)
    print("copying:", dirn+'/'+f[1], "--->", dest+f[1])
    copyfile(dirn+'/'+f[1], dest+f[1])
    try:
        out = sorted(sorter)[-1]
        with open('/home/lxf/.videocopyrc', 'w') as f:
            f.write(out[1])
    except IndexError:
        pass