forked from deepjyoti30/ytmdl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more changes to support extracting metadata from yt
- Loading branch information
1 parent
94d3a47
commit 66fc577
Showing
3 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Handle metadata extraction from youtube | ||
""" | ||
|
||
from typing import Dict | ||
|
||
from yt_dlp import YoutubeDL | ||
from simber import Logger | ||
|
||
from ytmdl.manual import Meta | ||
from ytmdl.utils.ytdl import get_ytdl_opts | ||
from ytmdl.exceptions import ExtractError | ||
|
||
# Create logger | ||
logger = Logger("meta:yt") | ||
|
||
|
||
def __parse_meta_from_details(details: Dict) -> Meta: | ||
""" | ||
Parse the meta object from the passed details | ||
""" | ||
return Meta( | ||
|
||
) | ||
|
||
def extract_meta_from_yt(video_id: str) -> Meta: | ||
""" | ||
Extract the metadata from the passed video ID and return | ||
it accordingly. | ||
""" | ||
ytdl_obj = YoutubeDL(get_ytdl_opts()) | ||
|
||
video_url = f"https://www.youtube.com/watch?v={video_id}" | ||
|
||
try: | ||
details = ytdl_obj.extract_info(video_url, download=False) | ||
except Exception as e: | ||
logger.debug("Got exception while extracting details for video with ID: ", video_id) | ||
logger.warning("Failed to extract metadata from yt with exception: ", str(e)) | ||
raise ExtractError(f"error extracting data from yt: {str(e)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters