changeset 71:a9776ed0538b

Create uploadafterdl.py committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Sun, 19 Jun 2022 04:20:21 -0400
parents eafe13de3f76
children 23d0073daa79
files uploadafterdl.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uploadafterdl.py	Sun Jun 19 04:20:21 2022 -0400
@@ -0,0 +1,37 @@
+from tubeup.TubeUp import TubeUp
+from yt_dlp.utils import sanitize_filename
+import glob
+import json
+import os
+
+tu = TubeUp()
+
+for basename in glob.glob('*.info.json'):
+    print(basename + " " + str(os.path.getsize(basename)))
+    if os.path.getsize(basename) != 0:
+        if not any(x in os.listdir(".") for x in [sanitize_filename(basename[:-10] + ".mp4", restricted=True),
+                                                sanitize_filename(basename[:-10] + ".mkv", restricted=True),
+                                                sanitize_filename(basename[:-10] + ".webm", restricted=True)]):
+            print("no video downloaded")
+            continue
+        with open(basename, "r", encoding="utf-8") as jf:
+            jsons = json.load(jf)
+        try:
+            jsons["extractor"]
+        except:
+            jsons["extractor"] = "youtube"
+        try:
+            jsons["display_id"] = jsons["id"]
+        except:
+            jsons["display_id"] = basename[:-10].split("-")[:-11]
+        try:
+            jsons["title"]
+        except:
+            jsons["title"] = jsons["fulltitle"]
+        jsons["webpage_url"] = "https://youtube.com/watch?v=%s" % jsons["display_id"]
+        jsons["extractor_key"] = "Youtube"
+        with open(basename, "w", encoding="utf-8") as jf:
+            jf.write(json.dumps(jsons))
+        identifier, meta, item_exists = tu.upload_ia(sanitize_filename(basename[:-10]))
+        print("%s, %s, %s" % (identifier, meta, item_exists))
+        print("uploaded %s" % basename)