How to use the lyricsgenius.Genius function in lyricsgenius

To help you get started, we’ve selected a few lyricsgenius examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnwmillr / LyricsGenius / lyricsgenius / __main__.py View on Github external
help="Specify whether search is for 'song' or 'artist'")
    parser.add_argument("terms", type=str, nargs="+",
                        help="Provide terms for search")
    parser.add_argument("--save", action="store_true",
                        help="If specified, saves songs to JSON file")
    parser.add_argument("--max-songs", type=int,
                        help="Specify number of songs when searching for artist")
    parser.add_argument("-q", "--quiet", action="store_true",
                        help="Turn off the API verbosity")
    args = parser.parse_args()

    # Create an instance of the Genius class
    client_access_token = os.environ.get("GENIUS_CLIENT_ACCESS_TOKEN", None)
    msg = "Must declare environment variable: GENIUS_CLIENT_ACCESS_TOKEN"
    assert client_access_token, msg
    api = lyricsgenius.Genius(client_access_token)
    if args.quiet:
        api.verbose = False

    # Handle the command-line inputs
    if args.search_type == "song":
        song = api.search_song(*args.terms)
        if not song:
            if not args.quiet:
                print("Could not find specified song. Check spelling?")
            return
        print('\n"{s}" by {a}:\n\n{lyrics}\n'.format(s=song.title,
                                                     a=song.artist,
                                                     lyrics=song.lyrics))
        if args.save:
            if not args.quiet:
                print("Saving lyrics to '{s}'...".format(s=song.title))

lyricsgenius

Download lyrics and metadata from Genius.com

MIT
Latest version published 3 years ago

Package Health Score

55 / 100
Full package analysis

Similar packages