ytfetcher.services package¶
Submodules¶
ytfetcher.services.exports module¶
- class ytfetcher.services.exports.BaseExporter(channel_data: list[ChannelData], allowed_metadata_list: Sequence[Literal['title', 'description', 'url', 'duration', 'view_count', 'thumbnails']] = ('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing: bool = True, filename: str = 'data', output_dir: str | None = None)¶
Bases:
ABCHandles exporting YouTube transcript and metadata to various formats: TXT, JSON, and CSV.
Supports customization of which metadata fields to include and whether to include transcript timing.
- Parameters:
channel_data (list[ChannelData]) – The transcript and metadata to export.
allowed_metadata_list (list) – Metadata fields to include (e.g., [‘title’, ‘description’]).
timing (bool) – Whether to include start/duration timing in exports.
filename (str) – Output filename without extension.
output_dir (str | None) – Directory to export files into. Defaults to current working directory.
- Raises:
NoDataToExport – If no data is provided.
OutputDirectoryNotFoundError – If specified path cannot found.
- abstractmethod write() None¶
- class ytfetcher.services.exports.CSVExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a flat CSV file, row-per-transcript-entry.
- write()¶
- class ytfetcher.services.exports.Exporter(*args, **kwargs)¶
Bases:
objectDEPRECATED: Use TXTExporter, JSONExporter, or CSVExporter instead.
This class is kept for backward compatibility and will be removed in a future versions.
- Parameters:
channel_data (list[ChannelData]) – The transcript and metadata to export.
allowed_metadata_list (list) – Metadata fields to include (e.g., [‘title’, ‘description’]).
timing (bool) – Whether to include start/duration timing in exports.
filename (str) – Output filename without extension.
output_dir (str | None) – Directory to export files into. Defaults to current working directory.
- Raises:
NoDataToExport – If no data is provided.
OutputDirectoryNotFoundError – If specified path cannot found.
- export_as_csv() None¶
- export_as_json() None¶
- export_as_txt() None¶
- class ytfetcher.services.exports.JSONExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a structured JSON file.
- write()¶
- class ytfetcher.services.exports.TXTExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a plain text file, including transcript and metadata.
- write()¶
Module contents¶
- class ytfetcher.services.CSVExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a flat CSV file, row-per-transcript-entry.
- write()¶
- class ytfetcher.services.Exporter(*args, **kwargs)¶
Bases:
objectDEPRECATED: Use TXTExporter, JSONExporter, or CSVExporter instead.
This class is kept for backward compatibility and will be removed in a future versions.
- Parameters:
channel_data (list[ChannelData]) – The transcript and metadata to export.
allowed_metadata_list (list) – Metadata fields to include (e.g., [‘title’, ‘description’]).
timing (bool) – Whether to include start/duration timing in exports.
filename (str) – Output filename without extension.
output_dir (str | None) – Directory to export files into. Defaults to current working directory.
- Raises:
NoDataToExport – If no data is provided.
OutputDirectoryNotFoundError – If specified path cannot found.
- export_as_csv() None¶
- export_as_json() None¶
- export_as_txt() None¶
- class ytfetcher.services.JSONExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a structured JSON file.
- write()¶
- class ytfetcher.services.PreviewRenderer¶
Bases:
object- render(data: list[ChannelData], limit: int = 4) None¶
Renders a rich preview.
- Parameters:
data – The list of fetched channel data.
limit – Controls BOTH the max number of videos shown AND the max lines/comments shown per video.
- class ytfetcher.services.TXTExporter(channel_data, allowed_metadata_list=('title', 'description', 'url', 'duration', 'view_count', 'thumbnails'), timing=True, filename='data', output_dir=None)¶
Bases:
BaseExporterExports the data as a plain text file, including transcript and metadata.
- write()¶