diff --git a/server/entertainment_decider/extractors/all/youtube.py b/server/entertainment_decider/extractors/all/youtube.py new file mode 100644 index 0000000..a55da69 --- /dev/null +++ b/server/entertainment_decider/extractors/all/youtube.py @@ -0,0 +1,48 @@ +from __future__ import annotations + +from typing import ( + List, + NewType, + TypedDict, +) + + +Keyword = NewType("Keyword", str) + + +class YoutubeDuration(TypedDict): + secondsText: str + + +class YoutubeViewCount(TypedDict): + text: str + + +class YoutubeThumbnailData(TypedDict): + url: str + width: int + height: int + + +class YoutubeChannelData(TypedDict): + name: str + id: str + link: str + + +class YoutubeVideoData(TypedDict): + id: str + title: str + duration: YoutubeDuration + viewCount: YoutubeViewCount + thumbnails: List[YoutubeThumbnailData] + description: str + channel: YoutubeChannelData + allowRatings: bool + averageRating: float + keywords: List[Keyword] + isLiveContent: bool + publishDate: str + uploadDate: str + isLiveNow: bool + link: str diff --git a/server/entertainment_decider/extractors/media/youtube.py b/server/entertainment_decider/extractors/media/youtube.py index f8fabba..149df2c 100644 --- a/server/entertainment_decider/extractors/media/youtube.py +++ b/server/entertainment_decider/extractors/media/youtube.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import datetime import logging import re -from typing import List, NewType, Optional, TypedDict +from typing import Optional from youtubesearchpython import ResultMode, Video @@ -12,6 +12,9 @@ from ...models import ( MediaThumbnail, thumbnail_sort_key, ) +from ..all.youtube import ( + YoutubeVideoData, +) from ..generic import ( AuthorExtractedData, ChangedReport, @@ -22,49 +25,7 @@ from ..generic import ( from .base import MediaExtractor -Keyword = NewType("Keyword", str) - - -class YoutubeDuration(TypedDict): - secondsText: str - - -class YoutubeViewCount(TypedDict): - text: str - - -class YoutubeThumbnailData(TypedDict): - url: str - width: int - height: int - - -class YoutubeChannelData(TypedDict): - name: str - id: str - link: str - - -class YoutubeVideoData(TypedDict): - id: str - title: str - duration: YoutubeDuration - viewCount: YoutubeViewCount - thumbnails: List[YoutubeThumbnailData] - description: str - channel: YoutubeChannelData - allowRatings: bool - averageRating: float - keywords: List[Keyword] - isLiveContent: bool - publishDate: str - uploadDate: str - isLiveNow: bool - link: str - - class YoutubeMediaExtractor(MediaExtractor[YoutubeVideoData]): - __uri_regex = re.compile( r"""^ https?://(