@ -500,13 +500,17 @@ class TranscodeChecker(object):
return result . rowcount
return result . rowcount
def main ( dbconnect , youtube_ creds_file, name = None , base_dir = " . " , metrics_port = 8003 , backdoor_port = 0 , upload_location = " " ) :
def main ( dbconnect , config, creds_file, name = None , base_dir = " . " , metrics_port = 8003 , backdoor_port = 0 ) :
""" dbconnect should be a postgres connection string, which is either a space-separated
""" dbconnect should be a postgres connection string, which is either a space-separated
list of key = value pairs , or a URI like :
list of key = value pairs , or a URI like :
postgresql : / / USER : PASSWORD @HOST / DBNAME ? KEY = VALUE
postgresql : / / USER : PASSWORD @HOST / DBNAME ? KEY = VALUE
youtube_creds_file should be a json file containing keys ' client_id ' , ' client_secret ' and ' refresh_token ' .
config should be a json blob mapping upload location names to a config object
upload_location is the name of the upload location this youtube creds file gives access to .
for that location . This config object should contain the keys :
type : the name of the upload backend type
along with any additional config options defined for that backend type .
creds_file should contain any required credentials for the upload backends , as JSON .
name defaults to hostname .
name defaults to hostname .
"""
"""
@ -538,25 +542,36 @@ def main(dbconnect, youtube_creds_file, name=None, base_dir=".", metrics_port=80
logging . info ( ' Cannot connect to database. Retrying in {:.0f} s ' . format ( delay ) )
logging . info ( ' Cannot connect to database. Retrying in {:.0f} s ' . format ( delay ) )
stop . wait ( delay )
stop . wait ( delay )
youtube_creds = json . load ( open ( youtube_creds_file ) )
with open ( creds_file ) as f :
youtube = Youtube (
credentials = json . load ( f )
client_id = youtube_creds [ ' client_id ' ] ,
client_secret = youtube_creds [ ' client_secret ' ] ,
config = json . loads ( config )
refresh_token = youtube_creds [ ' refresh_token ' ] ,
upload_locations = { }
)
for location , backend_config in config . items ( ) :
cutter = Cutter ( { upload_location : youtube } , dbmanager , stop , name , base_dir )
backend_type = backend_config . pop ( ' type ' )
transcode_checker = TranscodeChecker ( youtube , dbmanager , stop )
if type == ' youtube ' :
jobs = [
backend_type = Youtube
gevent . spawn ( cutter . run ) ,
else :
gevent . spawn ( transcode_checker . run ) ,
raise ValueError ( " Unknown upload backend type: {!r} " . format ( type ) )
upload_locations [ location ] = backend_type ( credentials , * * backend_config )
cutter = Cutter ( upload_locations , dbmanager , stop , name , base_dir )
transcode_checkers = [
TranscodeChecker ( backend , dbmanager , stop )
for backend in upload_locations . values ( )
if backend . needs_transcode
]
jobs = [ gevent . spawn ( cutter . run ) ] + [
gevent . spawn ( transcode_checker . run )
for transcode_checker in transcode_checkers
]
]
# Block until either exits
# Block until any on e exits
gevent . wait ( jobs , count = 1 )
gevent . wait ( jobs , count = 1 )
# Stop the other if it isn't stopping already
# Stop the other s if they are n't stopping already
stop . set ( )
stop . set ( )
# Block until both have exited
# Block until all have exited
gevent . wait ( jobs )
gevent . wait ( jobs )
# Call get() for each to re-raise if either errored
# Call get() for each one to re-raise if any errored
for job in jobs :
for job in jobs :
job . get ( )
job . get ( )