-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideos.py
54 lines (42 loc) · 1.35 KB
/
videos.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
import random
import logging
from os import listdir,stat
from os.path import join
from tinytag import TinyTag
# default video dir
VIDEO_DIR = "/home/pi/Videos"
class Videos:
"""
Play and manage videos
"""
player = None
def __init__(self,video_dir = VIDEO_DIR):
self.video_dir = video_dir
self.last_video_dir_mtime = 0
self.get_videos()
def get_video(self):
"""
select a random video to play
"""
# see if the contents of the video directory have changed since last scan
statinfo = stat(self.video_dir)
if statinfo.st_mtime != self.last_video_dir_mtime:
logging.info("video directory changed. Rescanning")
self.get_videos()
self.last_video_dir_mtime = statinfo.st_mtime
return random.choice(self.videos)
def get_videos(self):
"""
get info on all the videos in the video directory
"""
self.videos=[]
for f in listdir(self.video_dir):
if not f.endswith(".mp4"):
continue
absolute_path = join(self.video_dir,f)
# get the video file metadata
tag = TinyTag.get(absolute_path)
video={'filename':absolute_path,
'duration':tag.duration}
self.videos.append(video)
return self.videos