allinwonder funktioniert.
[videoscripts.git] / script-Z-preroll-generator.py
1 #!/usr/bin/env python3
2 import xmlrpc.client
3 import traceback
4 import socket
5 import time
6 import sys
7 import os
8
9 import renderlib
10 import c3t_rpc_client as rpc
11
12 try:
13         from termcolor import colored
14 except ImportError:
15         def colored(str, col):
16                 return str
17
18 print("C3TT preroll generator")
19 renderlib.debug = True
20
21 if os.environ.get('CRS_TOKEN') is None or os.environ.get('CRS_SECRET') is None:
22         print('CRS_TOKEN or CRS_SECRET is empty. did you source the tracker-scripts-profile?')
23         sys.exit(1)
24
25 ticket_type = 'recording'
26 ticket_state = 'generating'
27
28 host = socket.getfqdn()
29 url = os.environ['CRS_TRACKER']
30 token = os.environ['CRS_TOKEN']
31 secret = os.environ['CRS_SECRET']
32
33 filter = {}
34 if not os.environ.get('CRS_ROOM') is None:
35         filter['Fahrplan.Room'] = os.environ['CRS_ROOM']
36
37 projects = {}
38 def generatePreroll(ticket):
39         print(ticket)
40         projectname = ticket.get('Processing.Prerolls.Slug', ticket['Meta.Acronym'])
41         if not projectname in projects:
42                 projects[projectname] = renderlib.loadProject(projectname)
43
44         project = projects[projectname]
45         task = project.ticket(ticket)
46         task.outfile = os.path.join(ticket['Processing.Path.Intros'], ticket['Fahrplan.ID'] + '.dv')
47         task.workdir = os.path.join(os.getcwd(), projectname, 'artwork')
48
49         print(colored("rendering", 'green'))
50         renderlib.rendertask(task)
51
52         if hasattr(project, 'deploy'):
53                 print(colored("deploying", 'green'))
54                 project.deploy(ticket, task)
55
56
57 while True:
58         print(colored('Asking RPC for {0}-tickets which are ready for state {1}'.format(ticket_type, ticket_state), 'yellow'))
59
60         ticket_id = rpc.assignNextUnassignedForState(ticket_type, ticket_state, url, token, host, secret, filter)
61         if ticket_id != False:
62                 ticket = rpc.getTicketProperties(str(ticket_id), url, token, host, secret)
63                 try:
64                         generatePreroll(ticket)
65                         rpc.setTicketDone(str(ticket_id), url, token, host, secret)
66                 except:
67                         error = str(traceback.format_exc())
68                         print(colored(error, 'red'))
69                         rpc.setTicketFailed(str(ticket_id), error, url, token, host, secret)
70         
71         else:
72                 print('No ticket found')
73         
74         print('Sleeping for 30 seconds')
75         time.sleep(30);
76