Package: pylyrics2
pylyrics2A Python package to extract and analyze lyricsAuthors: Abhiket Gaurav, Artan Zandian, Macy Chan, Manju Abhinandana KumarOverviewThis package allows users to extract and analyze lyrics effortlessly. With pylyrics2 users can download songs attribute datasets from Kaggle, extract lyrics and generate a word cloud.FunctionsFunction NameInputOutputDescriptiondownload_datadataset,file_path,columnsPandas DataframeDownloads dataset fromkaggle datasetand extractcolumnsfrom csv fileextract_lyricssong_title,artistStringExtracts song lyrics of a songsong_titlebyartistclean_texttext,bool_contra_dictStringCleans up thelyricsby removing special characters, html tags, #tags, contraction words and convert everything to lower caseplot_cloudsong,file_path,max_font_size,max_words,background_colorImageCreates a word cloud image of most occuring words of a song/songs by an artistOur Package in the Python EcosystemThere exist similar packages Python. However, this package is more holistic, in the sense that it downloads the lyrics through APIs, cleans the text, and then makes the word cloud. There are packages which does one of these steps. This package takes care of all the steps. Of the many other similar packages, the following are examples that come close:PyLyrics,Cloud-Lyricsanddeezer.ioInstallationpipinstallpylyrics2FeaturesThepylyrics2packages contains the following four functions:download_data()The download data function downloads dataset from Kaggle, extracts the given columns from csv file and creates a dataframe.extract_lyrics()The extract lyrics function, extracts the lyrics from API for a song title and artist and saves it as a dataframe with columns song title, artist and lyrics.clean_text()The lyrics extracted fromextract_lyrics()are not clean. It removes special characters, html tags, #tags, contraction words and convert everything to lower case to get a cleaned paragraph.plot_cloud()The plot cloud function creates a word cloud of most occurring words in a song/songs by an artist.Dependenciespython = ^3.9pandas = ^1.2.3kaggle = ^1.5.12wordcloud = ^1.8.1matplotlib = ^3.5.1beautifulsoup4 = ^4.10.0UsageThepylyrics2package is a visual way to find prominent word used in a lyrics. Given a song title and artist's name, this package will show the word that is used most in that lyrics (or a group of lyrics)Downloading and SelectingThe first function in our package is thedownload_data(). Here you will input yourkaggle datasetand the columns to be extracted into a Pandas DataFrame withcolumnsargument.To use the Kaggle API, sign up for a Kaggle account atKaggle. Then go to the 'Account' tab of your user profile (https://www.kaggle.com/<username>/account) and select 'Create API Token'. This will trigger the download of kaggle.json, a file containing your API credentials. Place this file in the location~/.kaggle/kaggle.json. The function will automatically read your Kaggle credentials from the above path.frompylyrics2importdownload_dataasdd# Example dataset: Spotify Song Attributesdataset="geomack/spotifyclassification"file_path="data/spotify_attributes"columns=["song_title","artist"]# Extract columnsdd.download_data(dataset,"data/spotify_attributes",["song_title","artist"])Extracting LyricsTheextract_lyrics()function gets thesong_titleandartistname, checks validity and avialability of the combination, and extracts the lyrics for that song in a raw string format with header, footer etc which needs to be cleaned in order to create a human-readable text.frompylyrics2importextract_lyricsasel# extracting lyricsraw_lyrics=el.extract_lyrics("22","Taylor Swift")CleaningOurclean_text()function is straightforward. It turns the raw lyrics into a human-readable text.frompylyrics2importclean_textasct# Clean the extracted raw lyrics (text)clean_lyrics=ct.clean_text(raw_lyrics)Creating WordCloudWordCloud is an artistic rendering of the most frequent words in a text document. A higher occurrence for a word is translated into a larger text size.At this stage, we have helper functions to facilitate the extraction and cleaning of lyrics. Theplot_cloud()function accepts adictionarywithartistas dictionary key andsong_titleas values. It will then extract the lyrics for all songs in the dictionary and saves a WordCould of the most occurring terms in thefile_pathprovided by the user. The WordClould parameters to be set are self-explanatory:max_font_size,max_wordandbackground_color.frompylyrics2importplot_cloudaspc# plotting and saving WordCloudsong={"Taylor Swift":"all too well","Adele":"Hello"}file_path="data/wordcloud"pc.plot_cloud(song,file_path,max_font_size=30,max_words=100,background_color='black')DocumentationThe official documentation is hosted on Read the Docs:hereContributorsThe names of core development team is listed below.NameGitHub HandleAbhiket GauravabhiketArtan ZandianartanzandMacy ChanmacychanManju Abhinandana Kumarmanju-abhinandanaWe welcome and recognize all contributions. Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.Licensepylyrics2was created by Group 2. It is licensed under the terms of the MIT license.Creditspylyrics2was created withcookiecutterand thepy-pkgs-cookiecuttertemplate.