mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
e78b2bdb90
commit
46e8eb7244
144
webapp_media.py
144
webapp_media.py
|
|
@ -14,17 +14,17 @@ from utils import valid_url_prefix
|
||||||
def load_peertube_instances(base_dir: str, peertube_instances: []) -> None:
|
def load_peertube_instances(base_dir: str, peertube_instances: []) -> None:
|
||||||
"""Loads peertube instances from file into the given list
|
"""Loads peertube instances from file into the given list
|
||||||
"""
|
"""
|
||||||
peertubeList = None
|
peertube_list = None
|
||||||
peertube_instancesFilename = base_dir + '/accounts/peertube.txt'
|
peertube_instances_filename = base_dir + '/accounts/peertube.txt'
|
||||||
if os.path.isfile(peertube_instancesFilename):
|
if os.path.isfile(peertube_instances_filename):
|
||||||
with open(peertube_instancesFilename, 'r') as fp:
|
with open(peertube_instances_filename, 'r') as fp_inst:
|
||||||
peertubeStr = fp.read()
|
peertube_str = fp_inst.read()
|
||||||
if peertubeStr:
|
if peertube_str:
|
||||||
peertubeStr = peertubeStr.replace('\r', '')
|
peertube_str = peertube_str.replace('\r', '')
|
||||||
peertubeList = peertubeStr.split('\n')
|
peertube_list = peertube_str.split('\n')
|
||||||
if not peertubeList:
|
if not peertube_list:
|
||||||
return
|
return
|
||||||
for url in peertubeList:
|
for url in peertube_list:
|
||||||
if url in peertube_instances:
|
if url in peertube_instances:
|
||||||
continue
|
continue
|
||||||
peertube_instances.append(url)
|
peertube_instances.append(url)
|
||||||
|
|
@ -48,9 +48,9 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
"fullscreen\" allowfullscreen></iframe>\n</center>\n"
|
"fullscreen\" allowfullscreen></iframe>\n</center>\n"
|
||||||
return content
|
return content
|
||||||
|
|
||||||
videoSite = 'https://www.youtube.com'
|
video_site = 'https://www.youtube.com'
|
||||||
if '"' + videoSite in content:
|
if '"' + video_site in content:
|
||||||
url = content.split('"' + videoSite)[1]
|
url = content.split('"' + video_site)[1]
|
||||||
if '"' in url:
|
if '"' in url:
|
||||||
url = url.split('"')[0].replace('/watch?v=', '/embed/')
|
url = url.split('"')[0].replace('/watch?v=', '/embed/')
|
||||||
if '&' in url:
|
if '&' in url:
|
||||||
|
|
@ -59,27 +59,29 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
url = url.split('?utm_')[0]
|
url = url.split('?utm_')[0]
|
||||||
content = \
|
content = \
|
||||||
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
||||||
videoSite + url + "\" width=\"" + str(width) + \
|
video_site + url + "\" width=\"" + str(width) + \
|
||||||
"\" height=\"" + str(height) + \
|
"\" height=\"" + str(height) + \
|
||||||
"\" frameborder=\"0\" allow=\"autoplay; fullscreen\" " + \
|
"\" frameborder=\"0\" allow=\"autoplay; fullscreen\" " + \
|
||||||
"allowfullscreen></iframe>\n</center>\n"
|
"allowfullscreen></iframe>\n</center>\n"
|
||||||
return content
|
return content
|
||||||
|
|
||||||
invidiousSites = ('https://invidious.snopyta.org',
|
invidious_sites = (
|
||||||
'https://yewtu.be',
|
'https://invidious.snopyta.org',
|
||||||
'https://tube.connect.cafe',
|
'https://yewtu.be',
|
||||||
'https://invidious.kavin.rocks',
|
'https://tube.connect.cafe',
|
||||||
'https://invidiou.site',
|
'https://invidious.kavin.rocks',
|
||||||
'https://invidious.tube',
|
'https://invidiou.site',
|
||||||
'https://invidious.xyz',
|
'https://invidious.tube',
|
||||||
'https://invidious.zapashcanon.fr',
|
'https://invidious.xyz',
|
||||||
'http://c7hqkpkpemu6e7emz5b4vy' +
|
'https://invidious.zapashcanon.fr',
|
||||||
'z7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion',
|
'http://c7hqkpkpemu6e7emz5b4vy' +
|
||||||
'http://axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4' +
|
'z7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion',
|
||||||
'bzzsg2ii4fv2iid.onion')
|
'http://axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4' +
|
||||||
for videoSite in invidiousSites:
|
'bzzsg2ii4fv2iid.onion'
|
||||||
if '"' + videoSite in content:
|
)
|
||||||
url = content.split('"' + videoSite)[1]
|
for video_site in invidious_sites:
|
||||||
|
if '"' + video_site in content:
|
||||||
|
url = content.split('"' + video_site)[1]
|
||||||
if '"' in url:
|
if '"' in url:
|
||||||
url = url.split('"')[0].replace('/watch?v=', '/embed/')
|
url = url.split('"')[0].replace('/watch?v=', '/embed/')
|
||||||
if '&' in url:
|
if '&' in url:
|
||||||
|
|
@ -88,22 +90,22 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
url = url.split('?utm_')[0]
|
url = url.split('?utm_')[0]
|
||||||
content = \
|
content = \
|
||||||
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
||||||
videoSite + url + "\" width=\"" + \
|
video_site + url + "\" width=\"" + \
|
||||||
str(width) + "\" height=\"" + str(height) + \
|
str(width) + "\" height=\"" + str(height) + \
|
||||||
"\" frameborder=\"0\" allow=\"autoplay; fullscreen\" " + \
|
"\" frameborder=\"0\" allow=\"autoplay; fullscreen\" " + \
|
||||||
"allowfullscreen></iframe>\n</center>\n"
|
"allowfullscreen></iframe>\n</center>\n"
|
||||||
return content
|
return content
|
||||||
|
|
||||||
videoSite = 'https://media.ccc.de'
|
video_site = 'https://media.ccc.de'
|
||||||
if '"' + videoSite in content:
|
if '"' + video_site in content:
|
||||||
url = content.split('"' + videoSite)[1]
|
url = content.split('"' + video_site)[1]
|
||||||
if '"' in url:
|
if '"' in url:
|
||||||
url = url.split('"')[0]
|
url = url.split('"')[0]
|
||||||
if not url.endswith('/oembed'):
|
if not url.endswith('/oembed'):
|
||||||
url = url + '/oembed'
|
url = url + '/oembed'
|
||||||
content = \
|
content = \
|
||||||
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
content + "<center>\n<iframe loading=\"lazy\" src=\"" + \
|
||||||
videoSite + url + "\" width=\"" + \
|
video_site + url + "\" width=\"" + \
|
||||||
str(width) + "\" height=\"" + str(height) + \
|
str(width) + "\" height=\"" + str(height) + \
|
||||||
"\" frameborder=\"0\" allow=\"fullscreen\" " + \
|
"\" frameborder=\"0\" allow=\"fullscreen\" " + \
|
||||||
"allowfullscreen></iframe>\n</center>\n"
|
"allowfullscreen></iframe>\n</center>\n"
|
||||||
|
|
@ -113,13 +115,13 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
if peertube_instances:
|
if peertube_instances:
|
||||||
# only create an embedded video for a limited set of
|
# only create an embedded video for a limited set of
|
||||||
# peertube sites.
|
# peertube sites.
|
||||||
peerTubeSites = peertube_instances
|
peertube_sites = peertube_instances
|
||||||
else:
|
else:
|
||||||
# A default minimal set of peertube instances
|
# A default minimal set of peertube instances
|
||||||
# Also see https://peertube_isolation.frama.io/list/ for
|
# Also see https://peertube_isolation.frama.io/list/ for
|
||||||
# adversarial instances. Nothing in that list should be
|
# adversarial instances. Nothing in that list should be
|
||||||
# in the defaults below.
|
# in the defaults below.
|
||||||
peerTubeSites = (
|
peertube_sites = (
|
||||||
'share.tube',
|
'share.tube',
|
||||||
'visionon.tv',
|
'visionon.tv',
|
||||||
'peertube.fr',
|
'peertube.fr',
|
||||||
|
|
@ -127,7 +129,7 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
'peertube.social',
|
'peertube.social',
|
||||||
'videos.lescommuns.org'
|
'videos.lescommuns.org'
|
||||||
)
|
)
|
||||||
for site in peerTubeSites:
|
for site in peertube_sites:
|
||||||
site = site.strip()
|
site = site.strip()
|
||||||
if not site:
|
if not site:
|
||||||
continue
|
continue
|
||||||
|
|
@ -135,19 +137,19 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
|
||||||
continue
|
continue
|
||||||
if '.' not in site:
|
if '.' not in site:
|
||||||
continue
|
continue
|
||||||
siteStr = site
|
site_str = site
|
||||||
if site.startswith('http://'):
|
if site.startswith('http://'):
|
||||||
site = site.replace('http://', '')
|
site = site.replace('http://', '')
|
||||||
elif site.startswith('https://'):
|
elif site.startswith('https://'):
|
||||||
site = site.replace('https://', '')
|
site = site.replace('https://', '')
|
||||||
if site.endswith('.onion') or site.endswith('.i2p'):
|
if site.endswith('.onion') or site.endswith('.i2p'):
|
||||||
siteStr = 'http://' + site
|
site_str = 'http://' + site
|
||||||
else:
|
else:
|
||||||
siteStr = 'https://' + site
|
site_str = 'https://' + site
|
||||||
siteStr = '"' + siteStr
|
site_str = '"' + site_str
|
||||||
if siteStr not in content:
|
if site_str not in content:
|
||||||
continue
|
continue
|
||||||
url = content.split(siteStr)[1]
|
url = content.split(site_str)[1]
|
||||||
if '"' not in url:
|
if '"' not in url:
|
||||||
continue
|
continue
|
||||||
url = url.split('"')[0].replace('/watch/', '/embed/')
|
url = url.split('"')[0].replace('/watch/', '/embed/')
|
||||||
|
|
@ -177,26 +179,26 @@ def _add_embedded_audio(translate: {}, content: str) -> str:
|
||||||
extension = '.ogg'
|
extension = '.ogg'
|
||||||
|
|
||||||
words = content.strip('\n').split(' ')
|
words = content.strip('\n').split(' ')
|
||||||
for w in words:
|
for wrd in words:
|
||||||
if extension not in w:
|
if extension not in wrd:
|
||||||
continue
|
continue
|
||||||
w = w.replace('href="', '').replace('">', '')
|
wrd = wrd.replace('href="', '').replace('">', '')
|
||||||
if w.endswith('.'):
|
if wrd.endswith('.'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith('"'):
|
if wrd.endswith('"'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith(';'):
|
if wrd.endswith(';'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith(':'):
|
if wrd.endswith(':'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if not w.endswith(extension):
|
if not wrd.endswith(extension):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not valid_url_prefix(w):
|
if not valid_url_prefix(wrd):
|
||||||
continue
|
continue
|
||||||
content += \
|
content += \
|
||||||
'<center>\n<audio controls>\n' + \
|
'<center>\n<audio controls>\n' + \
|
||||||
'<source src="' + w + '" type="audio/' + \
|
'<source src="' + wrd + '" type="audio/' + \
|
||||||
extension.replace('.', '') + '">' + \
|
extension.replace('.', '') + '">' + \
|
||||||
translate['Your browser does not support the audio element.'] + \
|
translate['Your browser does not support the audio element.'] + \
|
||||||
'</audio>\n</center>\n'
|
'</audio>\n</center>\n'
|
||||||
|
|
@ -219,28 +221,28 @@ def _add_embedded_video(translate: {}, content: str) -> str:
|
||||||
extension = '.ogv'
|
extension = '.ogv'
|
||||||
|
|
||||||
words = content.strip('\n').split(' ')
|
words = content.strip('\n').split(' ')
|
||||||
for w in words:
|
for wrd in words:
|
||||||
if extension not in w:
|
if extension not in wrd:
|
||||||
continue
|
continue
|
||||||
w = w.replace('href="', '').replace('">', '')
|
wrd = wrd.replace('href="', '').replace('">', '')
|
||||||
if w.endswith('.'):
|
if wrd.endswith('.'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith('"'):
|
if wrd.endswith('"'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith(';'):
|
if wrd.endswith(';'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if w.endswith(':'):
|
if wrd.endswith(':'):
|
||||||
w = w[:-1]
|
wrd = wrd[:-1]
|
||||||
if not w.endswith(extension):
|
if not wrd.endswith(extension):
|
||||||
continue
|
continue
|
||||||
if not valid_url_prefix(w):
|
if not valid_url_prefix(wrd):
|
||||||
continue
|
continue
|
||||||
content += \
|
content += \
|
||||||
'<center><figure id="videoContainer" ' + \
|
'<center><figure id="videoContainer" ' + \
|
||||||
'data-fullscreen="false">\n' + \
|
'data-fullscreen="false">\n' + \
|
||||||
' <video id="video" controls ' + \
|
' <video id="video" controls ' + \
|
||||||
'preload="metadata">\n' + \
|
'preload="metadata">\n' + \
|
||||||
'<source src="' + w + '" type="video/' + \
|
'<source src="' + wrd + '" type="video/' + \
|
||||||
extension.replace('.', '') + '">\n' + \
|
extension.replace('.', '') + '">\n' + \
|
||||||
translate['Your browser does not support the video element.'] + \
|
translate['Your browser does not support the video element.'] + \
|
||||||
'</video>\n</figure>\n</center>\n'
|
'</video>\n</figure>\n</center>\n'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue