working split video

This commit is contained in:
jbannon 2022-06-24 04:33:12 +00:00
parent 966864c9b4
commit f1670a094d
3 changed files with 12 additions and 21 deletions

View file

@ -1,23 +1,10 @@
import copy
import os.path
import re
from pathlib import Path
from shutil import copyfile
from typing import Any
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import Tuple
from ytdl_sub.downloaders.youtube_downloader import YoutubeDownloader from ytdl_sub.downloaders.youtube_downloader import YoutubeDownloader
from ytdl_sub.downloaders.youtube_downloader import YoutubePlaylistDownloaderOptions from ytdl_sub.downloaders.youtube_downloader import YoutubePlaylistDownloaderOptions
from ytdl_sub.downloaders.youtube_downloader import YoutubeVideoDownloaderOptions
from ytdl_sub.entries.youtube import YoutubePlaylistVideo
from ytdl_sub.entries.youtube import YoutubeVideo from ytdl_sub.entries.youtube import YoutubeVideo
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.ffmpeg import FFMPEG
from ytdl_sub.utils.thumbnail import convert_download_thumbnail
from ytdl_sub.validators.validators import BoolValidator from ytdl_sub.validators.validators import BoolValidator
from ytdl_sub.validators.validators import StringValidator
############################################################################### ###############################################################################
# Youtube split video downloader + options # Youtube split video downloader + options

View file

@ -1,11 +1,9 @@
import copy import copy
import os.path
import re import re
from pathlib import Path from pathlib import Path
from shutil import copyfile from shutil import copyfile
from typing import Dict from typing import Dict
from typing import List from typing import List
from typing import Tuple
from ytdl_sub.downloaders.youtube_downloader import YoutubeDownloader from ytdl_sub.downloaders.youtube_downloader import YoutubeDownloader
from ytdl_sub.downloaders.youtube_downloader import YoutubeVideoDownloaderOptions from ytdl_sub.downloaders.youtube_downloader import YoutubeVideoDownloaderOptions
@ -13,7 +11,6 @@ from ytdl_sub.entries.youtube import YoutubePlaylistVideo
from ytdl_sub.entries.youtube import YoutubeVideo from ytdl_sub.entries.youtube import YoutubeVideo
from ytdl_sub.utils.chapters import Chapters from ytdl_sub.utils.chapters import Chapters
from ytdl_sub.utils.chapters import Timestamp from ytdl_sub.utils.chapters import Timestamp
from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.ffmpeg import FFMPEG from ytdl_sub.utils.ffmpeg import FFMPEG
from ytdl_sub.utils.thumbnail import convert_download_thumbnail from ytdl_sub.utils.thumbnail import convert_download_thumbnail
from ytdl_sub.validators.validators import StringValidator from ytdl_sub.validators.validators import StringValidator

View file

@ -90,16 +90,23 @@ class Chapters:
Represents a list of (timestamps, titles) Represents a list of (timestamps, titles)
""" """
def __init__(self, timestamps: List[Timestamp], titles: List[str], duration: Timestamp): def __init__(
self,
timestamps: List[Timestamp],
titles: List[str],
):
self.timestamps = timestamps self.timestamps = timestamps
self.titles = titles self.titles = titles
self.duration = duration
for idx in range(len(timestamps) - 1):
if timestamps[idx].timestamp_sec >= timestamps[idx + 1].timestamp_sec:
raise ValueError("Timestamps must be in ascending order")
def contains_zero_timestamp(self) -> bool: def contains_zero_timestamp(self) -> bool:
return self.timestamps[0].timestamp_sec == 0 return self.timestamps[0].timestamp_sec == 0
@classmethod @classmethod
def from_file(cls, chapters_file_path: str, duration: Timestamp) -> "Chapters": def from_file(cls, chapters_file_path: str) -> "Chapters":
if not os.path.isfile(chapters_file_path): if not os.path.isfile(chapters_file_path):
raise ValidationException( raise ValidationException(
f"chapter/timestamp file path '{chapters_file_path}' does not exist." f"chapter/timestamp file path '{chapters_file_path}' does not exist."
@ -112,7 +119,7 @@ class Chapters:
titles: List[str] = [] titles: List[str] = []
for idx, line in enumerate(lines): for idx, line in enumerate(lines):
line_split = line.lstrip().split(maxsplit=1) line_split = line.strip().split(maxsplit=1)
# Allow the last line to be blank # Allow the last line to be blank
if idx == len(lines) - 1 and not line.strip(): if idx == len(lines) - 1 and not line.strip():
@ -129,4 +136,4 @@ class Chapters:
timestamps.append(Timestamp.from_str(timestamp_str)) timestamps.append(Timestamp.from_str(timestamp_str))
titles.append(title) titles.append(title)
return cls(timestamps=timestamps, titles=titles, duration=duration) return cls(timestamps=timestamps, titles=titles)