Check that video site has a path

merge-requests/30/head
Bob Mottram 2022-11-07 11:15:08 +00:00
parent cd442d1415
commit 903bedbf01
1 changed files with 36 additions and 31 deletions

View File

@ -63,17 +63,18 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
url = content.split('>vimeo.com/')[1] url = content.split('>vimeo.com/')[1]
if '<' in url: if '<' in url:
url = url.split('<')[0] url = url.split('<')[0]
content += \ if url:
"<center>\n<span itemprop=\"video\">\n" + \ content += \
"<iframe loading=\"lazy\" decoding=\"async\" " + \ "<center>\n<span itemprop=\"video\">\n" + \
"src=\"https://player.vimeo.com/video/" + \ "<iframe loading=\"lazy\" decoding=\"async\" " + \
url + "\" width=\"" + str(width) + \ "src=\"https://player.vimeo.com/video/" + \
"\" height=\"" + str(height) + \ url + "\" width=\"" + str(width) + \
"\" frameborder=\"0\" allow=\"" + \ "\" height=\"" + str(height) + \
"fullscreen\" allowfullscreen " + \ "\" frameborder=\"0\" allow=\"" + \
"tabindex=\"10\"></iframe>\n" + \ "fullscreen\" allowfullscreen " + \
"</span>\n</center>\n" "tabindex=\"10\"></iframe>\n" + \
return content "</span>\n</center>\n"
return content
video_site = 'https://www.youtube.com' video_site = 'https://www.youtube.com'
if 'https://m.youtube.com' in content: if 'https://m.youtube.com' in content:
@ -82,7 +83,7 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
url = content.split('"' + video_site)[1] url = content.split('"' + video_site)[1]
if '"' in url: if '"' in url:
url = url.split('"')[0] url = url.split('"')[0]
if '/channel/' not in url and '/playlist' not in url: if url and '/channel/' not in url and '/playlist' not in url:
url = url.replace('/watch?v=', '/embed/') url = url.replace('/watch?v=', '/embed/')
if '&' in url: if '&' in url:
url = url.split('&')[0] url = url.split('&')[0]
@ -104,7 +105,7 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
url = content.split('"' + video_site)[1] url = content.split('"' + video_site)[1]
if '"' in url: if '"' in url:
url = url.split('"')[0] url = url.split('"')[0]
if '/channel/' not in url and '/playlist' not in url: if url and '/channel/' not in url and '/playlist' not in url:
url = 'embed/' + url url = 'embed/' + url
if '&' in url: if '&' in url:
url = url.split('&')[0] url = url.split('&')[0]
@ -140,7 +141,10 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
if '"' + video_site in content: if '"' + video_site in content:
url = content.split('"' + video_site)[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]
if not url:
continue
url = url.replace('/watch?v=', '/embed/')
if '&' in url: if '&' in url:
url = url.split('&')[0] url = url.split('&')[0]
if '?utm_' in url: if '?utm_' in url:
@ -174,23 +178,24 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
url = content.split('"' + video_site)[1] url = content.split('"' + video_site)[1]
if '"' in url: if '"' in url:
url = url.split('"')[0] url = url.split('"')[0]
video_site_settings = '' if url:
if '#' in url: video_site_settings = ''
video_site_settings = '#' + url.split('#', 1)[1] if '#' in url:
url = url.split('#')[0] video_site_settings = '#' + url.split('#', 1)[1]
if not url.endswith('/oembed'): url = url.split('#')[0]
url = url + '/oembed' if not url.endswith('/oembed'):
url += video_site_settings url = url + '/oembed'
content += \ url += video_site_settings
"<center>\n<span itemprop=\"video\">\n" + \ content += \
"<iframe loading=\"lazy\" " + \ "<center>\n<span itemprop=\"video\">\n" + \
"decoding=\"async\" src=\"" + \ "<iframe loading=\"lazy\" " + \
video_site + url + "\" width=\"" + \ "decoding=\"async\" src=\"" + \
str(width) + "\" height=\"" + str(height) + \ video_site + url + "\" width=\"" + \
"\" frameborder=\"0\" allow=\"fullscreen\" " + \ str(width) + "\" height=\"" + str(height) + \
"allowfullscreen tabindex=\"10\"></iframe>\n" + \ "\" frameborder=\"0\" allow=\"fullscreen\" " + \
"</span>\n</center>\n" "allowfullscreen tabindex=\"10\"></iframe>\n" + \
return content "</span>\n</center>\n"
return content
if '"https://' in content: if '"https://' in content:
if peertube_instances: if peertube_instances: