ytdl-sub/src/ytdl_sub/entries/variables/youtube_variables.py
Jesse Bannon cb6dc8e034
Add youtube.download_strategy: "merge_playlist" (#77)
* begin

* chapters class, trying to add chapter splitting and general ffmpeg metadata creation

* working split video

* so very close

* test passing, is reproducible

* lint fixed

* fix docs

* track no longer used in example

* if, then del

* multiple values

* github hash
2022-06-26 15:18:07 -07:00

93 lines
2.5 KiB
Python

from yt_dlp.utils import sanitize_filename
from ytdl_sub.entries.base_entry import BaseEntry
from ytdl_sub.entries.variables.entry_variables import EntryVariables
# This file contains mixins to a BaseEntry subclass. Ignore pylint's "no kwargs member" suggestion
# pylint: disable=no-member
class YoutubeVideoVariables(EntryVariables):
@property
def channel(self: BaseEntry) -> str:
"""
Returns
-------
The channel name.
"""
return self.kwargs("channel")
@property
def channel_sanitized(self) -> str:
"""
Returns
-------
The channel name, sanitized.
"""
return sanitize_filename(self.channel)
@property
def track_title(self: BaseEntry) -> str:
"""
Returns
-------
The track title of a music video if it is available, otherwise it falls back to the title.
NOTE: Even if a video has music metadata, this variable does not always get pulled via
yt-dlp. Use with caution.
"""
# Try to get the track, fall back on title
if self.kwargs_contains("track"):
return self.kwargs("track")
return super().title
@property
def track_title_sanitized(self) -> str:
"""
Returns
-------
The sanitized track title.
"""
return sanitize_filename(self.track_title)
@property
def artist(self: BaseEntry) -> str:
"""
Returns
-------
The artist of a music video if it is available, otherwise it falls back to the channel.
NOTE: Even if a video has music metadata, this variable does not always get pulled via
yt-dlp. Use with caution.
"""
if self.kwargs_contains("artist"):
return self.kwargs("artist")
return self.kwargs("channel")
@property
def artist_sanitized(self) -> str:
"""
Returns
-------
The sanitized artist name.
"""
return sanitize_filename(self.artist)
@property
def playlist_index(self) -> int:
"""
Returns
-------
The index of the video in the playlist. For non-playlist download strategies, this will
always return 1.
"""
return 1
@property
def playlist_size(self) -> int:
"""
Returns
-------
The size of the playlist. For non-playlist download strategies, this will always return 1.
"""
return 1