-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamplayer.py
134 lines (107 loc) · 4.28 KB
/
streamplayer.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'''
STREAM PLAYER FUNCTION
AUTHOR: GEORGIA BLANCO-LITCHFIELD GBL06
'''
import psutil, os
from autosmart_v2.runner import Runner
from autosmart_v2.config.config import Config
APP_PATH = Config['exctractorappPath']
STREAM_SPECS = Config['streamSpecs']
STREAMS_LOC = Config['streamsLocation']
class StreamPlayer(Runner):
def __init__(self, name, status, stream, logger, counter):
super(StreamPlayer, self).__init__(logger=logger)
self.name = name
self._status = status
self.stream = stream
self.logger = logger
self.counter = counter
@property
def status(self):
"""
"""
if not self.proc:
print("Player status")
for proc in psutil.process_iter():
if proc.name == 'StreamXpress.exe' or proc.name == 'DtPlay.exe':
self._status = "Playing"
self.logger.error("Already playing {}, stopping before start of test".format(proc.name))
proc.kill()
# else:
# self.logger.info("Process is not already playing. Continue with test.")
return self._status
def start_run(self, stream_file, clients):
"""
"""
if self.counter == clients:
command = APP_PATH + ' ' + stream_file + ' ' + STREAM_SPECS
print("yeeeeeeeee")
super(StreamPlayer, self).start_run(command, False)
for proc in psutil.process_iter():
if proc.name == 'DtPlay.exe':
self._status = "Playing"
self.stream = stream_file
self.logger.info('Command being run:' + command)
else:
if self.counter == clients:
super(StreamPlayer, self).start_run(command, False)
def stop_run(self):
if self.proc:
super(StreamPlayer, self).stop_run()
self._status = "Stopped"
self.logger.info("Stream Stopped111")
else:
for proc in psutil.process_iter():
if proc.name == 'StreamXpress.exe' or proc.name == 'DtPlay.exe':
self.logger.info("The process is:" + proc)
proc.kill()
self._status = "Stopped"
self.stream = "No stream selected"
self.counter = 0
self.logger.info("Stream Stopped")
@property
def streams(self):
files = []
# r=root, d=directories, f = files
for r, d, f in os.walk(STREAMS_LOC):
for f_name in f:
if f_name.endswith('.ts'):
files.append(f_name)
# with os.scandir(STREAMS_LOC) as entries:
# for entry in entries:
# if entry.is_dir():
# files.append(entry.name)
return files
# for f in files:
# print(f)
# elif self._status == "Playing":
# try:
# for proc in psutil.process_iter():
# if (proc.name() == 'StreamXpress.exe' or proc.name() == 'DtPlay.exe'):
# print proc
# proc.kill()
# print stoppedd
# self._status = "Stopped"
# self.logger.info("Stream Stopped")
# except Exception as exc:
# self.logger.error("cannot stop {}".format(exc))
# traceback.format_exc()
# self.logger.error("Stream player couldn't be stopped")
# from win32com.client import GetObject
# WMI = GetObject('winmgmts:')
# processes = WMI.InstancesOf('Win32_Process')
# if "python.exe" in [process.Properties_('Name').Value for process in processes]:
# #do the thing
# s = subprocess.check_output('tasklist', shell=True)
# if "cmd.exe" in s:
# print s
# s = subprocess.check_output('tasklist', shell=True)
# for app_name in ("StreamXpress.exe *32"):
# if app_name in s:
# os.system("taskkill /f /im StreamXpress.exe")
# for proc in psutil.process_iter():
# if proc.name() == "StreamXpress.exe"
# self.logger.info("Killing StreamXpress as open on computer.")
# raise Exception("Streamplayer is not running so cant stop it")
# s = subprocess.check_output('tasklist', shell=True)
# if not (DtPlay.exe) in s: