Skip to content

Commit

Permalink
optional flags to pass artist and album name are added.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Dec 10, 2018
1 parent f18fed8 commit 2ae910c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
13 changes: 10 additions & 3 deletions bin/ytmdl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ def arguments():
if more than one search result.\
The first result in each case will be considered.",
action='store_true')
parser.add_argument('--version', action='version', version='2018.11.10',
parser.add_argument('--artist', help="Name of the artist")
parser.add_argument('--album', help="Name of the album.")
parser.add_argument('--version', action='version', version='2018.12.10',
help='show the program version number and exit')
parser.add_argument('--url',
help="Youtube song link.")
parser.add_argument('--better-search', help="Better search is addition of\
passed artist and album keyword to the youtube search\
in order to get a more accurate result. (Default: true)",
type=bool, default=True)
parser.add_argument('-s', '--setup',
help='Setup the config file',
action='store_true')
Expand Down Expand Up @@ -102,7 +108,8 @@ def main(args):
print(song_name, end='')
print(Style.RESET_ALL)

data, urls = yt.search(song_name)
data, urls = yt.search(song_name, args.better_search,
kw=[args.artist, args.album])

if len(data) > 1 and not is_quiet:
# Ask for a choice
Expand Down Expand Up @@ -147,7 +154,7 @@ def main(args):
print('Getting song data...')

# TRACK_INFO = song.getData(song_name)
TRACK_INFO = metadata.SEARCH_SONG(song_name)
TRACK_INFO = metadata.SEARCH_SONG(song_name, filters=[args.artist, args.album])

# declare a variable to store the option
option = 0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if __name__ == '__main__':
setuptools.setup(
name="ytmdl",
version="2018.11.10",
version="2018.12.10",
author="Deepjyoti Barman",
author_email="[email protected]",
description="Youtube Music Downloader",
Expand Down
11 changes: 9 additions & 2 deletions ytmdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ def arguments():
if more than one search result.\
The first result in each case will be considered.",
action='store_true')
parser.add_argument('--artist', help="Name of the artist")
parser.add_argument('--album', help="Name of the album.")
parser.add_argument('--version', action='version', version='2018.11.10',
help='show the program version number and exit')
parser.add_argument('--url',
help="Youtube song link.")
parser.add_argument('--better-search', help="Better search is addition of\
passed artist and album keyword to the youtube search\
in order to get a more accurate result. (Default: true)",
type=bool, default=True)
parser.add_argument('-s', '--setup',
help='Setup the config file',
action='store_true')
Expand Down Expand Up @@ -102,7 +108,8 @@ def main(args):
print(song_name, end='')
print(Style.RESET_ALL)

data, urls = yt.search(song_name)
data, urls = yt.search(song_name, args.better_search,
kw=[args.artist, args.album])

if len(data) > 1 and not is_quiet:
# Ask for a choice
Expand Down Expand Up @@ -147,7 +154,7 @@ def main(args):
print('Getting song data...')

# TRACK_INFO = song.getData(song_name)
TRACK_INFO = metadata.SEARCH_SONG(song_name)
TRACK_INFO = metadata.SEARCH_SONG(song_name, filters=[args.artist, args.album])

# declare a variable to store the option
option = 0
Expand Down
35 changes: 33 additions & 2 deletions ytmdl/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,32 @@ def _search_tokens(song_name, song_list):
return res


def SEARCH_SONG(q="Tera Buzz"):
def filterSongs(data, filters={}):
"""Filter the songs according to the passed filters.
In the passed filters the first element is artist.
The second element is album."""

new_tuple = []
rest = []

for songData in data:
aritstMatch = True
albumMatch = True

if filters[0] is not None:
aritstMatch = (songData.artist_name == filters[0])
if filters[1] is not None:
albumMatch = (songData.collection_name == filters[1])

if aritstMatch and albumMatch:
new_tuple.append(songData)
else:
rest.append(songData)
return (new_tuple + rest)


def SEARCH_SONG(q="Tera Buzz", filters=[]):
"""Do the task by calling other functions."""
to_be_sorted = []
rest = []
Expand All @@ -63,6 +88,12 @@ def SEARCH_SONG(q="Tera Buzz"):
data_itunes = get_from_itunes(q)
data_gaana = get_from_gaana(q)

# Before passing for sorting filter the songs
# with the passed args
if len(filters) != 0:
data_itunes = filterSongs(data_itunes, filters)
data_gaana = filterSongs(data_gaana, filters)

if data_itunes is not None:
to_be_sorted = data_itunes[:10]
rest = data_itunes[10:]
Expand All @@ -84,7 +115,7 @@ def SEARCH_SONG(q="Tera Buzz"):


if __name__ == '__main__':
n = SEARCH_SONG("How would you feel (Paean)")
n = SEARCH_SONG("Mia", ['Drake', None])

for i in n:
print(i.track_name + ' by ' + i.artist_name + ' of ' + i.collection_name)
8 changes: 7 additions & 1 deletion ytmdl/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_href(url):
return part


def search(querry, lim=10):
def search(querry, bettersearch, kw=[], lim=10):
"""Search the querry in youtube and return lim number of results.
Querry is the keyword, i:e name of the song
Expand All @@ -95,6 +95,12 @@ def search(querry, lim=10):
video = []
urls = []

# Add keywords if better search is enabled
if bettersearch:
for keyword in kw:
if keyword is not None:
querry += ' ' + keyword

# Replace all the spaces with +
querry = querry.replace(' ', '+')

Expand Down

0 comments on commit 2ae910c

Please sign in to comment.