|
|
- from __future__ import print_function
- from prismedia import upload import main as upload
-
- import sys
- import zerorpc
-
-
- class PrismediahedronAPI():
- prismedia =
-
- def upload(self, *args, **kwargs):
- """upload video using prismedia"""
- arguments = [
- self.prismedia,
- *args,
- *kwargs
- ]
-
- try:
- output = subprocess.check_output(
- arguments,
- stderr=subprocess.STDOUT)
-
- return uploader._geturl(output)
-
- except subprocess.CalledProcessError as cpe:
- print "cpe.returncode", cpe.returncode
- print "cpe.cmd", cpe.cmd
- print "cpe.output", cpe.output
-
- @staticmethod
- def _geturl(s):
- # the output contains much more than just the url
- cue = "Peertube: Watch it at "
- for line in s.split("\n"):
- if cue in line:
- # the url befins right after the cue. Between in url and the end of the line is a single ".",
- # which also needs to be remove
- return line.split(cue, 1)[1][:-1]
-
-
- def parse_port():
- port = 4242
- try:
- port = int(sys.argv[1])
- except Exception as e:
- pass
- return '{}'.format(port)
-
-
- def main():
- addr = 'tcp://127.0.0.1:' + parse_port()
- s = zerorpc.Server(PrismediahedronAPI())
- s.bind(addr)
- print('prismediahedron started on {}'.format(addr))
- s.run()
-
-
- if __name__ == '__main__':
- main()
|