Skip to content

Commit

Permalink
Add trending
Browse files Browse the repository at this point in the history
The **--trending** flag now shows the top 50 tracks of the week.
  • Loading branch information
ZingyTomato committed Jul 4, 2022
1 parent 29a9bf0 commit aca89ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 13 additions & 0 deletions harmony/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

LYRICS_API = "https://api.textyl.co/api"

TRENDING_API = "https://charts-spotify-com-service.spotify.com/public/v0/charts"

SUB_FILE = ""

def emptyQueue():
Expand Down Expand Up @@ -172,4 +174,15 @@ def addSongs(videoid, title, author, duration, explicit):
added = print(colored(f"\n{fixFormatting(title)} - ", 'cyan') + colored(f"{fixFormatting(author)}", 'red') + colored(" has been added to the queue.", 'green'))
return songs.searchSongs()

def getTrending():
clearScreen()
print(colored("\nSearching for trending tracks...\n", 'cyan', attrs=['bold']))
searchurl = requests.request("GET", f"{TRENDING_API}", headers=headers).text.encode()
searchjson = json.loads(searchurl)
return showTrending(searchjson)

def showTrending(result):
lists = print(f"\n".join([f"{colored(i, 'green')}. {colored(fixFormatting(item['trackMetadata']['trackName']), 'red', attrs=['bold'])} - {fixFormatting(colored(item['trackMetadata']['artists'][0]['name'], 'cyan'))}" for i, item in enumerate((result['chartEntryViewResponses'][0]['entries']), start=1)]))
return

signal.signal(signal.SIGINT, forceQuit)
6 changes: 5 additions & 1 deletion harmony/harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

parser.add_argument('SEARCH_QUERY', help="Name of the song to search for. Example: harmony 2step Ed Sheeran", type=str, nargs="*")

parser.add_argument('-t', '--trending', help="See the top 50 trending songs of the week.", action="store_true")

args = parser.parse_args()

if " ".join(args.SEARCH_QUERY) == "":
if args.trending:
functions.getTrending()
elif " ".join(args.SEARCH_QUERY) == "":
print(colored("Please enter the name of a song! Type -h for help.", 'red', attrs=['bold']))
else:
songs.listTracks(" ".join(args.SEARCH_QUERY))

0 comments on commit aca89ef

Please sign in to comment.