Skip to content

Commit 0ca3d93

Browse files
committed
Merge branch 'unstable' into master
2 parents 7db8d60 + b8177c0 commit 0ca3d93

File tree

14 files changed

+281
-36
lines changed

14 files changed

+281
-36
lines changed

.github/workflows/release.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PyPI Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout the latest release code
14+
uses: actions/checkout@v2
15+
- name: Setup Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: "3.9"
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install setuptools wheel twine
23+
- name: Install ytmdl locally
24+
run: python setup.py install
25+
- name: Generate the completion files
26+
run: python utils/completion.py
27+
- name: List files in current directory
28+
run: ls -al
29+
- name: Build the dist
30+
run: python setup.py sdist bdist_wheel
31+
- name: Upload to PyPI
32+
env:
33+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
34+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
35+
run: twine upload dist/*
36+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/
44
dist/
55
ytmdl.*
66
ytmdl/__pycache__/*
7+
.cache

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<div align="center">
66
<h1>YouTube Music Downloader</h1>
7-
<h4>Download songs from YouTube by getting the audio from YouTube and the metadata from sources like Itunes and Gaana.</h4>
7+
<h4>Download songs from YouTube by getting the audio from YouTube and the metadata from sources like Itunes, Spotify, Gaana etc.</h4>
88
</div>
99

1010
<div align="center" width="60%" height="auto">
@@ -38,7 +38,7 @@ Ytmdl also has an web app, you can try it out [here](https://ytmdl.deepjyoti30.d
3838
## Why this?
3939

4040
This app downloads a song by getting the audio from Youtube sources __using__ youtube-dl and then adds song information like
41-
artist name, album name, release date, thumbnail etc by fetching it from sources like Itunes, Gaana and other sources.
41+
artist name, album name, release date, thumbnail etc by fetching it from sources like Itunes, Spotify, Gaana and other sources.
4242

4343
__NO__. YoutubeDL doesn't do that. All youtube-dl does is lets you download audio from a video that you specify.
4444
__This app is not yet another youtube-dl clone.__
@@ -68,6 +68,7 @@ If you like my work, consider buying me a coffee or donating. In case you want t
6868
- [PyPi](#pypi)
6969
- [Arch Linux](#arch-linux)
7070
- [Gentoo](#gentoo)
71+
- [NixOS](#nixos)
7172
- [Windows](#windows)
7273
- [Manual](#manual)
7374

@@ -100,6 +101,14 @@ emerge -av --autounmask net-misc/ytmdl
100101

101102
Available in **src_prepare-overlay** [here](https://gitlab.com/src_prepare/src_prepare-overlay)
102103

104+
### NixOS
105+
106+
`ytmdl` can be installed using Nix with the command
107+
108+
```console
109+
nix-env -iA nixos.ytmdl
110+
```
111+
103112
### Windows
104113

105114
You need to install `ffmpeg` in order for `ytmdl` to work properly. This can be done by downloading the `ffmpeg` binary from [here](https://ffmpeg.org/download.html). Once downloaded, extract the file and find the `ffmpeg.exe` file. Copy the directory's path and add it to PATH in the following way.
@@ -150,11 +159,12 @@ You can manually install `ytmdl` by cloning this repository and running the `set
150159
```console
151160
usage: ytmdl [-h] [-q] [--song SONG-METADATA] [--choice CHOICE]
152161
[--artist ARTIST] [--album ALBUM] [--disable-metaadd]
153-
[--skip-meta] [-m] [--itunes-id ITUNES_ID] [--disable-sort]
154-
[--ask-meta-name] [--on-meta-error ON_META_ERROR] [--proxy URL]
155-
[--url URL] [--list PATH TO LIST] [--nolocal] [--format FORMAT]
156-
[--trim] [--version] [--keep-chapter-name]
157-
[--download-archive FILE] [--pl-start NUMBER] [--pl-end NUMBER]
162+
[--skip-meta] [-m] [--itunes-id ITUNES_ID]
163+
[--spotify-id SPOTIFY_ID] [--disable-sort] [--ask-meta-name]
164+
[--on-meta-error ON_META_ERROR] [--proxy URL] [--url URL]
165+
[--list PATH TO LIST] [--nolocal] [--format FORMAT] [--trim]
166+
[--version] [--keep-chapter-name] [--download-archive FILE]
167+
[--ignore-chapters] [--pl-start NUMBER] [--pl-end NUMBER]
158168
[--pl-items ITEM_SPEC] [--ignore-errors] [--title-as-name]
159169
[--level LEVEL] [--disable-file] [--list-level]
160170
[SONG_NAME ...]
@@ -194,6 +204,8 @@ optional arguments:
194204
file. The songs are matched by using the videoId. All
195205
downloaded song Id's are automatically added to the
196206
file.
207+
--ignore-chapters Ignore chapters if available in the video and treat it
208+
like one video
197209

198210
Metadata:
199211
--song SONG-METADATA The song to search in Metadata. Particularly useful
@@ -213,7 +225,11 @@ Metadata:
213225
will override this option, pass only one of them.
214226
-m, --manual-meta Manually enter song details.
215227
--itunes-id ITUNES_ID
216-
Direct lookup from itunes.
228+
Direct lookup from itunes. If passed, metadata will be
229+
automatically added.
230+
--spotify-id SPOTIFY_ID
231+
Direct lookup for Spotify tracks using the ID. If
232+
passed, metadata will be automatically added.
217233
--disable-sort Disable sorting of the metadata before asking for
218234
input. Useful if the song is in some other language
219235
and/or just a few providers are used.
@@ -278,6 +294,7 @@ As of the latest development branch, the following options can be changed from t
278294
| `DEFAULT_FORMAT` | Default format of the song | mp3 |
279295
| `ON_META_ERROR` | What to do if error occurs while writing meta | exit |
280296
| `ITUNES_COUNTRY` | Which region to use while searching from Itunes | US |
297+
| `SPOTIFY_COUNTRY` | Which market to use while searching from Spotify | US |
281298

282299
### Advanced Configuration
283300

bin/ytmdl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def arguments():
9696
metadata_group.add_argument('-m', '--manual-meta', help="Manually enter song\
9797
details.", action="store_true")
9898
metadata_group.add_argument(
99-
'--itunes-id', help="Direct lookup from itunes.")
99+
'--itunes-id', help="Direct lookup from itunes. If passed, metadata will be automatically added.")
100+
metadata_group.add_argument(
101+
"--spotify-id", help="Direct lookup for Spotify tracks using the ID. If passed, metadata will be automatically added.")
100102
metadata_group.add_argument("--disable-sort", help="Disable sorting of the metadata \
101103
before asking for input. Useful if the song is in some other language \
102104
and/or just a few providers are used.", action="store_true")
@@ -143,6 +145,9 @@ def arguments():
143145
the passed file. The songs are matched by using the videoId. All downloaded \
144146
song Id's are automatically added to the file.", default=None,
145147
metavar="FILE")
148+
parser.add_argument('--ignore-chapters', help="Ignore chapters if available in the video and treat \
149+
it like one video",
150+
action="store_true")
146151

147152
playlist_group = parser.add_argument_group("Playlist")
148153
playlist_group.add_argument(
@@ -281,7 +286,7 @@ def main(args):
281286

282287
songs_to_download = [{}]
283288
# If the chapters are present, we will have to iterate and extract each chapter
284-
if chapters:
289+
if chapters and not args.ignore_chapters:
285290
logger.info("The song has chapters in it.",
286291
"Each part will be extracted and worked accordingly.")
287292

examples/config

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,53 @@
4646
# The METADATA_PROVIDERS value is a comma separated
4747
# values that specifies wich API providers to use for getting
4848
# the song metadata. Available values right now are:
49-
# itunes, gaana, deezer, lastfm, musicbrainz, saavn.
49+
#
50+
# ---------
51+
# itunes, spotify, gaana, deezer, lastfm, musicbrainz, saavn.
52+
# ---------
53+
#
5054
# Please check the github page of ytmdl for more information.
5155
#
52-
#METADATA_PROVIDERS = "itunes, gaana"
56+
#METADATA_PROVIDERS = "itunes, spotify, gaana"
5357
#
5458
#*****************************************#
5559
# The DEFAULT_FORMAT denotes what to use as default for downloading.
5660
# Available values are:
61+
#
62+
# ---------
5763
# mp3, m4a, opus
64+
# ---------
5865
#
5966
#DEFAULT_FORMAT = "mp3"
6067
#
6168
#*****************************************#
6269
# What to do when something goes wrong while adding the metadata. This can
6370
# happen for various reasons like lack of metadata or network issues.
6471
# Available options are:
72+
#
73+
# ---------
6574
# exit, skip, manual
75+
# ---------
6676
#
6777
#ON_META_ERROR = "exit"
6878
#****************************************#
6979
# ITUNES SETTINGS
7080
# Which region to use while searching from Itunes.
7181
#
82+
#
83+
# Country where the song is to be searched for in Itunes.
84+
# The country helps if you're looking for regional songs in
85+
# which case Itunes orders the results accordingly.
86+
#
7287
# By default, 'US' will be used.
88+
#
7389
#ITUNES_COUNTRY = "US"
90+
#
91+
# Country where the song is to be searched for in Spotify.
92+
# The country helps if you're looking for regional songs in
93+
# which case Spotify orders the results accordingly.
94+
#
95+
# By default, 'US' is used
96+
#
97+
#SPOTIFY_COUNTRY = "US"
7498
#

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
'ffmpeg-python',
2323
'pysocks',
2424
'unidecode',
25-
'youtube_search',
25+
'youtube-search-python',
2626
'pyDes',
2727
'urllib3',
2828
'simber',
2929
'rich',
3030
'musicbrainzngs',
31-
'ytmusicapi'
31+
'ytmusicapi',
32+
'spotipy'
3233
]
3334

3435

ytmdl/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Store the version of the package
2-
__version__ = "2021.06.26-1"
2+
__version__ = "2021.07.26.dev"

ytmdl/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def search(song_name, args) -> Union[str, str]:
4343
logger.info('Quiet is enabled')
4444

4545
logger.info('Searching Youtube for {}{}{}'.format(
46-
Fore.LIGHTYELLOW_EX,
47-
song_name,
48-
Style.RESET_ALL
46+
Fore.LIGHTYELLOW_EX,
47+
song_name,
48+
Style.RESET_ALL
4949
))
5050

5151
data = yt.search(song_name, not args.disable_metaadd,
@@ -144,7 +144,7 @@ def convert(
144144
logger.debug("{}:{}".format(start, end))
145145
if start is not None and end is not None:
146146
conv_name = utility.extract_part_convert(
147-
path, passed_format, start, end)
147+
path, passed_format, start, end)
148148

149149
# We need to raise exception if something went wrong
150150
if type(conv_name) is not str:
@@ -218,6 +218,9 @@ def meta(conv_name: str, song_name: str, search_by: str, args):
218218
elif args.itunes_id:
219219
logger.info('Direct iTunes lookup for {}...'.format(args.itunes_id))
220220
TRACK_INFO = metadata.lookup_from_itunes(args.itunes_id)
221+
elif args.spotify_id:
222+
logger.info('Direct Spotify lookup for {}...'.format(args.spotify_id))
223+
TRACK_INFO = metadata.lookup_from_spotify(args.spotify_id)
221224
else:
222225
# Else add metadata in ordinary way
223226
logger.info('Getting song data for {}...'.format(search_by))

ytmdl/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ def __parse_dir_path(dir_path: str):
5353
ON_ERROR_DEFAULT = setupConfig.GIVE_DEFAULT(1, 'ON_META_ERROR')
5454

5555
ITUNES_COUNTRY = setupConfig.GIVE_DEFAULT(1, 'ITUNES_COUNTRY')
56+
57+
SPOTIFY_COUNTRY = setupConfig.GIVE_DEFAULT(1, 'SPOTIFY_COUNTRY')

ytmdl/dir.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ def dry_cleanup(current_path, passed_name):
197197
new_basename = "{}.{}".format(passed_name, extension)
198198
DEST = defaults.DEFAULT.SONG_DIR
199199

200+
# NOTE: If the DEST is a dynamic directory, then we cannot
201+
# do a dry cleanup. So we'll have to use the base directory
202+
# instead.
203+
if "$" in DEST:
204+
logger.debug(DEST)
205+
206+
# pylama:ignore=E501
207+
logger.warning(
208+
"Destination is a dynamic directory but this is a dry cleanup. Don't pass `--skip-meta` if you don't want this!")
209+
210+
# Use the base directory
211+
DEST = DEST[:DEST.find("$")]
212+
213+
logger.debug(f"Using {DEST} as destination instead")
214+
200215
logger.debug("Moving to: {}".format(DEST))
201216

202217
# Create the destination file name

0 commit comments

Comments
 (0)