How to use the lyricsgenius.utils.sanitize_filename 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 / tests / test_genius.py View on Github external
def determine_filenames(self, extension):
        expected_filenames = []
        for song in self.artist.songs:
            fn = "lyrics_{name}_{song}.{ext}".format(name=self.artist.name,
                                                     song=song.title,
                                                     ext=extension)
            fn = sanitize_filename(fn.lower().replace(" ", ""))
            expected_filenames.append(fn)
        return expected_filenames
github johnwmillr / LyricsGenius / lyricsgenius / artist.py View on Github external
result is returned as a string.
        :sanitize: Sanitizes the filename if True.

        OUTPUT
            If `filename` is None, returns the lyrics as
            a plain string. Otherwise None.
        """
        data = self._body
        data['songs'] = [song._body for song in self.songs]

        # Return the json string if no output path was specified
        if not filename:
            return json.dumps(data, indent=1)

        # Save Song object to a json file
        filename = sanitize_filename(filename) if sanitize else filename
        with open(filename, 'w') as ff:
            json.dump(data, ff, indent=1)
        return None
github johnwmillr / LyricsGenius / lyricsgenius / artist.py View on Github external
result is returned as a string.
        :binary_encoding: Enable binary encoding of text data.
        :sanitize: Sanitizes the filename if True.

        OUTPUT
            If `filename` is None, returns the lyrics as
            a plain string. Otherwise None.
        """
        data = ' '.join(song.lyrics for song in self.songs)

        # Return the lyrics as a string if no `filename` was specified
        if not filename:
            return data

        # Save song lyrics to a text file
        filename = sanitize_filename(filename) if sanitize else filename
        with open(filename, 'wb' if binary_encoding else 'w') as ff:
            if binary_encoding:
                data = data.encode('utf8')
            ff.write(data)
        return None
github johnwmillr / LyricsGenius / lyricsgenius / artist.py View on Github external
def save_lyrics(self,
                    filename=None,
                    extension='json',
                    overwrite=False,
                    binary_encoding=False,
                    sanitize=True,
                    verbose=True):
        """Saves all lyrics within an Artist object to a single file."""
        extension = extension.lstrip(".").lower()
        assert (extension == 'json') or (extension == 'txt'), "extension must be JSON or TXT"

        # Determine the filename
        if not filename:
            filename = 'Lyrics_' + self.name.replace(' ', '') + '.' + extension
        filename = sanitize_filename(filename) if sanitize else filename

        # Check if file already exists
        write_file = False
        if overwrite or not os.path.isfile(filename):
            write_file = True
        elif verbose:
            if input("{} already exists. Overwrite?\n(y/n): ".format(filename)).lower() == 'y':
                write_file = True

        # Exit if we won't be saving a file
        if not write_file:
            if verbose:
                print('Skipping file save.\n')
            return

        # Save the lyrics to a file

lyricsgenius

Download lyrics and metadata from Genius.com

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages