-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_wilmaa
executable file
·117 lines (89 loc) · 2.88 KB
/
watch_wilmaa
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
#!/usr/bin/env python
"""
get wilmaa stream and store it into 2 buffer files (with defined length)
"""
__author__ = 'cooper'
import os
import wwwc.misc as misc
import logging as log
import wwwc.config as config
import wwwc.streamhandler as streamhandler
import wwwc.channelhandler as channelhandler
def cleanup_tmpdir(tmppath):
# TODO add fifoname to configfile
fifoname = os.path.join(tmppath, 'streamfifo')
try:
os.unlink(fifoname)
except:
pass
def get_uid(configfile, session):
from ConfigParser import ConfigParser
config = ConfigParser()
config.read(configfile)
try:
user_id = config.get('userdata', 'user_id')
# check user ID
except:
import getpass
from wwwc.sessionhandler import get_user_data
print 'No user_id found in config file'
username = raw_input('Username: ')
passwd = getpass.getpass()
user_id = get_user_data(username, passwd, session)
if not user_id:
misc.die(-1, 'unknown user ID')
return user_id
def main():
"""main"""
import wwwc.sessionhandler as sessionhandler
configfile = '/usr/local/wwwc/config/default_config.ini'
opts, args = config.get_cli_options()
# configure logger
# reset old log settings
if log.root:
del log.root.handlers[:]
formatstring = '[%(levelname)s]: %(message)s'
if opts.loglevel:
loglevel = log.getLevelName(opts.loglevel.upper())
else:
loglevel = log.WARN
# log.basicConfig(format=formatstring, level=loglevel)
log.basicConfig(filename='/tmp/wwwc.log', filemode='a', format=formatstring, level=loglevel)
# parse config
if opts.config_file:
configfile = opts.config_file
if not os.path.isfile(configfile):
msg = 'config file did not exist (' + configfile + ')'
misc.die(-1, msg)
session = config.create_stream_session(configfile)
tmppath = session.get('tmp_path')
if not tmppath:
import tempfile
tmppath = tempfile.mkdtemp()
try:
os.mkdir(tmppath)
except:
pass
# cleanup the tmpdir
cleanup_tmpdir(tmppath)
session.set('tmppath', tmppath)
# create userID cookie and add it to the config
uid = get_uid(configfile, session)
uid_ck = sessionhandler.create_uid_cookie(uid)
session.add_cookie(uid_ck)
channel_list = channelhandler.get_channel_list(session)
if opts.channel:
channel = opts.channel
channel_url = channelhandler.get_url_from_channel(channel_list, channel)
else:
channel_url = channelhandler.select_channel(channel_list)
session.set('channel', channel_url)
rc, msg = streamhandler.dump_to_file(session)
if int(rc) < 0:
misc.die(rc, msg)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('Abort by user.')
# vim: ft=py:tabstop=4:et