diff --git a/harmony/functions.py b/harmony/functions.py index 9bcb227..d91eb0e 100644 --- a/harmony/functions.py +++ b/harmony/functions.py @@ -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(): @@ -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) \ No newline at end of file diff --git a/harmony/harmony.py b/harmony/harmony.py index 7f1c47c..b1bb9f8 100644 --- a/harmony/harmony.py +++ b/harmony/harmony.py @@ -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)) \ No newline at end of file