```sh-5.2$ /bin/python "/home/lucas/# Code preview for the youtube channel h.py"
Starting process...
Fetching videos from channel: https://www.youtube.com/@el-ea
Traceback (most recent call last):
  File "/home/lucas/# Code preview for the youtube channel h.py", line 63, in <module>
    main()
  File "/home/lucas/# Code preview for the youtube channel h.py", line 58, in main
    downloaded_videos = download_videos(CHANNEL_URL)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lucas/# Code preview for the youtube channel h.py", line 23, in download_videos
    channel = Channel(channel_url)
              ^^^^^^^^^^^^^^^^^^^^
  File "/var/data/python/lib/python3.12/site-packages/pytube/contrib/channel.py", line 24, in __init__
    self.channel_uri = extract.channel_name(url)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/data/python/lib/python3.12/site-packages/pytube/extract.py", line 185, in channel_name
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: channel_name: could not find match for patterns
sh-5.2$ ```


# Code preview for the youtube channel https://www.youtube.com/@el-ea
# Simple baseline of the code: Grab the videos of the youtube channel and display short cuts of them
import os
from pytube import Channel, YouTube
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip

# Constants
CHANNEL_URL = "https://www.youtube.com/@el-ea"
DOWNLOAD_FOLDER = "downloads"
CLIP_FOLDER = "clips"
CLIP_DURATION = 10  # Duration of each preview clip in seconds

# Create folders for downloads and clips
os.makedirs(DOWNLOAD_FOLDER, exist_ok=True)
os.makedirs(CLIP_FOLDER, exist_ok=True)

def download_videos(channel_url, max_videos=5):
    """
    Download the latest videos from the specified channel.
    """
    print(f"Fetching videos from channel: {channel_url}")
    channel = Channel(channel_url)
    video_urls = channel.video_urls[:max_videos]
    downloaded_videos = []

    for url in video_urls:
        try:
            yt = YouTube(url)
            print(f"Downloading: {yt.title}")
            video = yt.streams.filter(progressive=True, file_extension="mp4").first()
            output_path = video.download(DOWNLOAD_FOLDER)
            downloaded_videos.append(output_path)
            print(f"Downloaded: {output_path}")
        except Exception as e:
            print(f"Error downloading {url}: {e}")
    
    return downloaded_videos

def create_clips(video_paths):
    """
    Extract short clips from downloaded videos.
    """
    print("Creating short clips...")
    for video_path in video_paths:
        try:
            video = VideoFileClip(video_path)
            clip_start = min(5, video.duration - CLIP_DURATION)  # Start at 5s or earlier if duration is short
            clip_end = clip_start + CLIP_DURATION
            clip_output = os.path.join(CLIP_FOLDER, f"clip_{os.path.basename(video_path)}")
            ffmpeg_extract_subclip(video_path, clip_start, clip_end, targetname=clip_output)
            print(f"Clip created: {clip_output}")
        except Exception as e:
            print(f"Error creating clip for {video_path}: {e}")

def main():
    print("Starting process...")
    downloaded_videos = download_videos(CHANNEL_URL)
    create_clips(downloaded_videos)
    print("Process complete. Check the 'clips' folder for results.")

if __name__ == "__main__":
    main()