__filename__ = "webapp_media.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.2.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Timeline"
import os
from utils import validUrlPrefix
def loadPeertubeInstances(base_dir: str, peertube_instances: []) -> None:
"""Loads peertube instances from file into the given list
"""
peertubeList = None
peertube_instancesFilename = base_dir + '/accounts/peertube.txt'
if os.path.isfile(peertube_instancesFilename):
with open(peertube_instancesFilename, 'r') as fp:
peertubeStr = fp.read()
if peertubeStr:
peertubeStr = peertubeStr.replace('\r', '')
peertubeList = peertubeStr.split('\n')
if not peertubeList:
return
for url in peertubeList:
if url in peertube_instances:
continue
peertube_instances.append(url)
def _addEmbeddedVideoFromSites(translate: {}, content: str,
peertube_instances: [],
width: int, height: int) -> str:
"""Adds embedded videos
"""
if '>vimeo.com/' in content:
url = content.split('>vimeo.com/')[1]
if '<' in url:
url = url.split('<')[0]
content = \
content + "
\n\n
\n"
return content
videoSite = 'https://www.youtube.com'
if '"' + videoSite in content:
url = content.split('"' + videoSite)[1]
if '"' in url:
url = url.split('"')[0].replace('/watch?v=', '/embed/')
if '&' in url:
url = url.split('&')[0]
if '?utm_' in url:
url = url.split('?utm_')[0]
content = \
content + "
\n\n
\n"
return content
invidiousSites = ('https://invidious.snopyta.org',
'https://yewtu.be',
'https://tube.connect.cafe',
'https://invidious.kavin.rocks',
'https://invidiou.site',
'https://invidious.tube',
'https://invidious.xyz',
'https://invidious.zapashcanon.fr',
'http://c7hqkpkpemu6e7emz5b4vy' +
'z7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion',
'http://axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4' +
'bzzsg2ii4fv2iid.onion')
for videoSite in invidiousSites:
if '"' + videoSite in content:
url = content.split('"' + videoSite)[1]
if '"' in url:
url = url.split('"')[0].replace('/watch?v=', '/embed/')
if '&' in url:
url = url.split('&')[0]
if '?utm_' in url:
url = url.split('?utm_')[0]
content = \
content + "
\n\n
\n"
return content
videoSite = 'https://media.ccc.de'
if '"' + videoSite in content:
url = content.split('"' + videoSite)[1]
if '"' in url:
url = url.split('"')[0]
if not url.endswith('/oembed'):
url = url + '/oembed'
content = \
content + "
\n\n
\n"
return content
if '"https://' in content:
if peertube_instances:
# only create an embedded video for a limited set of
# peertube sites.
peerTubeSites = peertube_instances
else:
# A default minimal set of peertube instances
# Also see https://peertube_isolation.frama.io/list/ for
# adversarial instances. Nothing in that list should be
# in the defaults below.
peerTubeSites = ('share.tube',
'visionon.tv',
'peertube.fr',
'kolektiva.media',
'peertube.social',
'videos.lescommuns.org')
for site in peerTubeSites:
site = site.strip()
if not site:
continue
if len(site) < 5:
continue
if '.' not in site:
continue
siteStr = site
if site.startswith('http://'):
site = site.replace('http://', '')
elif site.startswith('https://'):
site = site.replace('https://', '')
if site.endswith('.onion') or site.endswith('.i2p'):
siteStr = 'http://' + site
else:
siteStr = 'https://' + site
siteStr = '"' + siteStr
if siteStr not in content:
continue
url = content.split(siteStr)[1]
if '"' not in url:
continue
url = url.split('"')[0].replace('/watch/', '/embed/')
content = \
content + "
\n\n
\n"
return content
return content
def _addEmbeddedAudio(translate: {}, content: str) -> str:
"""Adds embedded audio for mp3/ogg
"""
if not ('.mp3' in content or '.ogg' in content):
return content
if '