Added indexed lists and link edition in tunes
This commit is contained in:
32
folkugat_web/services/temes/links.py
Normal file
32
folkugat_web/services/temes/links.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
IMAGE_FORMATS_RE = "|".join([
|
||||
'jpg', 'jpeg', 'png'
|
||||
])
|
||||
|
||||
LINK_RES = {
|
||||
model.LinkType.IMAGE: [
|
||||
re.compile(rf"^.*\.({IMAGE_FORMATS_RE})$")
|
||||
],
|
||||
model.LinkType.PDF: [
|
||||
re.compile(r"^.*\.pdf$")
|
||||
],
|
||||
model.LinkType.SPOTIFY: [
|
||||
re.compile(r"^.*spotify\.com.*$")
|
||||
],
|
||||
model.LinkType.YOUTUBE: [
|
||||
re.compile(r"^.*youtube\.com.*$"),
|
||||
re.compile(r"^.*youtu\.be.*$"),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def guess_link_type(url: str) -> Optional[model.LinkType]:
|
||||
for link_type, regexes in LINK_RES.items():
|
||||
for regex in regexes:
|
||||
if regex.match(url):
|
||||
return link_type
|
||||
return None
|
||||
Reference in New Issue
Block a user