-
Notifications
You must be signed in to change notification settings - Fork 18
/
video.py
76 lines (66 loc) · 1.57 KB
/
video.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import subprocess
import random
path=""
video_list=[]
def set_path():
if not os.path.exists("./path.txt"):
path = raw_input("Enter the path where videos are stored")
path=path.lstrip().rstrip()
if os.path.exists(path):
if path !="":
try:
f=open("./path.txt","w")
except(IOError):
print "Something is wrong with the file"
exit()
finally:
print "file created on this path: "+path
f.write(path)
f.write("\n")
f.close()
else:
print "That path is invalid"
else:
return
def listing():
#this function invokes the vlc media player to actually play a video
try:
f = open("./path.txt")
except(IOError):
print "Path invalid, please try again"
exit()
path = f.readline()
f.close()
path=path.lstrip().rstrip()
video_list = os.listdir(path)
total_videos = len(video_list)
if not os.path.exists("./list.txt"):
f=open("./list.txt","w")
num=random.randint(0,len(video_list)-1)
f.write("%s,"%(num))
f.close()
else:
f = open("./list.txt","r")
line = f.readline()
line = line.split(",")
num=0
if len(line)==total_videos: #when all the videos have been watched, truncate the file
print "all videos finished"
f=open("./list.txt","w")
f.close()
while True:
num=random.randint(0,len(video_list)-1)
if str(num) not in line:
break
f=open("./list.txt","a")
f.write("%s,"%(num))
print "written to file"
f.close()
play(path, video_list, num)
def play(path, video_list, num):
os.chdir(path)
subprocess.Popen(["vlc", video_list[num]])
if __name__=="__main__":
set_path()
listing()