a zerorpc server exposing prismedia, a video uploader to PeerTube and friends.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

5 years ago
  1. from __future__ import print_function
  2. from prismedia import upload import main as upload
  3. import sys
  4. import zerorpc
  5. class PrismediahedronAPI():
  6. prismedia =
  7. def upload(self, *args, **kwargs):
  8. """upload video using prismedia"""
  9. arguments = [
  10. self.prismedia,
  11. *args,
  12. *kwargs
  13. ]
  14. try:
  15. output = subprocess.check_output(
  16. arguments,
  17. stderr=subprocess.STDOUT)
  18. return uploader._geturl(output)
  19. except subprocess.CalledProcessError as cpe:
  20. print "cpe.returncode", cpe.returncode
  21. print "cpe.cmd", cpe.cmd
  22. print "cpe.output", cpe.output
  23. @staticmethod
  24. def _geturl(s):
  25. # the output contains much more than just the url
  26. cue = "Peertube: Watch it at "
  27. for line in s.split("\n"):
  28. if cue in line:
  29. # the url befins right after the cue. Between in url and the end of the line is a single ".",
  30. # which also needs to be remove
  31. return line.split(cue, 1)[1][:-1]
  32. def parse_port():
  33. port = 4242
  34. try:
  35. port = int(sys.argv[1])
  36. except Exception as e:
  37. pass
  38. return '{}'.format(port)
  39. def main():
  40. addr = 'tcp://127.0.0.1:' + parse_port()
  41. s = zerorpc.Server(PrismediahedronAPI())
  42. s.bind(addr)
  43. print('prismediahedron started on {}'.format(addr))
  44. s.run()
  45. if __name__ == '__main__':
  46. main()