From 22e8fc62bcda59171cdb6f8c78458d4fe028689a Mon Sep 17 00:00:00 2001 From: Raymond Pulsipher Date: Sat, 18 Sep 2021 12:45:01 -0700 Subject: [PATCH] - Fix pytube - newer version not putting .mp4 on filenames automatically. --- modules.txt | 3 +- scratch.py | 8 +++ web2py/applications/smc/controllers/test.py | 62 +++++++++++++++++++ web2py/applications/smc/models/x_scheduler.py | 4 +- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/modules.txt b/modules.txt index ac04bdd9..b355ea26 100644 --- a/modules.txt +++ b/modules.txt @@ -1,4 +1,4 @@ -requests +requests=2.25.1 # Needed by streamlink ldap3 # python-ldap paramiko ecdsa @@ -22,3 +22,4 @@ bs4 weasyprint # see additional notes https://weasyprint.readthedocs.io/en/stable/install.html # apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf-dev lxml +streamlink diff --git a/scratch.py b/scratch.py index 78b05e91..c9575d9e 100644 --- a/scratch.py +++ b/scratch.py @@ -1,4 +1,12 @@ +""" +Links to canvas resources + +https://github.com/ucfopen/canvasapi +https://github.com/unsupported/canvas/tree/master/canvas_data/sync_canvas_data/python + +""" + def dom_test(): html = """ diff --git a/web2py/applications/smc/controllers/test.py b/web2py/applications/smc/controllers/test.py index 97e74edf..84af2c8d 100644 --- a/web2py/applications/smc/controllers/test.py +++ b/web2py/applications/smc/controllers/test.py @@ -30,6 +30,68 @@ import module_reload ret = module_reload.ReloadModules() +@auth.requires_membership("Administrators") +def test_youtube(): + response.view = 'generic.json' + ret = dict() + + + yt_url = "https://www.youtube.com/watch?v=jAMGMKlBSV0" + + yt, stream, res = find_best_yt_stream(yt_url) + ret['yt'] = str(yt) + ret['stream'] = str(stream) + ret['res'] = str(res) + + (w2py_folder, applications_folder, app_folder) = get_app_folders() + target_folder = os.path.join(app_folder, 'static', 'media') + output_mp4_filename = "test.mp4" + + print("Downloading " + str(yt_url)+"\n\n") + stream.download(output_path=target_folder, filename=output_mp4_filename) # put in folder name + print("\nDownload Complete!") + + return ret + + +@auth.requires_membership("Administrators") +def test_imscc_import(): + response.view = 'generic.json' + + if Canvas.Connect() is not True: + return dict(error="Couldn't Connect to Canvas!") + + #access_token = AppSettings.GetValue('canvas_access_token', '') + import urllib + + source_url = "http://gateway./migrations/" + urllib.parse.quote("course_file.imscc") + course_id = "502033000000079" + + p = dict() + p["migration_type"] = "canvas_cartridge_importer" + p["settings[file_url]"] = source_url + + new_migration = None + new_migration = Canvas.APICall(Canvas._canvas_server_url, Canvas._canvas_access_token, + "/api/v1/courses/" + course_id + "/content_migrations", + method="POST", params=p) + + ret = dict() + ret["url"] = Canvas._canvas_server_url + ret["output"] = str(new_migration) + + return ret + +@auth.requires_membership("Administrators") +def test_streamlink(): + import streamlink + + streams = streamlink.streams("https://www.youtube.com/watch?v=T9gewxW9zVY") + trys = ['720p', '360p', 'best', 'worst'] + stream = streams['720p'] + + + return dict(s=stream) @auth.requires_membership("Administrators") def test_yt_proxies(): diff --git a/web2py/applications/smc/models/x_scheduler.py b/web2py/applications/smc/models/x_scheduler.py index 1391fa06..5e418255 100644 --- a/web2py/applications/smc/models/x_scheduler.py +++ b/web2py/applications/smc/models/x_scheduler.py @@ -148,7 +148,7 @@ def process_media_file(media_id): # Find number of CPUs cpus = int(multiprocessing.cpu_count()) # Drop the number of threads so we don't use up all CPU power - cpus -= 2 + cpus -= 3 # W 4 cpus, use only one, always leave 3 for processing if available. if cpus < 1: cpus = 1 @@ -463,7 +463,7 @@ def pull_youtube_video(yt_url, media_guid): target_file = os.path.join(target_folder, file_guid).replace("\\", "/") output_mp4 = target_file + ".mp4" - output_mp4_filename = file_guid # Note - don't add mp4 as yt will do that + output_mp4_filename = file_guid + ".mp4" # Note - NOT -it quits adding it? - don't add mp4 as yt will do that output_meta = target_file + ".json" output_poster = target_file + ".poster.png" output_thumb = target_file + ".thumb.png"