Improved playlist handling
This commit is contained in:
parent
d0630f7415
commit
a81ee127e9
2 changed files with 17 additions and 70 deletions
|
|
@ -206,11 +206,10 @@ class DownloadQueue(metaclass=Singleton):
|
||||||
LOG.error(f"Failed to cancel downloads. {e!s}")
|
LOG.error(f"Failed to cancel downloads. {e!s}")
|
||||||
|
|
||||||
async def _process_playlist(self, entry: dict, item: Item, already=None):
|
async def _process_playlist(self, entry: dict, item: Item, already=None):
|
||||||
if 1 == self.config.playlist_items_concurrency:
|
|
||||||
return await self._process_playlist_old(entry=entry, item=item, already=already)
|
|
||||||
|
|
||||||
LOG.info(f"Playlist '{entry.get('id')}: {entry.get('title')}' processing.")
|
|
||||||
entries = entry.get("entries", [])
|
entries = entry.get("entries", [])
|
||||||
|
|
||||||
|
LOG.info(f"Processing '{entry.get('id')}: {entry.get('title')}' Playlist.")
|
||||||
|
|
||||||
playlistCount = int(entry.get("playlist_count", len(entries)))
|
playlistCount = int(entry.get("playlist_count", len(entries)))
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
|
|
@ -227,60 +226,17 @@ class DownloadQueue(metaclass=Singleton):
|
||||||
if property in entry:
|
if property in entry:
|
||||||
extras[f"playlist_{property}"] = entry.get(property)
|
extras[f"playlist_{property}"] = entry.get(property)
|
||||||
|
|
||||||
LOG.debug(f"Processing entry {i}/{playlistCount} - ID: {etr.get('id')} - Title: {etr.get('title')}")
|
|
||||||
|
|
||||||
if "thumbnail" not in etr and "youtube:" in entry.get("extractor", ""):
|
if "thumbnail" not in etr and "youtube:" in entry.get("extractor", ""):
|
||||||
extras["thumbnail"] = f"https://img.youtube.com/vi/{etr['id']}/maxresdefault.jpg"
|
extras["thumbnail"] = f"https://img.youtube.com/vi/{etr['id']}/maxresdefault.jpg"
|
||||||
|
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
|
LOG.debug(f"Processing entry {i}/{playlistCount} - ID: {etr.get('id')} - Title: {etr.get('title')}")
|
||||||
return await self.add(
|
return await self.add(
|
||||||
item=item.new_with(url=etr.get("url") or etr.get("webpage_url"), extras=extras),
|
item=item.new_with(url=etr.get("url") or etr.get("webpage_url"), extras=extras),
|
||||||
already=already,
|
already=already,
|
||||||
)
|
)
|
||||||
|
|
||||||
tasks = [process_entry(i, etr) for i, etr in enumerate(entries, start=1)]
|
results = await asyncio.gather(*(process_entry(i, etr) for i, etr in enumerate(entries, start=1)))
|
||||||
results = await asyncio.gather(*tasks)
|
|
||||||
|
|
||||||
LOG.info(
|
|
||||||
f"Playlist '{entry.get('id')}: {entry.get('title')}' processing completed with '{len(results)}' entries."
|
|
||||||
)
|
|
||||||
|
|
||||||
if any("error" == res["status"] for res in results):
|
|
||||||
return {
|
|
||||||
"status": "error",
|
|
||||||
"msg": ", ".join(res["msg"] for res in results if res["status"] == "error" and "msg" in res),
|
|
||||||
}
|
|
||||||
|
|
||||||
return {"status": "ok"}
|
|
||||||
|
|
||||||
async def _process_playlist_old(self, entry: dict, item: Item, already=None):
|
|
||||||
LOG.info(f"Playlist '{entry.get('id')}: {entry.get('title')}' processing.")
|
|
||||||
entries = entry.get("entries", [])
|
|
||||||
playlistCount = int(entry.get("playlist_count", len(entries)))
|
|
||||||
results = []
|
|
||||||
|
|
||||||
for i, etr in enumerate(entries, start=1):
|
|
||||||
extras = {
|
|
||||||
"playlist": entry.get("id"),
|
|
||||||
"playlist_index": f"{{0:0{len(str(playlistCount))}d}}".format(i),
|
|
||||||
"playlist_autonumber": i,
|
|
||||||
}
|
|
||||||
|
|
||||||
for property in ("id", "title", "uploader", "uploader_id"):
|
|
||||||
if property in entry:
|
|
||||||
extras[f"playlist_{property}"] = entry.get(property)
|
|
||||||
|
|
||||||
if "thumbnail" not in etr and "youtube:" in entry.get("extractor", ""):
|
|
||||||
extras["thumbnail"] = f"https://img.youtube.com/vi/{etr['id']}/maxresdefault.jpg"
|
|
||||||
|
|
||||||
LOG.debug(f"Processing entry {i}/{playlistCount} - ID: {etr.get('id')} - Title: {etr.get('title')}")
|
|
||||||
|
|
||||||
results.append(
|
|
||||||
await self.add(
|
|
||||||
item=item.new_with(url=etr.get("url") or etr.get("webpage_url"), extras=extras),
|
|
||||||
already=already,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
LOG.info(
|
LOG.info(
|
||||||
f"Playlist '{entry.get('id')}: {entry.get('title')}' processing completed with '{len(results)}' entries."
|
f"Playlist '{entry.get('id')}: {entry.get('title')}' processing completed with '{len(results)}' entries."
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from app.library.Services import Services
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .encoder import Encoder
|
from .encoder import Encoder
|
||||||
from .Events import EventBus, Events, error, info, success
|
from .Events import EventBus, Events, error, success
|
||||||
from .Scheduler import Scheduler
|
from .Scheduler import Scheduler
|
||||||
from .Singleton import Singleton
|
from .Singleton import Singleton
|
||||||
from .Utils import init_class
|
from .Utils import init_class
|
||||||
|
|
@ -300,26 +300,17 @@ class Tasks(metaclass=Singleton):
|
||||||
template: str = task.template if task.template else ""
|
template: str = task.template if task.template else ""
|
||||||
cli: str = task.cli if task.cli else ""
|
cli: str = task.cli if task.cli else ""
|
||||||
|
|
||||||
LOG.info(f"Dispatched '{task.name}' at '{timeNow}'.")
|
await self._notify.emit(
|
||||||
|
Events.ADD_URL,
|
||||||
tasks: list = [
|
data={
|
||||||
self._notify.emit(
|
"url": task.url,
|
||||||
Events.LOG_INFO, data=info(f"Dispatched '{task.name}' at '{timeNow}'.", data={"lowPriority": True})
|
"preset": preset,
|
||||||
),
|
"folder": folder,
|
||||||
self._notify.emit(
|
"template": template,
|
||||||
Events.ADD_URL,
|
"cli": cli,
|
||||||
data={
|
},
|
||||||
"url": task.url,
|
id=task.id,
|
||||||
"preset": preset,
|
)
|
||||||
"folder": folder,
|
|
||||||
"template": template,
|
|
||||||
"cli": cli,
|
|
||||||
},
|
|
||||||
id=task.id,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
await asyncio.wait_for(asyncio.gather(*tasks), timeout=None)
|
|
||||||
|
|
||||||
timeNow = datetime.now(UTC).isoformat()
|
timeNow = datetime.now(UTC).isoformat()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue