Skip to content

Commit

Permalink
Add some fixes to properly extract meta from yt
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Nov 20, 2023
1 parent b5fdf46 commit 8e32540
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
13 changes: 8 additions & 5 deletions ytmdl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,14 @@ def meta(conv_name: str, song_name: str, search_by: str, args):
# If no meta was found raise error
if not TRACK_INFO:
# Check if we are supposed to add manual meta
if args.on_meta_error != "manual":
raise NoMetaError(search_by)

TRACK_INFO = manual.get_data(song_name)
return TRACK_INFO
if args.on_meta_error == "manual":
TRACK_INFO = manual.get_data(song_name)
return TRACK_INFO
elif args.on_meta_error == 'youtube':
# TODO: Extract meta from youtube
pass

raise NoMetaError(search_by)

logger.info('Setting data...')
option = song.setData(TRACK_INFO, IS_QUIET, conv_name, PASSED_FORMAT,
Expand Down
6 changes: 2 additions & 4 deletions ytmdl/meta/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@ def __parse_meta_from_details(details: Dict) -> Meta:
artwork_url_100=details.get("thumbnail", "N/A")
)

def extract_meta_from_yt(video_id: str) -> Meta:
def extract_meta_from_yt(video_url: 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)
return __parse_meta_from_details(details)
except Exception as e:
logger.debug("Got exception while extracting details for video with ID: ", video_id)
logger.debug("Got exception while extracting details for video: ", video_url)
logger.warning("Failed to extract metadata from yt with exception: ", str(e))
raise ExtractError(f"error extracting data from yt: {str(e)}")
2 changes: 1 addition & 1 deletion ytmdl/setupConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self):

self.DEFAULT_FORMAT = 'mp3'

self.ON_ERROR_OPTIONS = ['exit', 'skip', 'manual']
self.ON_ERROR_OPTIONS = ['exit', 'skip', 'manual', 'youtube']

self.ON_ERROR_DEFAULT = 'exit'

Expand Down
10 changes: 5 additions & 5 deletions ytmdl/utils/ytdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@


def get_ytdl_opts() -> Dict:
is_quiet: bool = utility.determine_logger_level(
) != logger.level_map["DEBUG"]
no_warnings: bool = utility.determine_logger_level(
) > logger.level_map["WARNING"]

return {
"quiet": is_quiet,
'no_warnings': no_warnings,
Expand Down Expand Up @@ -49,11 +54,6 @@ def ydl_opts_with_config(ytdl_config: str = None) -> Dict:
If the config is not present, return an empty dictionary
"""
is_quiet: bool = utility.determine_logger_level(
) != logger.level_map["DEBUG"]
no_warnings: bool = utility.determine_logger_level(
) > logger.level_map["WARNING"]

ydl_opts = get_ytdl_opts()

# If config is passed, generated opts with config
Expand Down

0 comments on commit 8e32540

Please sign in to comment.