Skip to content

Commit

Permalink
Add -p to CLI for specifying providers
Browse files Browse the repository at this point in the history
  • Loading branch information
moehmeni committed Dec 14, 2023
1 parent 436bd77 commit 9d932c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions syncedlyrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ def search(
- `providers`: A list of provider names to include in searching; loops over all the providers as soon as an LRC is found
"""
_providers = [Musixmatch(), Lrclib(), NetEase(), Megalobiz()]
if providers:
if providers and any(providers):
# Filtering the providers
_providers = [p for p in _providers if p.__class__.__name__ in providers]
_providers = [
p
for p in _providers
if p.__class__.__name__.lower() in [p.lower() for p in providers]
]
if not _providers:
logger.error(
f"Providers {providers} not found in the list of available providers."
)
return
lrc = None
for provider in _providers:
logger.debug(f"Looking for an LRC on {provider.__class__.__name__}")
Expand Down
10 changes: 7 additions & 3 deletions syncedlyrics/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def cli_handler():
description="Search for an LRC format (synchronized lyrics) of a music"
)
parser.add_argument("search_term", help="The search term to find the track.")
parser.add_argument(
"-p",
help="Comma-separated list of providers to include in searching",
default="",
)
parser.add_argument(
"-o", "--output", help="Path to save '.lrc' lyrics", default="{search_term}.lrc"
)
Expand All @@ -24,9 +29,8 @@ def cli_handler():
"-v", "--verbose", help="Use this flag to show the logs", action="store_true"
)
args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

lrc = search(args.search_term, args.allow_plain, args.output)
p = args.p.split(",") if args.p else None
lrc = search(args.search_term, args.allow_plain, args.output, p)
if lrc:
print(lrc)

0 comments on commit 9d932c0

Please sign in to comment.