Added possible fallback for playlist incase filename got changed.
This commit is contained in:
parent
0cd36ea4be
commit
7a5a06219c
3 changed files with 42 additions and 2 deletions
31
app/Utils.py
31
app/Utils.py
|
|
@ -4,6 +4,8 @@ from datetime import datetime, timezone
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
from socketio import AsyncServer
|
from socketio import AsyncServer
|
||||||
|
|
@ -388,3 +390,32 @@ def load_file(file: str, check_type=None) -> tuple[dict | list, bool, str]:
|
||||||
return ({}, False, f"Failed to assert that the contents '{type(opts)}' are of type '{check_type}'.",)
|
return ({}, False, f"Failed to assert that the contents '{type(opts)}' are of type '{check_type}'.",)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return ({}, False, f'{e}',)
|
return ({}, False, f'{e}',)
|
||||||
|
|
||||||
|
|
||||||
|
def checkId(basePath: str, file: pathlib.Path) -> bool | str:
|
||||||
|
"""
|
||||||
|
Check if we are able to get an id from the file name.
|
||||||
|
if so check if any video file with the same id exists.
|
||||||
|
|
||||||
|
:param basePath: Base path to strip.
|
||||||
|
:param file: File to check.
|
||||||
|
|
||||||
|
:return: False if no id found, otherwise the id.
|
||||||
|
"""
|
||||||
|
|
||||||
|
match = re.search(r'(?<=\[)(?:youtube-)?(?P<id>[a-zA-Z0-9\-_]{11})(?=\])', file.stem, re.IGNORECASE)
|
||||||
|
if not match:
|
||||||
|
return False
|
||||||
|
|
||||||
|
id = match.groupdict().get('id')
|
||||||
|
|
||||||
|
for f in file.parent.iterdir():
|
||||||
|
if id not in f.stem:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if f.suffix not in ('.mp4', '.mkv', '.webm', '.m4v', '.m4a', '.mp3', '.aac', '.ogg',):
|
||||||
|
continue
|
||||||
|
|
||||||
|
return f.absolute()
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
|
||||||
|
|
@ -465,6 +465,8 @@ class Main:
|
||||||
download_path=self.config.download_path,
|
download_path=self.config.download_path,
|
||||||
file=file
|
file=file
|
||||||
)
|
)
|
||||||
|
if isinstance(text, Response):
|
||||||
|
return text
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return web.HTTPNotFound(reason=str(e))
|
return web.HTTPNotFound(reason=str(e))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from Utils import calcDownloadPath
|
||||||
import pathlib
|
import pathlib
|
||||||
from .ffprobe import FFProbe
|
from .ffprobe import FFProbe
|
||||||
from .Subtitle import Subtitle
|
from .Subtitle import Subtitle
|
||||||
|
from aiohttp.web import Response
|
||||||
|
|
||||||
|
|
||||||
class Playlist:
|
class Playlist:
|
||||||
|
|
@ -14,11 +15,17 @@ class Playlist:
|
||||||
def __init__(self, url: str):
|
def __init__(self, url: str):
|
||||||
self.url = url
|
self.url = url
|
||||||
|
|
||||||
async def make(self, download_path: str, file: str):
|
async def make(self, download_path: str, file: str) -> str | Response:
|
||||||
rFile = pathlib.Path(calcDownloadPath(basePath=download_path, folder=file, createPath=False))
|
rFile = pathlib.Path(calcDownloadPath(basePath=download_path, folder=file, createPath=False))
|
||||||
|
|
||||||
if not rFile.exists():
|
if not rFile.exists():
|
||||||
raise Exception(f"File '{rFile}' does not exist.")
|
possibleFile = self.checkId(download_path, rFile)
|
||||||
|
if not possibleFile:
|
||||||
|
raise Exception(f"File '{rFile}' does not exist.")
|
||||||
|
|
||||||
|
return Response(status=302, headers={
|
||||||
|
'Location': f"{self.url}player/playlist/{quote(possibleFile.replace(download_path, '').strip('/'))}.m3u8"
|
||||||
|
})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ffprobe = FFProbe(rFile)
|
ffprobe = FFProbe(rFile)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue