panosteal/youtubesteal/__init__.py

72 lines
2 KiB
Python
Raw Normal View History

2019-02-18 16:23:47 +00:00
import PIL.Image
import urllib.request
import io
import math
import subprocess
import tempfile
import pathlib
import os
import subprocess
import uuid
import glob
from stitching import tiles_to_equirectangular_blender, multistitch
def youtube_get_video(url):
vid = uuid.uuid4().hex
2020-05-02 11:24:31 +00:00
with open("/tmp/" + vid, "w") as logfile:
process = subprocess.Popen(
['youtube-dl',
'--user-agent', '""',
'-o', vid,
"--merge-output-format", "mkv",
url,
],
cwd="/tmp/panosteal/youtube/",
stdout=logfile,
stderr=logfile
)
2019-02-18 16:23:47 +00:00
2020-05-02 11:24:31 +00:00
process.wait()
2019-02-18 16:23:47 +00:00
2020-05-02 11:24:31 +00:00
try:
data = open('/tmp/panosteal/youtube/%s.mkv' % vid, 'rb').read()
except:
try:
data = open('/tmp/panosteal/youtube/%s.mp4' % vid, 'rb').read()
except:
try:
data = open('/tmp/panosteal/youtube/%s.webm' % vid, 'rb').read()
process2 = subprocess.Popen(
['ffmpeg',
'-i', '%s.webm' % vid,
'-c:v', "copy",
'%s.mkv' % vid],
cwd="/tmp/panosteal/youtube/"
)
except:
raise
2019-02-18 16:23:47 +00:00
for i in glob.glob("/tmp/panosteal/youtube/%s*" % vid):
os.remove(i)
return data
def youtube_get_file(yurl):
urllib.request.urlopen(yurl)
def youtube_to_equirectangular(url, rotation=[0,0,0], resolution=[3840,1920]):
'''
Takes the URL of any YouTube video, downloads it and returns the video file.
:param url: YouTube URL
:return: File object containing the video
'''
rx, ry, rz = rotation
width, height = resolution
return youtube_get_video(url)
process_url = youtube_to_equirectangular