[BACKEND] epoch and playlist_index_reversed variables (#257)
This commit is contained in:
parent
7d29b72010
commit
cd9a094e2c
4 changed files with 73 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from abc import ABC
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
|
|
@ -11,6 +12,8 @@ from typing import final
|
|||
from yt_dlp.utils import sanitize_filename
|
||||
|
||||
from ytdl_sub.entries.variables.kwargs import DESCRIPTION
|
||||
from ytdl_sub.entries.variables.kwargs import EPOCH
|
||||
from ytdl_sub.entries.variables.kwargs import EXTRACTOR
|
||||
from ytdl_sub.entries.variables.kwargs import TITLE
|
||||
from ytdl_sub.entries.variables.kwargs import UID
|
||||
from ytdl_sub.entries.variables.kwargs import UPLOADER
|
||||
|
|
@ -58,7 +61,37 @@ class BaseEntryVariables:
|
|||
str
|
||||
The ytdl extractor name
|
||||
"""
|
||||
return self.kwargs("extractor")
|
||||
return self.kwargs(EXTRACTOR)
|
||||
|
||||
@property
|
||||
def epoch(self: "BaseEntry") -> int:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
The unix epoch of when the metadata was scraped by yt-dlp.
|
||||
"""
|
||||
return self.kwargs(EPOCH)
|
||||
|
||||
@property
|
||||
def epoch_date(self: "BaseEntry") -> str:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The epoch's date, in YYYYMMDD format.
|
||||
"""
|
||||
return datetime.utcfromtimestamp(self.epoch).strftime("%Y%m%d")
|
||||
|
||||
@property
|
||||
def epoch_hour(self: "BaseEntry") -> str:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The epoch's hour, padded
|
||||
"""
|
||||
return datetime.utcfromtimestamp(self.epoch).strftime("%H")
|
||||
|
||||
@property
|
||||
def title(self: "BaseEntry") -> str:
|
||||
|
|
|
|||
|
|
@ -169,6 +169,16 @@ class EntryVariables(BaseEntryVariables):
|
|||
"""
|
||||
return self.kwargs_get(PLAYLIST_INDEX, 1)
|
||||
|
||||
@property
|
||||
def playlist_index_reversed(self: Self) -> int:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
int
|
||||
Playlist index reversed via ``playlist_count - playlist_index + 1``
|
||||
"""
|
||||
return self.playlist_count - self.playlist_index + 1
|
||||
|
||||
@property
|
||||
def playlist_index_padded(self: Self) -> str:
|
||||
"""
|
||||
|
|
@ -179,6 +189,16 @@ class EntryVariables(BaseEntryVariables):
|
|||
"""
|
||||
return _pad(self.playlist_index, width=2)
|
||||
|
||||
@property
|
||||
def playlist_index_reversed_padded(self: Self) -> str:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
playlist_index_reversed padded two digits
|
||||
"""
|
||||
return _pad(self.playlist_index_reversed, width=2)
|
||||
|
||||
@property
|
||||
def playlist_index_padded6(self: Self) -> str:
|
||||
"""
|
||||
|
|
@ -189,6 +209,16 @@ class EntryVariables(BaseEntryVariables):
|
|||
"""
|
||||
return _pad(self.playlist_index, width=6)
|
||||
|
||||
@property
|
||||
def playlist_index_reversed_padded6(self: Self) -> str:
|
||||
"""
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
playlist_index_reversed padded six digits.
|
||||
"""
|
||||
return _pad(self.playlist_index_reversed, width=6)
|
||||
|
||||
@property
|
||||
def playlist_count(self: Self) -> int:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ PLAYLIST_UPLOADER_ID = _("playlist_uploader_id")
|
|||
PLAYLIST_UPLOADER_URL = _("playlist_uploader_url")
|
||||
|
||||
UID = _("id")
|
||||
EXTRACTOR = _("extractor")
|
||||
EPOCH = _("epoch")
|
||||
CHANNEL = _("channel")
|
||||
EXT = _("ext")
|
||||
TITLE = _("title")
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ def mock_entry_to_dict(
|
|||
return {
|
||||
"uid": uid,
|
||||
"uid_sanitized": uid,
|
||||
"epoch": 1596878400,
|
||||
"epoch_date": "20200808",
|
||||
"epoch_hour": "09",
|
||||
"title": "entry {title}",
|
||||
"title_sanitized": "entry {title}",
|
||||
"ext": ext,
|
||||
|
|
@ -95,6 +98,9 @@ def mock_entry_to_dict(
|
|||
"playlist_index": 1,
|
||||
"playlist_index_padded": "01",
|
||||
"playlist_index_padded6": "000001",
|
||||
"playlist_index_reversed": 1,
|
||||
"playlist_index_reversed_padded": "01",
|
||||
"playlist_index_reversed_padded6": "000001",
|
||||
"playlist_count": 1,
|
||||
"playlist_max_upload_year": 2021,
|
||||
"playlist_max_upload_year_truncated": 21,
|
||||
|
|
@ -126,6 +132,7 @@ def mock_entry_kwargs(
|
|||
):
|
||||
return {
|
||||
"id": uid,
|
||||
"epoch": 1596878400,
|
||||
"extractor": extractor,
|
||||
"title": title,
|
||||
"ext": ext,
|
||||
|
|
|
|||
Loading…
Reference in a new issue