Exemplo n.º 1
0
def get_all_transcripts(
    retreive_from_cache: bool = True,
    store_in_cache: bool = True,
    cache_folder: Path = TRANSCRIPTS_FOLDER,
) -> List[Transcript]:
    from lectures.config import get_lecture_groups

    lecture_groups = get_lecture_groups()
    transcripts: List[Transcript] = []
    for lg in lecture_groups:
        for lecture in lg.lectures:
            yt_id = lecture.youtube_id
            if not yt_id:
                print(
                    f"Skipping getting transcript for lecture {lecture.title} as has no YouTube ID"
                )
                continue
            try:
                transcript = get_transcript(
                    yt_id,
                    retreive_from_cache=retreive_from_cache,
                    store_in_cache=store_in_cache,
                    cache_folder=cache_folder,
                )
            except TranscriptsDisabled as e:
                print(e)
                continue
            transcripts.append(transcript)
    return transcripts
def generate_lecture_youtube_description_metadata_json(
        out_path: pathlib.Path = LECTURE_YOUTUBE_DESCRIPTIONS_METADATA_PATH):
    print(f"Analyzing metadata for lecture YouTube descriptions")
    current_metadata: Optional[
        LectureYouTubeDescriptionCollectionMetadata] = None
    if out_path.exists():
        current_metadata = LectureYouTubeDescriptionCollectionMetadata.parse_raw(
            out_path.read_text())
        print(
            f"Got existing metadata with {len(current_metadata.items)} items")
    print(f"Generating new metadata for lecture YouTube descriptions")
    lecture_groups = get_lecture_groups()
    metadata = LectureYouTubeDescriptionCollectionMetadata.generate_from_lecture_groups(
        lecture_groups)
    if current_metadata is not None:
        print(f"Merging metadata")
        metadata = current_metadata.merge(metadata, drop_unique_old=True)
    metadata.sort()
    print(f"Writing content metadata to {out_path}")
    out_path.write_text(metadata.json(indent=2))
Exemplo n.º 3
0
 def lecture_groups(self) -> List['LectureGroup']:
     from lectures.config import get_lecture_groups
     lgs = get_lecture_groups()
     return [lg for lg in lgs if lg.course == self]
Exemplo n.º 4
0
Sample usages:

All videos:
python -m build_tools.upload_descriptions_yt

Single video:
python -m build_tools.upload_descriptions_yt --video-id=<VIDEO_ID>
"""

import argparse

from build_tools import yt_api
from lectures.config import get_lecture_groups

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--video-id", help="ID of video to update.")
    args = parser.parse_args()

    youtube = yt_api.get_authenticated_service()

    lecture_groups = get_lecture_groups()
    for lg in lecture_groups:
        for lect in lg.lectures:
            if (args.video_id
                    and lect.youtube_id == args.video_id) or not args.video_id:
                try:
                    lect.upload_youtube_description(youtube=youtube)
                except yt_api.YouTubeDescriptionIsCurrentException as e:
                    print(str(e))