Skip to content

Instantly share code, notes, and snippets.

@frozenpandaman
Last active December 12, 2019 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozenpandaman/83628812635abcec9c1766545087660c to your computer and use it in GitHub Desktop.
Save frozenpandaman/83628812635abcec9c1766545087660c to your computer and use it in GitHub Desktop.
Upload all .mp4 files in a directory to Streamable
#!/usr/bin/env python
import os, requests, json
from io import BytesIO
STREAMABLE_USERNAME = ""
STREAMABLE_PASSWORD = ""
DIRECTORY = ""
def main():
for filename in os.listdir(DIRECTORY):
if filename.endswith('.mp4'):
url = "https://api.streamable.com/upload"
in_file = open(os.path.join(DIRECTORY, filename), "rb")
data = in_file.read()
in_file.close()
file = BytesIO(data)
payload = { os.path.splitext(filename)[0]: file.getvalue() }
print("Uploading {}...".format(filename))
res = requests.post(url, files=payload, auth=(STREAMABLE_USERNAME, STREAMABLE_PASSWORD))
try:
print("Uploaded to https://streamable.com/{}".format(json.loads(res.text)["shortcode"]))
os.remove(os.path.join(DIRECTORY, filename))
except KeyError:
print("Error uploading.")
try:
wait = input("Waiting for keypress to continue...")
except KeyboardInterrupt:
print("\nExiting.")
exit(0)
print("Done!")
if __name__ == "__main__":
main()
@rmcmill9
Copy link

Is there any way that you could auto delete the video from the folder after the streamable shortcode is given?

@frozenpandaman
Copy link
Author

@rmcmill9 Sorry for the late reply! Sure – just involves adding one line. I updated the script and improved I/O a bit too. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment