-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
103 lines (80 loc) · 2.48 KB
/
__init__.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import sys
import re
from subprocess import Popen,PIPE, call
class MetaData:
"""A class to return a list of tuples with metadata keys and
values for a given video path. Uses mplayer to probe video.
"""
def __init__(self, path):
self.path = path
self.kv = {}
id_re = re.compile('(^ID.*)=(.*)')
lt_values = []
p = Popen('mplayer -nolirc -vo null -ao null -frames 0 -identify ' + self.path, shell=True, stdout=PIPE)
while True:
o = p.stdout.readline()
if o == '' and p.poll() != None: break
# the 'o' variable stores a line from the command's stdout
# do anything u wish with the 'o' variable here
# this loop will break once theres a blank output
# from stdout and the subprocess have ended
try:
match = re.findall(id_re,o)[0]
lt_values.append(match)
except:
pass
self.kv = dict(lt_values)
#if self.kv['ID_VIDEO_FORMAT'] is '0':
# print "invalid video"
# sys.exit()
def all_values(self):
#return dictionary of all values
return self.kv
@property
def audio_bitrate(self):
return self.kv['ID_AUDIO_BITRATE']
@property
def audio_codec(self):
return self.kv['ID_AUDIO_CODEC']
@property
def audio_format(self):
return self.kv['ID_AUDIO_FORMAT']
@property
def audio_id(self):
return self.kv['ID_AUDIO_ID']
@property
def video_id(self):
return self.kv['ID_VIDEO_ID']
@property
def demuxer(self):
return self.kv['ID_DEMUXER']
@property
def video_format(self):
return self.kv['ID_VIDEO_FORMAT']
@property
def video_bitrate(self):
return self.kv['ID_VIDEO_BITRATE']
@property
def video_width(self):
return self.kv['ID_VIDEO_WIDTH']
@property
def video_height(self):
return self.kv['ID_VIDEO_HEIGHT']
@property
def video_fps(self):
return self.kv['ID_VIDEO_FPS']
@property
def video_aspect(self):
return self.kv['ID_VIDEO_ASPECT']
@property
def audio_format(self):
return self.kv['ID_AUDIO_FORMAT']
@property
def audio_rate(self):
return self.kv['ID_AUDIO_RATE']
@property
def audio_ch(self):
return self.kv['ID_AUDIO_NCH']
@property
def duration(self):
return self.kv['ID_LENGTH']