3
# Copyright (C) 2008 Luis de Bethencourt
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2, or (at your option)
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22
"""play videos randomly"""
25
sys.path.append("../src")
27
from engine import Engine
28
from controller import Controller
36
usage = """shuffle.py [input_folder]"""
37
parser = optparse.OptionParser(usage = usage)
38
(options, args) = parser.parse_args()
41
print "A video folder needs to be specified."
45
if self.folder.endswith("/"):
46
self.folder = self.folder[:-1]
49
controller = Controller(engine)
52
ls = os.listdir(self.folder)
54
# Populating database of files in input directory.
55
self.browse_folder(ls, self.folder, self.tree)
57
length = len(self.tree)
59
print "Founded " + str(length) + " videos."
63
video = random.choice(self.tree)
64
controller.play(video, 1.0, 0)
65
print "playing " + video
68
def browse_folder(self, folder, dir, tree):
69
'''Creates a tree of all the files and folder inside the in put dir.'''
72
if not files.startswith(".") and (not files == folder):
73
files = dir + "/" + files
75
if os.path.isdir(files):
76
temp = files[files.find(self.folder_short):]
77
temp = "".join("%s/" % (n) for n in \
79
new = os.listdir(files)
80
self.browse_folder(new, files, tree)
83
if __name__ == "__main__":
85
print "Welcome to freemix shuffle... enjoy!"