Skip to content

Commit 912adc9

Browse files
Billa05xnetcat
andauthored
Feat: redownload flag for meta (#1944)
Co-authored-by: kuba <[email protected]>
1 parent 359f8fe commit 912adc9

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

spotdl/console/meta.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from spotdl.utils.ffmpeg import FFMPEG_FORMATS
1313
from spotdl.utils.lrc import generate_lrc
1414
from spotdl.utils.metadata import embed_metadata, get_file_metadata
15-
from spotdl.utils.search import QueryError, get_search_results, reinit_song
15+
from spotdl.utils.search import QueryError, get_search_results, parse_query, reinit_song
1616

1717
__all__ = ["meta"]
1818

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

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

5758
# Check if song has metadata
@@ -144,7 +145,6 @@ def process_file(file: Path):
144145
logger.info("Saved lrc file for %s", song.display_name)
145146
else:
146147
logger.info("Could not find lrc file for %s", song.display_name)
147-
148148
return None
149149

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

160160
# call all task asynchronously, and wait until all are finished
161161
downloader.loop.run_until_complete(asyncio.gather(*tasks))
162+
163+
# to re-download the local songs
164+
if downloader.settings["redownload"]:
165+
songs_url: List[str] = []
166+
for file in paths:
167+
meta_data = get_file_metadata(
168+
Path(file), downloader.settings["id3_separator"]
169+
)
170+
if meta_data and meta_data["url"]:
171+
songs_url.append(meta_data["url"])
172+
173+
songs_list = parse_query(
174+
songs_url,
175+
downloader.settings["threads"],
176+
downloader.settings["ytm_data"],
177+
downloader.settings["playlist_numbering"],
178+
)
179+
180+
downloader.download_multiple_songs(songs_list)

spotdl/types/options.py

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class DownloaderOptions(TypedDict):
8181
proxy: Optional[str]
8282
skip_explicit: Optional[bool]
8383
log_format: Optional[str]
84+
redownload: Optional[bool]
8485

8586

8687
class WebOptions(TypedDict):
@@ -162,6 +163,7 @@ class DownloaderOptionalOptions(TypedDict, total=False):
162163
proxy: Optional[str]
163164
skip_explicit: Optional[bool]
164165
log_format: Optional[str]
166+
redownload: Optional[bool]
165167

166168

167169
class WebOptionalOptions(TypedDict, total=False):

spotdl/utils/arguments.py

+8
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,14 @@ def parse_output_options(parser: _ArgumentGroup):
544544
choices=FFMPEG_FORMATS.keys(),
545545
)
546546

547+
# download song in meta operation
548+
parser.add_argument(
549+
"--redownload",
550+
action="store_const",
551+
const=True,
552+
help="to redownload the local song in diffrent format using --format for meta operation",
553+
)
554+
547555

548556
# Ignore songs from a paticular album
549557
parser.add_argument(

spotdl/utils/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def get_parameter(cls, key):
325325
"proxy": None,
326326
"skip_explicit": False,
327327
"log_format": None,
328+
"redownload": False,
328329
}
329330

330331
WEB_OPTIONS: WebOptions = {

0 commit comments

Comments
 (0)