Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install --upgrade setuptools wheel twine
- name: Install ytmdl locally
run: python setup.py install
- name: Generate the completion files
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ positional arguments:
SONG_NAME Name of the song to download. Can be an URL to a
playlist as well. It will be automatically recognized.

options:
optional arguments:
-h, --help show this help message and exit
-q, --quiet Don't ask the user to select songs if more than one
search result. The first result in each case will be
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
exec(open("ytmdl/__version__.py").read())

req_pkgs = [
'yt-dlp>=2022.7.6',
'yt-dlp>=2024.4.9',
'httpx<0.28',
'mutagen',
'itunespy',
'requests',
Expand Down
2 changes: 1 addition & 1 deletion ytmdl/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Store the version of the package
__version__ = "2023.11.26"
__version__ = "2024.08.15.2"
3 changes: 1 addition & 2 deletions ytmdl/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def __replace_special_characters(passed_name: str) -> str:
/ with a `-` so that it does not raise any errors
related to the OS while moving the file
"""
# TODO: Also add support for removing backslash
return sub(r'/', '-', passed_name)
return sub(r'[\\/|&?;:#~!"<>$%^*{}[\]+=`´]+', '-', passed_name)


def get_abs_path(path_passed: str) -> str:
Expand Down
14 changes: 10 additions & 4 deletions ytmdl/song.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ def getChoice(SONG_INFO, type):
return choice - 1 if (choice != -1 and choice != -2) else choice


def get_song_name_to_save(name: str, format: str) -> str:
"""
Get the song name to save the song with.
"""
return f"{__replace_special_characters(name)}.{format}"


def set_MP3_data(song, song_path):
"""
Set the meta data if the passed data is mp3.
Expand Down Expand Up @@ -228,8 +235,7 @@ def set_MP3_data(song, song_path):

data.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = __replace_special_characters(
song.track_name) + '.mp3'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "mp3")

# Rename the downloaded file
to_save_as = os.path.join(
Expand Down Expand Up @@ -296,7 +302,7 @@ def set_M4A_data(song, song_path):

audio.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.m4a'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "m4a")

# Rename the downloaded file
os.rename(SONG_PATH, os.path.join(
Expand Down Expand Up @@ -361,7 +367,7 @@ def set_OPUS_data(song, song_path):

mutagen_file.save()

defaults.DEFAULT.SONG_NAME_TO_SAVE = song.track_name + '.opus'
defaults.DEFAULT.SONG_NAME_TO_SAVE = get_song_name_to_save(song.track_name, "opus")

# Rename the downloaded file
os.rename(SONG_PATH, os.path.join(
Expand Down
26 changes: 23 additions & 3 deletions ytmdl/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ def progress_handler(d):
stdout.flush()


def dw_using_yt(link, proxy, song_name, datatype, no_progress=False, ytdl_config: str = None, dont_convert: bool = False):
def dw_using_yt(
link,
proxy,
song_name,
datatype,
no_progress=False,
ytdl_config: str = None,
dont_convert: bool = False,
cookiefile=None,
creds = None
):
"""
Download the song using YTDL downloader and use downloader CLI's
functions to be used to display a progressbar.
Expand Down Expand Up @@ -121,6 +131,13 @@ def dw_using_yt(link, proxy, song_name, datatype, no_progress=False, ytdl_config
if proxy is not None:
ydl_opts['proxy'] = proxy

if cookiefile is not None:
ydl_opts['cookiefile'] = cookiefile

if creds is not None:
ydl_opts["username"] = creds.get("username", "")
ydl_opts["password"] = creds.get("password", "")

logger.debug("args passed: ", str(ydl_opts))
ydl = yt_dlp.YoutubeDL(ydl_opts)

Expand All @@ -139,7 +156,9 @@ def dw(
datatype='mp3',
no_progress=False,
ytdl_config: str = None,
dont_convert: bool = False
dont_convert: bool = False,
cookiefile: str = None,
creds = None
):
"""
Download the song.
Expand Down Expand Up @@ -173,7 +192,8 @@ def dw(

# Start downloading the song
status = dw_using_yt(value, proxy, name, datatype,
no_progress, ytdl_config, dont_convert)
no_progress, ytdl_config, dont_convert,
cookiefile, creds)

if status == 0:
return name
Expand Down