Skip to content

Commit

Permalink
Feat: redownload flag for meta (#1944)
Browse files Browse the repository at this point in the history
Co-authored-by: kuba <[email protected]>
  • Loading branch information
Billa05 and xnetcat authored Oct 30, 2023
1 parent 359f8fe commit 912adc9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
23 changes: 21 additions & 2 deletions spotdl/console/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from spotdl.utils.ffmpeg import FFMPEG_FORMATS
from spotdl.utils.lrc import generate_lrc
from spotdl.utils.metadata import embed_metadata, get_file_metadata
from spotdl.utils.search import QueryError, get_search_results, reinit_song
from spotdl.utils.search import QueryError, get_search_results, parse_query, reinit_song

__all__ = ["meta"]

Expand Down Expand Up @@ -52,6 +52,7 @@ def meta(query: List[str], downloader: Downloader) -> None:
paths.append(test_path)

def process_file(file: Path):
# metadata of the file, url is present in the file.
song_meta = get_file_metadata(file, downloader.settings["id3_separator"])

# Check if song has metadata
Expand Down Expand Up @@ -144,7 +145,6 @@ def process_file(file: Path):
logger.info("Saved lrc file for %s", song.display_name)
else:
logger.info("Could not find lrc file for %s", song.display_name)

return None

async def pool_worker(file_path: Path) -> None:
Expand All @@ -159,3 +159,22 @@ async def pool_worker(file_path: Path) -> None:

# call all task asynchronously, and wait until all are finished
downloader.loop.run_until_complete(asyncio.gather(*tasks))

# to re-download the local songs
if downloader.settings["redownload"]:
songs_url: List[str] = []
for file in paths:
meta_data = get_file_metadata(
Path(file), downloader.settings["id3_separator"]
)
if meta_data and meta_data["url"]:
songs_url.append(meta_data["url"])

songs_list = parse_query(
songs_url,
downloader.settings["threads"],
downloader.settings["ytm_data"],
downloader.settings["playlist_numbering"],
)

downloader.download_multiple_songs(songs_list)
2 changes: 2 additions & 0 deletions spotdl/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class DownloaderOptions(TypedDict):
proxy: Optional[str]
skip_explicit: Optional[bool]
log_format: Optional[str]
redownload: Optional[bool]


class WebOptions(TypedDict):
Expand Down Expand Up @@ -162,6 +163,7 @@ class DownloaderOptionalOptions(TypedDict, total=False):
proxy: Optional[str]
skip_explicit: Optional[bool]
log_format: Optional[str]
redownload: Optional[bool]


class WebOptionalOptions(TypedDict, total=False):
Expand Down
8 changes: 8 additions & 0 deletions spotdl/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ def parse_output_options(parser: _ArgumentGroup):
choices=FFMPEG_FORMATS.keys(),
)

# download song in meta operation
parser.add_argument(
"--redownload",
action="store_const",
const=True,
help="to redownload the local song in diffrent format using --format for meta operation",
)


# Ignore songs from a paticular album
parser.add_argument(
Expand Down
1 change: 1 addition & 0 deletions spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def get_parameter(cls, key):
"proxy": None,
"skip_explicit": False,
"log_format": None,
"redownload": False,
}

WEB_OPTIONS: WebOptions = {
Expand Down

0 comments on commit 912adc9

Please sign in to comment.