From 3dc9345705f9a08d3a4c9a5adfab549e4973e323 Mon Sep 17 00:00:00 2001 From: Suraj Patil Date: Sat, 3 Jan 2015 16:15:23 +0530 Subject: [PATCH 1/3] created video.py This file takes an absolute path to the folder where there are considerable number of videos and randomly plays them --- video.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 video.py diff --git a/video.py b/video.py new file mode 100644 index 0000000..8a44866 --- /dev/null +++ b/video.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +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") + if path !="": + try: + f=open("./path.txt","w") + except(IOError): + print "Something is wrong with the file" + exit + f.write(path) + f.close() + +def play(): + try: + f = open("./path.txt") + except(IOError): + print "Path invalid, please try again" + exit + path = f.readline() + f.close() + + video_list = os.listdir(path) + os.chdir(path) + + subprocess.Popen(["vlc", video_list[random.randint(0,len(video_list)-1)]]) + +if __name__=="__main__": + set_path() + play() From 5007e4820690adedb209d1351581c69877961c5d Mon Sep 17 00:00:00 2001 From: Suraj Patil Date: Sat, 3 Jan 2015 16:17:01 +0530 Subject: [PATCH 2/3] added details about video.py --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0955c19..306fa22 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,4 @@ List: 12. tables: generates mathematical tables 13. generateAllPossibleWords.txt: A step by step tutorial of generating all possible strings from an imput string, this is a session stored from the IDLE 14. builtinFunctions.py: demo of major builtin functions that are used all the time +15. video.py: takes a path of the folder where there are videos and stores the path in a file and will play a random video when you execute the file, it uses subprocess module to call vlc so you need to have vlc installed From e742e85b5bd6df5735983a532defe80cee834e6c Mon Sep 17 00:00:00 2001 From: Suraj Patil Date: Sun, 4 Jan 2015 18:00:09 +0530 Subject: [PATCH 3/3] update video.py fixed the bug of repetitive videos being played, now the program stores the previously played videos --- video.py | 67 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/video.py b/video.py index 8a44866..6808fb6 100644 --- a/video.py +++ b/video.py @@ -1,4 +1,3 @@ -#!/usr/bin/python import os import subprocess import random @@ -9,29 +8,69 @@ def set_path(): if not os.path.exists("./path.txt"): path = raw_input("Enter the path where videos are stored") - if path !="": - try: - f=open("./path.txt","w") - except(IOError): - print "Something is wrong with the file" - exit - f.write(path) - f.close() + 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 play(): +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 + exit() + path = f.readline() f.close() + path=path.lstrip().rstrip() video_list = os.listdir(path) - os.chdir(path) + total_videos = len(video_list) - subprocess.Popen(["vlc", video_list[random.randint(0,len(video_list)-1)]]) + 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() - play() + listing()