Last active
December 12, 2019 07:13
-
-
Save frozenpandaman/83628812635abcec9c1766545087660c to your computer and use it in GitHub Desktop.
Upload all .mp4 files in a directory to Streamable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 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
Is there any way that you could auto delete the video from the folder after the streamable shortcode is given?