Skip to content

Commit

Permalink
- Fix pytube - newer version not putting .mp4 on filenames automatica…
Browse files Browse the repository at this point in the history
…lly.
  • Loading branch information
frankyrumple committed Sep 18, 2021
1 parent b481381 commit 22e8fc6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
3 changes: 2 additions & 1 deletion modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests
requests=2.25.1 # Needed by streamlink
ldap3 # python-ldap
paramiko
ecdsa
Expand All @@ -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
8 changes: 8 additions & 0 deletions scratch.py
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down
62 changes: 62 additions & 0 deletions web2py/applications/smc/controllers/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.<DOMAIN>/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():
Expand Down
4 changes: 2 additions & 2 deletions web2py/applications/smc/models/x_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 22e8fc6

Please sign in to comment.