variable definitions

This commit is contained in:
Jesse Bannon 2023-12-19 22:12:54 -08:00
parent 5777aa57d9
commit bb76112e3a
4 changed files with 133 additions and 339 deletions

View file

@ -146,9 +146,6 @@ class VariableDefinitions:
@property
def webpage_url(self) -> MetadataVariable:
"""
Returns
-------
str
The url to the webpage.
"""
return MetadataVariable(metadata_key="webpage_url", variable_name="webpage_url")
@ -156,9 +153,6 @@ class VariableDefinitions:
@property
def info_json_ext(self) -> Variable:
"""
Returns
-------
str
The "info.json" extension
"""
return Variable("info_json_ext")
@ -166,9 +160,6 @@ class VariableDefinitions:
@property
def description(self) -> MetadataVariable:
"""
Returns
-------
str
The description if it exists. Otherwise, returns an emtpy string.
"""
return MetadataVariable(variable_name="description", metadata_key="description")
@ -176,9 +167,6 @@ class VariableDefinitions:
@property
def uploader_id(self) -> MetadataVariable:
"""
Returns
-------
str
The uploader id if it exists, otherwise return the unique ID.
"""
return MetadataVariable(variable_name="uploader_id", metadata_key="uploader_id")
@ -186,9 +174,6 @@ class VariableDefinitions:
@property
def uploader(self) -> MetadataVariable:
"""
Returns
-------
str
The uploader if it exists, otherwise return the uploader ID.
"""
return MetadataVariable(variable_name="uploader", metadata_key="uploader")
@ -196,9 +181,6 @@ class VariableDefinitions:
@property
def uploader_url(self) -> MetadataVariable:
"""
Returns
-------
str
The uploader url if it exists, otherwise returns the webpage_url.
"""
return MetadataVariable("uploader_url", metadata_key="uploader_url")
@ -206,9 +188,6 @@ class VariableDefinitions:
@property
def source_title(self) -> MetadataVariable:
"""
Returns
-------
str
Name of the source (i.e. channel with multiple playlists) if it exists, otherwise
returns its playlist_title.
"""
@ -217,9 +196,6 @@ class VariableDefinitions:
@property
def source_uid(self) -> MetadataVariable:
"""
Returns
-------
str
The source unique id if it exists, otherwise returns the playlist unique ID.
"""
return MetadataVariable("source_uid", metadata_key=self.uid.metadata_key)
@ -227,9 +203,6 @@ class VariableDefinitions:
@property
def source_index(self) -> MetadataVariable:
"""
Returns
-------
int
Source index if it exists, otherwise returns ``1``.
It is recommended to not use this unless you know the source will never add new content
@ -240,9 +213,6 @@ class VariableDefinitions:
@property
def source_index_padded(self) -> Variable:
"""
Returns
-------
int
The source index, padded.
"""
return Variable("source_index_padded")
@ -250,9 +220,6 @@ class VariableDefinitions:
@property
def source_count(self) -> MetadataVariable:
"""
Returns
-------
int
The source count if it exists, otherwise returns the playlist count.
"""
return MetadataVariable("source_count", metadata_key=self.playlist_count.metadata_key)
@ -260,9 +227,6 @@ class VariableDefinitions:
@property
def source_webpage_url(self) -> MetadataVariable:
"""
Returns
-------
str
The source webpage url if it exists, otherwise returns the playlist webpage url.
"""
return MetadataVariable("source_webpage_url", metadata_key=self.webpage_url.metadata_key)
@ -270,9 +234,6 @@ class VariableDefinitions:
@property
def source_description(self) -> MetadataVariable:
"""
Returns
-------
str
The source description if it exists, otherwise returns the playlist description.
"""
return MetadataVariable("source_description", metadata_key=self.description.metadata_key)
@ -280,9 +241,6 @@ class VariableDefinitions:
@property
def playlist_uid(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist unique ID if it exists, otherwise return the entry unique ID.
"""
return MetadataVariable(variable_name="playlist_uid", metadata_key="playlist_id")
@ -290,9 +248,6 @@ class VariableDefinitions:
@property
def playlist_title(self) -> MetadataVariable:
"""
Returns
-------
str
Name of its parent playlist/channel if it exists, otherwise returns its title.
"""
return MetadataVariable(variable_name="playlist_title", metadata_key="playlist_title")
@ -300,9 +255,6 @@ class VariableDefinitions:
@property
def playlist_index(self) -> MetadataVariable:
"""
Returns
-------
int
Playlist index if it exists, otherwise returns ``1``.
Note that for channels/playlists, any change (i.e. adding or removing a video) will make
@ -313,9 +265,6 @@ class VariableDefinitions:
@property
def playlist_index_reversed(self) -> Variable:
"""
Returns
-------
int
Playlist index reversed via ``playlist_count - playlist_index + 1``
"""
return Variable("playlist_index_reversed")
@ -323,9 +272,6 @@ class VariableDefinitions:
@property
def playlist_index_padded(self) -> Variable:
"""
Returns
-------
str
playlist_index padded two digits
"""
return Variable("playlist_index_padded")
@ -333,9 +279,6 @@ class VariableDefinitions:
@property
def playlist_index_reversed_padded(self) -> Variable:
"""
Returns
-------
str
playlist_index_reversed padded two digits
"""
return Variable("playlist_index_reversed_padded")
@ -343,9 +286,6 @@ class VariableDefinitions:
@property
def playlist_index_padded6(self) -> Variable:
"""
Returns
-------
str
playlist_index padded six digits.
"""
return Variable("playlist_index_padded6")
@ -353,9 +293,6 @@ class VariableDefinitions:
@property
def playlist_index_reversed_padded6(self) -> Variable:
"""
Returns
-------
str
playlist_index_reversed padded six digits.
"""
return Variable("playlist_index_reversed_padded6")
@ -363,9 +300,6 @@ class VariableDefinitions:
@property
def playlist_count(self) -> MetadataVariable:
"""
Returns
-------
int
Playlist count if it exists, otherwise returns ``1``.
Note that for channels/playlists, any change (i.e. adding or removing a video) will make
@ -376,9 +310,6 @@ class VariableDefinitions:
@property
def playlist_description(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist description if it exists, otherwise returns the entry's description.
"""
return MetadataVariable(
@ -388,9 +319,6 @@ class VariableDefinitions:
@property
def playlist_webpage_url(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist webpage url if it exists. Otherwise, returns the entry webpage url.
"""
return MetadataVariable(
@ -400,8 +328,6 @@ class VariableDefinitions:
@property
def playlist_max_upload_date(self) -> Variable:
"""
Returns
-------
Max upload_date for all entries in this entry's playlist if it exists, otherwise returns
``upload_date``
"""
@ -410,9 +336,6 @@ class VariableDefinitions:
@property
def playlist_max_upload_year(self) -> Variable:
"""
Returns
-------
int
Max upload_year for all entries in this entry's playlist if it exists, otherwise returns
``upload_year``
"""
@ -422,9 +345,6 @@ class VariableDefinitions:
@property
def playlist_max_upload_year_truncated(self) -> Variable:
"""
Returns
-------
int
The max playlist truncated upload year for all entries in this entry's playlist if it
exists, otherwise returns ``upload_year_truncated``.
"""
@ -433,9 +353,6 @@ class VariableDefinitions:
@property
def playlist_uploader_id(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist uploader id if it exists, otherwise returns the entry uploader ID.
"""
return MetadataVariable("playlist_uploader_id", metadata_key="playlist_uploader_id")
@ -443,9 +360,6 @@ class VariableDefinitions:
@property
def playlist_uploader(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist uploader if it exists, otherwise return the entry uploader.
"""
return MetadataVariable("playlist_uploader", metadata_key=self.uploader.metadata_key)
@ -453,9 +367,6 @@ class VariableDefinitions:
@property
def playlist_uploader_url(self) -> MetadataVariable:
"""
Returns
-------
str
The playlist uploader url if it exists, otherwise returns the playlist webpage_url.
"""
return MetadataVariable(
@ -465,9 +376,6 @@ class VariableDefinitions:
@property
def source_uploader_id(self) -> MetadataVariable:
"""
Returns
-------
str
The source uploader id if it exists, otherwise returns the playlist_uploader_id
"""
return MetadataVariable("source_uploader_id", metadata_key=self.uploader_id.metadata_key)
@ -475,9 +383,6 @@ class VariableDefinitions:
@property
def source_uploader(self) -> MetadataVariable:
"""
Returns
-------
str
The source uploader if it exists, otherwise return the playlist_uploader
"""
return MetadataVariable("source_uploader", metadata_key=self.uploader.metadata_key)
@ -485,9 +390,6 @@ class VariableDefinitions:
@property
def source_uploader_url(self) -> MetadataVariable:
"""
Returns
-------
str
The source uploader url if it exists, otherwise returns the source webpage_url.
"""
return MetadataVariable("source_uploader_url", metadata_key=self.uploader_url.metadata_key)
@ -495,9 +397,6 @@ class VariableDefinitions:
@property
def creator(self) -> MetadataVariable:
"""
Returns
-------
str
The creator name if it exists, otherwise returns the channel.
"""
return MetadataVariable(variable_name="creator", metadata_key="creator")
@ -505,9 +404,6 @@ class VariableDefinitions:
@property
def channel(self) -> MetadataVariable:
"""
Returns
-------
str
The channel name if it exists, otherwise returns the uploader.
"""
return MetadataVariable(variable_name="channel", metadata_key="channel")
@ -515,9 +411,6 @@ class VariableDefinitions:
@property
def channel_id(self) -> MetadataVariable:
"""
Returns
-------
str
The channel id if it exists, otherwise returns the entry uploader ID.
"""
return MetadataVariable(variable_name="channel_id", metadata_key="channel_id")
@ -525,9 +418,6 @@ class VariableDefinitions:
@property
def ext(self) -> MetadataVariable:
"""
Returns
-------
str
The downloaded entry's file extension
"""
return MetadataVariable(variable_name="ext", metadata_key="ext")
@ -535,9 +425,6 @@ class VariableDefinitions:
@property
def thumbnail_ext(self) -> Variable:
"""
Returns
-------
str
The download entry's thumbnail extension. Will always return 'jpg'. Until there is a
need to support other image types, we always convert to jpg.
"""
@ -581,9 +468,6 @@ class VariableDefinitions:
@property
def download_index(self) -> Variable:
"""
Returns
-------
int
The i'th entry downloaded. NOTE that this is fetched dynamically from the download
archive.
"""
@ -592,9 +476,6 @@ class VariableDefinitions:
@property
def download_index_padded6(self) -> Variable:
"""
Returns
-------
str
The download_index padded six digits
"""
return Variable("download_index_padded6")
@ -602,9 +483,6 @@ class VariableDefinitions:
@property
def upload_date_index(self) -> Variable:
"""
Returns
-------
int
The i'th entry downloaded with this upload date.
"""
return Variable(variable_name="upload_date_index")
@ -612,9 +490,6 @@ class VariableDefinitions:
@property
def upload_date_index_padded(self) -> Variable:
"""
Returns
-------
int
The upload_date_index padded two digits
"""
return Variable("upload_date_index_padded")
@ -622,9 +497,6 @@ class VariableDefinitions:
@property
def upload_date_index_reversed(self) -> Variable:
"""
Returns
-------
int
100 - upload_date_index
"""
return Variable("upload_date_index_reversed")
@ -632,9 +504,6 @@ class VariableDefinitions:
@property
def upload_date_index_reversed_padded(self) -> Variable:
"""
Returns
-------
int
The upload_date_index padded two digits
"""
return Variable("upload_date_index_reversed_padded")
@ -642,9 +511,6 @@ class VariableDefinitions:
@property
def upload_date(self) -> MetadataVariable:
"""
Returns
-------
str
The entrys uploaded date, in YYYYMMDD format. If not present, return todays date.
"""
return MetadataVariable(variable_name="upload_date", metadata_key="upload_date")
@ -652,9 +518,6 @@ class VariableDefinitions:
@property
def upload_year(self) -> Variable:
"""
Returns
-------
int
The entry's upload year
"""
return Variable("upload_year")
@ -662,9 +525,6 @@ class VariableDefinitions:
@property
def upload_year_truncated(self) -> Variable:
"""
Returns
-------
int
The last two digits of the upload year, i.e. 22 in 2022
"""
return Variable("upload_year_truncated")
@ -672,9 +532,6 @@ class VariableDefinitions:
@property
def upload_year_truncated_reversed(self) -> Variable:
"""
Returns
-------
int
The upload year truncated, but reversed using ``100 - {upload_year_truncated}``, i.e.
2022 returns ``100 - 22`` = ``78``
"""
@ -683,9 +540,6 @@ class VariableDefinitions:
@property
def upload_month_reversed(self) -> Variable:
"""
Returns
-------
int
The upload month, but reversed using ``13 - {upload_month}``, i.e. March returns ``10``
"""
return Variable("upload_month_reversed")
@ -693,9 +547,6 @@ class VariableDefinitions:
@property
def upload_month_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed upload month, but padded. i.e. November returns "02"
"""
return Variable("upload_month_reversed_padded")
@ -703,9 +554,6 @@ class VariableDefinitions:
@property
def upload_month_padded(self) -> Variable:
"""
Returns
-------
str
The entry's upload month padded to two digits, i.e. March returns "03"
"""
return Variable("upload_month_padded")
@ -713,9 +561,6 @@ class VariableDefinitions:
@property
def upload_day_padded(self) -> Variable:
"""
Returns
-------
str
The entry's upload day padded to two digits, i.e. the fifth returns "05"
"""
return Variable("upload_day_padded")
@ -723,9 +568,6 @@ class VariableDefinitions:
@property
def upload_month(self) -> Variable:
"""
Returns
-------
int
The upload month as an integer (no padding).
"""
return Variable("upload_month")
@ -733,9 +575,6 @@ class VariableDefinitions:
@property
def upload_day(self) -> Variable:
"""
Returns
-------
int
The upload day as an integer (no padding).
"""
return Variable("upload_day")
@ -743,9 +582,6 @@ class VariableDefinitions:
@property
def upload_day_reversed(self) -> Variable:
"""
Returns
-------
int
The upload day, but reversed using ``{total_days_in_month} + 1 - {upload_day}``,
i.e. August 8th would have upload_day_reversed of ``31 + 1 - 8`` = ``24``
"""
@ -754,9 +590,6 @@ class VariableDefinitions:
@property
def upload_day_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed upload day, but padded. i.e. August 30th returns "02".
"""
return Variable("upload_day_reversed_padded")
@ -764,9 +597,6 @@ class VariableDefinitions:
@property
def upload_day_of_year(self) -> Variable:
"""
Returns
-------
int
The day of the year, i.e. February 1st returns ``32``
"""
return Variable("upload_day_of_year")
@ -774,9 +604,6 @@ class VariableDefinitions:
@property
def upload_day_of_year_padded(self) -> Variable:
"""
Returns
-------
str
The upload day of year, but padded i.e. February 1st returns "032"
"""
return Variable("upload_day_of_year_padded")
@ -784,9 +611,6 @@ class VariableDefinitions:
@property
def upload_day_of_year_reversed(self) -> Variable:
"""
Returns
-------
int
The upload day, but reversed using ``{total_days_in_year} + 1 - {upload_day}``,
i.e. February 2nd would have upload_day_of_year_reversed of ``365 + 1 - 32`` = ``334``
"""
@ -795,9 +619,6 @@ class VariableDefinitions:
@property
def upload_day_of_year_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed upload day of year, but padded i.e. December 31st returns "001"
"""
return Variable("upload_day_of_year_reversed_padded")
@ -805,9 +626,6 @@ class VariableDefinitions:
@property
def upload_date_standardized(self) -> Variable:
"""
Returns
-------
str
The uploaded date formatted as YYYY-MM-DD
"""
return Variable("upload_date_standardized")
@ -815,9 +633,6 @@ class VariableDefinitions:
@property
def release_date(self) -> MetadataVariable:
"""
Returns
-------
str
The entrys release date, in YYYYMMDD format. If not present, return the upload date.
"""
return MetadataVariable(variable_name="release_date", metadata_key="release_date")
@ -825,9 +640,6 @@ class VariableDefinitions:
@property
def release_year(self) -> Variable:
"""
Returns
-------
int
The entry's release year
"""
return Variable("release_year")
@ -835,9 +647,6 @@ class VariableDefinitions:
@property
def release_year_truncated(self) -> Variable:
"""
Returns
-------
int
The last two digits of the release year, i.e. 22 in 2022
"""
return Variable("release_year_truncated")
@ -845,9 +654,6 @@ class VariableDefinitions:
@property
def release_year_truncated_reversed(self) -> Variable:
"""
Returns
-------
int
The release year truncated, but reversed using ``100 - {release_year_truncated}``, i.e.
2022 returns ``100 - 22`` = ``78``
"""
@ -856,9 +662,6 @@ class VariableDefinitions:
@property
def release_month_reversed(self) -> Variable:
"""
Returns
-------
int
The release month, but reversed
using ``13 - {release_month}``, i.e. March returns ``10``
"""
@ -867,9 +670,6 @@ class VariableDefinitions:
@property
def release_month_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed release month, but padded. i.e. November returns "02"
"""
return Variable("release_month_reversed_padded")
@ -877,9 +677,6 @@ class VariableDefinitions:
@property
def release_month_padded(self) -> Variable:
"""
Returns
-------
str
The entry's release month padded to two digits, i.e. March returns "03"
"""
return Variable("release_month_padded")
@ -887,9 +684,6 @@ class VariableDefinitions:
@property
def release_day_padded(self) -> Variable:
"""
Returns
-------
str
The entry's release day padded to two digits, i.e. the fifth returns "05"
"""
return Variable("release_day_padded")
@ -897,9 +691,6 @@ class VariableDefinitions:
@property
def release_month(self) -> Variable:
"""
Returns
-------
int
The release month as an integer (no padding).
"""
return Variable("release_month")
@ -907,9 +698,6 @@ class VariableDefinitions:
@property
def release_day(self) -> Variable:
"""
Returns
-------
int
The release day as an integer (no padding).
"""
return Variable("release_day")
@ -917,9 +705,6 @@ class VariableDefinitions:
@property
def release_day_reversed(self) -> Variable:
"""
Returns
-------
int
The release day, but reversed using ``{total_days_in_month} + 1 - {release_day}``,
i.e. August 8th would have release_day_reversed of ``31 + 1 - 8`` = ``24``
"""
@ -928,9 +713,6 @@ class VariableDefinitions:
@property
def release_day_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed release day, but padded. i.e. August 30th returns "02".
"""
return Variable("release_day_reversed_padded")
@ -938,9 +720,6 @@ class VariableDefinitions:
@property
def release_day_of_year(self) -> Variable:
"""
Returns
-------
int
The day of the year, i.e. February 1st returns ``32``
"""
return Variable("release_day_of_year")
@ -948,9 +727,6 @@ class VariableDefinitions:
@property
def release_day_of_year_padded(self) -> Variable:
"""
Returns
-------
str
The release day of year, but padded i.e. February 1st returns "032"
"""
return Variable("release_day_of_year_padded")
@ -958,9 +734,6 @@ class VariableDefinitions:
@property
def release_day_of_year_reversed(self) -> Variable:
"""
Returns
-------
int
The release day, but reversed using ``{total_days_in_year} + 1 - {release_day}``,
i.e. February 2nd would have release_day_of_year_reversed of ``365 + 1 - 32`` = ``334``
"""
@ -969,9 +742,6 @@ class VariableDefinitions:
@property
def release_day_of_year_reversed_padded(self) -> Variable:
"""
Returns
-------
str
The reversed release day of year, but padded i.e. December 31st returns "001"
"""
return Variable("release_day_of_year_reversed_padded")
@ -979,9 +749,6 @@ class VariableDefinitions:
@property
def release_date_standardized(self) -> Variable:
"""
Returns
-------
str
The release date formatted as YYYY-MM-DD
"""
return Variable("release_date_standardized")

View file

@ -0,0 +1,16 @@
from tools.docgen.utils import get_property_docs
from tools.docgen.utils import properties
from tools.docgen.utils import section
from ytdl_sub.entries.script.variable_definitions import VariableDefinitions
def generate_variable_docs() -> str:
docs = section("Entry Variables", level=0)
for variable_name in properties(VariableDefinitions):
docs += get_property_docs(property_name=variable_name, obj=VariableDefinitions, level=1)
return docs
print(generate_variable_docs())

View file

@ -2,6 +2,8 @@ import inspect
from typing import Dict
from typing import Type
from tools.docgen.utils import get_property_docs
from tools.docgen.utils import properties
from tools.docgen.utils import section
from ytdl_sub.config.overrides import Overrides
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
@ -21,22 +23,16 @@ def should_filter_property(property_name: str) -> bool:
)
def generate_plugin_docs(name: str, options: Type[OptionsValidator], offset: int):
def generate_plugin_docs(name: str, options: Type[OptionsValidator], offset: int) -> str:
docs = ""
docs += section(name, level=offset + 0)
docs += inspect.cleandoc(options.__doc__)
docs += "\n"
property_names = [
prop
for prop in dir(options)
if isinstance(getattr(options, prop), property) and not should_filter_property(prop)
]
property_names = [prop for prop in properties(options) if not should_filter_property(prop)]
for property_name in sorted(property_names):
docs += section(property_name, level=offset + 1)
docs += inspect.cleandoc(getattr(options, property_name).__doc__)
docs += "\n"
docs += get_property_docs(property_name=property_name, obj=options, level=offset + 1)
return docs

View file

@ -1,7 +1,22 @@
import inspect
from typing import Any
from typing import Dict
from typing import List
from typing import Type
LEVEL_CHARS: Dict[int, str] = {0: "=", 1: "-", 2: "~", 3: "^"}
def section(name: str, level: int) -> str:
return f"\n{name}\n{len(name) * LEVEL_CHARS[level]}\n"
def properties(obj: Type[Any]) -> List[str]:
return [prop for prop in dir(obj) if isinstance(getattr(obj, prop), property)]
def get_property_docs(property_name: str, obj: Any, level: int) -> str:
docs = section(property_name, level=level)
docs += inspect.cleandoc(getattr(obj, property_name).__doc__)
docs += "\n"
return docs