Skip to content

Commit cbd0b0b

Browse files
committed
Merge branch 'unstable'
2 parents b016582 + 018676d commit cbd0b0b

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Use [pylama](https://github.com/klen/pylama) for linting.
3131
3.Modules
3232

3333
- Module names should be all lowercase
34-
- If more than one word, the words should be seperated by an underscore
34+
- If more than one word, the words should be separated by an underscore
3535
- It is preferrable to stick to single word for the module name
3636

3737
4.Constants
3838

3939
- Constant variables should be capitalized
40-
- If more than one word, the words can be seperated by an underscore
40+
- If more than one word, the words can be separated by an underscore

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ You can manually install `ytmdl` by cloning this repository and running the `set
144144
1. Clone this repo:
145145

146146
```console
147-
git clone https://github.com/deepjyoti30/ytmdl
147+
git clone https://github.com/deepjyoti30/ytmdl
148148
```
149149

150150
1. Move into the `ytmdl` directory and run the `setup.py` script:
@@ -157,7 +157,7 @@ You can manually install `ytmdl` by cloning this repository and running the `set
157157
## Usage
158158

159159
```console
160-
usage: ytmdl [-h] [-q] [--song SONG-METADATA] [--choice CHOICE]
160+
usage: ytmdl [-h] [-q] [-o SONG-DIR] [--song SONG-METADATA] [--choice CHOICE]
161161
[--artist ARTIST] [--album ALBUM] [--disable-metaadd]
162162
[--skip-meta] [-m] [--itunes-id ITUNES_ID]
163163
[--spotify-id SPOTIFY_ID] [--disable-sort] [--ask-meta-name]
@@ -178,6 +178,9 @@ optional arguments:
178178
-q, --quiet Don't ask the user to select songs if more than one
179179
search result. The first result in each case will be
180180
considered.
181+
-o, --output The location for the song to be downloaded
182+
to. When no argument is passed, the default locations
183+
of SONG_DIR or XDG_MUSIC_DIR are used.
181184
--proxy URL Use the specified HTTP/HTTPS/SOCKS proxy. To enable
182185
SOCKS proxy, specify a proper scheme. For example
183186
socks5://127.0.0.1:1080/. Pass in an empty string
@@ -233,7 +236,7 @@ Metadata:
233236
--disable-sort Disable sorting of the metadata before asking for
234237
input. Useful if the song is in some other language
235238
and/or just a few providers are used.
236-
--ask-meta-name Ask the user to enter a seperate name for searching
239+
--ask-meta-name Ask the user to enter a separate name for searching
237240
the metadata (Default: false)
238241
--on-meta-error ON_META_ERROR
239242
What to do if adding the metadata fails for some
@@ -244,7 +247,7 @@ Playlist:
244247
--pl-start NUMBER Playlist video to start at (default is 1)
245248
--pl-end NUMBER Playlist video to end at (default is last)
246249
--pl-items ITEM_SPEC Playlist video items to download. Specify indices of
247-
the videos present in the playlist seperated by commas
250+
the videos present in the playlist separated by commas
248251
like: '--playlist-items 1, 2, 4, 6' if you want to
249252
download videos indexed 1, 2, 4 and 6. Range can also
250253
be passed like: '--playlist-items 1-3, 5-7' to
@@ -288,7 +291,7 @@ As of the latest development branch, the following options can be changed from t
288291

289292
| Name | Description | Default |
290293
|:--------------------:|----------------------------------------------------|--------------------------------|
291-
| `SONG_DIR` | Directory to save the songs in after editing | Current direcotry |
294+
| `SONG_DIR` | Directory to save the songs in after editing | Current directory |
292295
| `SONG_QUALITY` | Quality of the song | 320kbps |
293296
| `METADATA_PROVIDERS` | Which API providers to use for metadata | all supported options are used |
294297
| `DEFAULT_FORMAT` | Default format of the song | mp3 |
@@ -302,7 +305,7 @@ As of the latest development branch, the following options can be changed from t
302305

303306
`SONG_DIR` field also takes values that are extracted from the song being downloaded
304307

305-
The `SONG_DIR` field needs to be passed some special values in order to achieve that. The string is scanned and when a `$` sign occurs, the special string will start and each directory can be seperated by using an `->` sign.
308+
The `SONG_DIR` field needs to be passed some special values in order to achieve that. The string is scanned and when a `$` sign occurs, the special string will start and each directory can be separated by using an `->` sign.
306309

307310
To save the song in the `/dir/<album_name>/<artist_name>/<title>/<song_name>.mp3` format, the following needs to be added in the `SONG_DIR` field.
308311

@@ -342,4 +345,3 @@ As of the latest source, the following options can be passed to the special stri
342345
| `Genre` | Genre Of the Song |
343346
| `TrackNumber` | TrackNumber Of the Song |
344347
| `ReleaseDate` | ReleaseDate Of the Song |
345-

bin/ytmdl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ from ytmdl.utils.archive import (
3939
is_present_in_archive,
4040
add_song_to_archive
4141
)
42+
from ytmdl.yt import is_yt_url
4243
from ytmdl.__version__ import __version__
4344

4445
# init colorama for windows
@@ -67,6 +68,10 @@ def arguments():
6768
if more than one search result.\
6869
The first result in each case will be considered.",
6970
action='store_true')
71+
parser.add_argument('-o', '--output-dir',
72+
help="The location for the song to be downloaded\
73+
to. When no argument is passed, the default locations\
74+
of SONG_DIR or XDG_MUSIC_DIR are used.")
7075
metadata_group = parser.add_argument_group("Metadata")
7176
metadata_group.add_argument(
7277
'--song', help="The song to search in Metadata. \
@@ -102,7 +107,7 @@ def arguments():
102107
metadata_group.add_argument("--disable-sort", help="Disable sorting of the metadata \
103108
before asking for input. Useful if the song is in some other language \
104109
and/or just a few providers are used.", action="store_true")
105-
metadata_group.add_argument("--ask-meta-name", help="Ask the user to enter a seperate \
110+
metadata_group.add_argument("--ask-meta-name", help="Ask the user to enter a separate \
106111
name for searching the metadata (Default: false)", action="store_true")
107112
metadata_group.add_argument("--on-meta-error", help="What to do if adding the metadata fails \
108113
for some reasong like lack of metadata or perhaps a network issue. \
@@ -168,7 +173,7 @@ def arguments():
168173
"--pl-items",
169174
help="Playlist video items to download. \
170175
Specify indices of the videos present in the\
171-
playlist seperated by commas like: '--playlist-items\
176+
playlist separated by commas like: '--playlist-items\
172177
1, 2, 4, 6' if you want to download videos indexed\
173178
1, 2, 4 and 6. Range can also be passed like:\
174179
'--playlist-items 1-3, 5-7' to download the videos\
@@ -443,6 +448,14 @@ def pre_checks(args):
443448
for opt in vars(args))))
444449
exit(0)
445450

451+
# Ensure the output directory is legitimate
452+
if (args.output_dir is not None):
453+
if path.isdir(path.expanduser(args.output_dir)):
454+
defaults.DEFAULT.SONG_DIR = path.expanduser(args.output_dir)
455+
else:
456+
logger.warning(
457+
"{}: is an invalid path. Continuing with default.".format(args.output_dir))
458+
446459
# Extract on-meta-error
447460
logger.debug("on_meta_error before: ", str(args.on_meta_error))
448461
on_meta_error = args.on_meta_error
@@ -502,7 +515,15 @@ def extract_data():
502515
logger.info("Downloading songs in {}".format(args.list))
503516
for song_name in songs:
504517
logger.debug(song_name)
505-
args.SONG_NAME = [song_name]
518+
519+
# Set the song name if an URL is not passed, else
520+
# pass it as an URL
521+
if is_yt_url(song_name):
522+
logger.debug("Detected passed song as URL")
523+
args.url = song_name
524+
else:
525+
args.SONG_NAME = [song_name]
526+
506527
main(args)
507528
else:
508529
logger.info("{}: is empty".format(args.list))

ytmdl/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def download(link, yt_title, args) -> str:
114114
defaults.DEFAULT.SONG_QUALITY,
115115
Style.RESET_ALL
116116
))
117-
path = yt.dw(link, args.proxy, yt_title, args.format)
117+
path = yt.dw(link, args.proxy, yt_title,
118+
args.format, no_progress=args.quiet)
118119

119120
if type(path) is not str:
120121
# Probably an error occured

ytmdl/dir.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __replace_special_characters(passed_name: str) -> str:
2323

2424

2525
def cleanup(TRACK_INFO, index, datatype, remove_cached=True):
26-
"""Move the song from temp to $HOME/Music dir."""
26+
"""Move the song from temp to the song dir."""
2727
try:
2828
SONG = glob.glob(os.path.join(
2929
defaults.DEFAULT.SONG_TEMP_DIR,
@@ -166,8 +166,8 @@ def make_custom_dir(DIR, TRACK_INFO):
166166
# Sometimes, certain strings have / in the name which creates
167167
# issues since those strings are used to create directories.
168168
# Whenever there is a /, replace it with -
169-
# Sometimes strings also contains [\,?,",<>] which may cause error
170-
dir_name = sub('[\\\\?<>/"]', "-", dir_name)
169+
# Sometimes strings also contains [\,?,",<>, *] which may cause error
170+
dir_name = sub('[\\\\?<>/"*]', "-", dir_name)
171171

172172
new_dir = os.path.join(base_DIR, dir_name)
173173

ytmdl/yt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def dw_using_yt(link, proxy, song_name, datatype, no_progress=False):
9595
}
9696

9797
if not no_progress:
98+
logger.debug("Enabling progress hook.")
99+
logger.debug(f"Passed value for no_progress: {no_progress}")
98100
ydl_opts['progress_hooks'] = [progress_handler]
99101

100102
if proxy is not None:
@@ -257,6 +259,14 @@ def is_playlist(url):
257259
return match(playlist_part, url)
258260

259261

262+
def is_yt_url(url):
263+
"""
264+
Check if the passed URL is a valid youtube URL.
265+
"""
266+
yt_url = r"https?://(www\.|music\.)?youtube\.com/watch\?v=.*?$"
267+
return match(yt_url, url)
268+
269+
260270
def get_playlist(
261271
url,
262272
proxy,

0 commit comments

Comments
 (0)