commit
5b3204bd26
@ -165,6 +165,9 @@ class Variable:
|
|||||||
return bool(int(self._value))
|
return bool(int(self._value))
|
||||||
|
|
||||||
def as_string(self) -> str:
|
def as_string(self) -> str:
|
||||||
|
if self._value is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
return str(self._value)
|
return str(self._value)
|
||||||
|
|
||||||
def as_int(self) -> int:
|
def as_int(self) -> int:
|
||||||
|
|||||||
52
src/utils.py
52
src/utils.py
@ -3,7 +3,6 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from urllib.parse import urlparse, parse_qs
|
|
||||||
from typing import Optional, List, Dict
|
from typing import Optional, List, Dict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from cron_descriptor import ExpressionDescriptor
|
from cron_descriptor import ExpressionDescriptor
|
||||||
@ -159,21 +158,40 @@ def get_ip_address() -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def regex_search(pattern: str, string: str, group: int):
|
||||||
|
"""Shortcut method to search a string for a given pattern.
|
||||||
|
:param str pattern:
|
||||||
|
A regular expression pattern.
|
||||||
|
:param str string:
|
||||||
|
A target string to search.
|
||||||
|
:param int group:
|
||||||
|
Index of group to return.
|
||||||
|
:rtype:
|
||||||
|
str or tuple
|
||||||
|
:returns:
|
||||||
|
Substring pattern matches.
|
||||||
|
"""
|
||||||
|
regex = re.compile(pattern)
|
||||||
|
results = regex.search(string)
|
||||||
|
if not results:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return results.group(group)
|
||||||
|
|
||||||
|
|
||||||
def get_yt_video_id(url: str) -> str:
|
def get_yt_video_id(url: str) -> str:
|
||||||
if not url.startswith('http'):
|
if len(url) <= 14:
|
||||||
url = 'http://' + url
|
return url
|
||||||
|
|
||||||
query = urlparse(url)
|
"""Extract the ``video_id`` from a YouTube url.
|
||||||
|
This function supports the following patterns:
|
||||||
try:
|
- :samp:`https://youtube.com/watch?v={video_id}`
|
||||||
if 'youtube' in query.hostname:
|
- :samp:`https://youtube.com/embed/{video_id}`
|
||||||
if query.path == '/watch':
|
- :samp:`https://youtu.be/{video_id}`
|
||||||
return parse_qs(query.query)['v'][0]
|
:param str url:
|
||||||
elif query.path.startswith(('/embed/', '/v/')):
|
A YouTube url containing a video id.
|
||||||
return query.path.split('/')[2]
|
:rtype: str
|
||||||
elif 'youtu.be' in query.hostname:
|
:returns:
|
||||||
return query.path[1:]
|
YouTube video id.
|
||||||
except:
|
"""
|
||||||
return ''
|
return regex_search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url, group=1)
|
||||||
|
|
||||||
return ''
|
|
||||||
|
|||||||
@ -33,10 +33,12 @@
|
|||||||
<i class="fa fa-sort icon-left"></i>
|
<i class="fa fa-sort icon-left"></i>
|
||||||
</a>
|
</a>
|
||||||
{% set icon_type = 'globe' %}
|
{% set icon_type = 'globe' %}
|
||||||
{% if slide.type == 'video' %}
|
{% if slide.type == enum_slide_type.VIDEO %}
|
||||||
{% set icon_type = 'video' %}
|
{% set icon_type = 'film' %}
|
||||||
{% elif slide.type == 'picture' %}
|
{% elif slide.type == enum_slide_type.PICTURE %}
|
||||||
{% set icon_type = 'image' %}
|
{% set icon_type = 'image' %}
|
||||||
|
{% elif slide.type == enum_slide_type.YOUTUBE %}
|
||||||
|
{% set icon_type = 'video' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<i class="fa fa-{{ icon_type }} icon-left"></i>
|
<i class="fa fa-{{ icon_type }} icon-left"></i>
|
||||||
@ -79,15 +81,21 @@
|
|||||||
<a href="javascript:void(0);" class="item-edit slide-edit">
|
<a href="javascript:void(0);" class="item-edit slide-edit">
|
||||||
<i class="fa fa-pencil"></i>
|
<i class="fa fa-pencil"></i>
|
||||||
</a>
|
</a>
|
||||||
{% if not fleet_mode or not slide.has_file() %}
|
|
||||||
<a href="{{ slide.location }}" class="item-download slide-download" target="_blank">
|
{% set location = slide.location %}
|
||||||
<i class="fa fa-eye"></i>
|
|
||||||
</a>
|
{% if var_external_url.as_string().strip()|length > 0 and slide.has_file() %}
|
||||||
{% elif var_external_url.value|length > 0 %}
|
{% set location = var_external_url.value ~ '/' ~ slide.location %}
|
||||||
<a href="{{ var_external_url.value }}/{{ slide.location }}" class="item-download slide-download" target="_blank">
|
|
||||||
<i class="fa fa-eye"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if slide.type == enum_slide_type.YOUTUBE %}
|
||||||
|
{% set location = 'https://www.youtube.com/watch?v=' ~ slide.location %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<a href="{{ location }}" class="item-download slide-download" target="_blank">
|
||||||
|
<i class="fa fa-eye"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
<a href="javascript:void(0);" class="item-delete slide-delete">
|
<a href="javascript:void(0);" class="item-delete slide-delete">
|
||||||
<i class="fa fa-trash"></i>
|
<i class="fa fa-trash"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user