File: generate-cut-list.py

package info (click to toggle)
voctomix-outcasts 0.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 212 kB
  • sloc: python: 688; sh: 156; makefile: 18
file content (59 lines) | stat: -rwxr-xr-x 1,841 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env python3
#
# Copyright: 2015,2016    Carl F. Karsten <carl@nextdayvideo.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.


import argparse
import socket
import datetime
import sys


def capture_cuts(sock):
    """Listen to a voctocore control socket, and yield on cuts"""
    fd = sock.makefile('rw')
    for line in fd:
        words = line.rstrip('\n').split(' ')

        signal = words[0]
        args = words[1:]

        if signal == 'message' and args[0] == 'cut':
            yield


def main():
    p = argparse.ArgumentParser()
    p.add_argument('--host', default='localhost',
                   help='Hostname of voctocore')
    p.add_argument('--port', type=int, default=9999,
                   help='Port to connect to, on voctocore')
    p.add_argument('--file', type=argparse.FileType('a'),
                   help='Filename to write cuts to')
    args = p.parse_args()

    sock = socket.create_connection((args.host, args.port))
    for cut in capture_cuts(sock):
        ts = datetime.datetime.now().strftime("%Y-%m-%d/%H_%M_%S")
        print(ts)
        sys.stdout.flush()
        if args.file:
            args.file.write('%s\n' % ts)
            args.file.flush()


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        sys.exit(1)