Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 #171

Merged
merged 45 commits into from
Feb 9, 2021
Merged

v3.0 #171

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3a5d852
Added vcr support for consistent tests
ludehon Sep 1, 2019
37bcd08
Merge branch 'master' into pr/109
allerter Nov 8, 2020
69dc4c3
added vcr to tests
allerter Nov 8, 2020
92a3d69
changed displaying types attributes as table in docs
allerter Nov 8, 2020
92816fd
add vcrpy to requirements
allerter Nov 8, 2020
33f096c
test tox.ini
allerter Nov 8, 2020
cfe657e
Revert "test tox.ini"
allerter Nov 8, 2020
99bf009
removed except in tests
allerter Nov 9, 2020
1d9f297
merge pr/109 into docs
allerter Nov 9, 2020
c1221ae
merge pr/109 into docs
allerter Nov 10, 2020
b77c6d1
- added checking for the instrumental attribute in song info
allerter Nov 10, 2020
5cb1668
added instrumental attribute to types.Song
allerter Nov 10, 2020
58cd38f
Revert "merge pr/109 into docs"
allerter Nov 10, 2020
0471eb9
add Song.instrumental to docs
allerter Nov 10, 2020
2d1f63c
- add instrumental to to_dict
allerter Nov 10, 2020
0ba9c74
set retries to 3
allerter Nov 10, 2020
e131b0d
- Genius: removed checking instrumental in search_artist (genius.arti…
allerter Nov 11, 2020
50e883d
add some description for charts
allerter Nov 11, 2020
f2ab716
remove Song.instrumental references
allerter Nov 11, 2020
1c39376
added raising TypeError when no token/empty token is passed
allerter Nov 12, 2020
bf8c076
- renamed album.songs to album.tracks
allerter Nov 21, 2020
9b72d56
added importing Track from types
allerter Nov 21, 2020
db0c3b3
- fixed issues in Track
allerter Nov 21, 2020
b84221d
- reconfigured get_user_token to accept code and state parameters
allerter Nov 28, 2020
2376a58
- updated get_user_token docstring
allerter Nov 28, 2020
4573de5
- removed test_get_user_token_client_flow as its unnecessary
allerter Nov 28, 2020
65b2980
- refactored get_user_token to allow use by token flow
allerter Dec 7, 2020
402eaf5
removed redundant requirements.txt file
allerter Dec 7, 2020
609b1bb
fixed tests issue
allerter Dec 7, 2020
bcf14f7
- added page_data endpoint to PublicAPI
allerter Dec 9, 2020
df213e3
handle instance where error response might not be json
allerter Jan 17, 2021
c0ad3eb
added test for page_data
allerter Jan 19, 2021
0385abd
fix typo in artist ID in example and test
allerter Jan 19, 2021
8cf520d
fixed TypeError when instantiating PublicAPI directly with no token p…
allerter Jan 19, 2021
7cc60e6
use built-in class name to define public api constructor
allerter Jan 19, 2021
838cc21
genius.lyrics: broke down urlthing parameter into song_url and song_id
allerter Jan 27, 2021
c51cb8b
added non-breaking space to punctuation words
allerter Jan 28, 2021
08691ca
linked to the snippets page in the usage page
allerter Feb 6, 2021
0cf0b3d
Revert "add vcrpy to requirements"
allerter Feb 7, 2021
468a806
Revert adding vcrpy to tests
allerter Feb 7, 2021
96bb0c6
Remove VCR from test_base.py
johnwmillr Feb 7, 2021
0c59c09
Remove VCR from test_genius.py and test_public_methods.py
allerter Feb 7, 2021
184432f
Update version to 3.0.0
johnwmillr Feb 7, 2021
4c7f312
added release notes for 3.0.0
allerter Feb 8, 2021
ab719c0
Set release date to 2021-02-08
johnwmillr Feb 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions docs/src/examples/snippets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Snippets
==================
Here are some snippets showcasing how the library can be used.

- `Authenticating using OAuth2`_
- `All the songs of an artist`_
- `Artist's least popular song`_
- `Getting songs that have a tag`
- `Authenticating using OAuth2`_
- `Getting song lyrics by URL or ID`_
- `Getting songs by tag (genre)`_
- `Getting the lyrics for all songs of a search`_
- `Searching for a song by lyrics`_
- `YouTube URL of artist's songs`_
Expand All @@ -23,7 +23,7 @@ Getting song lyrics by URL or ID

# Using Song URL
url = "https://genius.com/Andy-shauf-begin-again-lyrics"
genius.lyrics(url)
genius.lyrics(song_url=url)

# Using Song ID
# Requires an extra request to get song URL
Expand Down Expand Up @@ -101,8 +101,8 @@ Using :meth:`search_all <Genius.search_all>`:
for hit in request['sections'][2]['hits']:
print(hit['result']['title'])

Getting songs that have a tag
-----------------------------
Getting songs by tag (genre)
----------------------------
Genius has the following main tags:
``rap``, ``pop``, ``r-b``, ``rock``, ``country``, ``non-music``
To discover more tags, visit the `Genius Tags`_ page.
Expand All @@ -121,7 +121,7 @@ Genius probably has more than 1000 songs with the pop tag.
while page:
res = genius.tag('pop', page=page)
for hit in res['hits']:
song_lyrics = genius.lyrics(hit['url'])
song_lyrics = genius.lyrics(song_url=hit['url'])
lyrics.append(song_lyrics)
page = res['next_page']

Expand All @@ -135,7 +135,7 @@ Getting the lyrics for all songs of a search
songs = genius.search_songs('Begin Again Andy Shauf')
for song in songs['hits']:
url = song['result']['url']
song_lyrics = genius.lyrics(url)
song_lyrics = genius.lyrics(song_url=url)
# id = song['result']['id']
# song_lyrics = genius.lyrics(id)
lyrics.append(song_lyrics)
Expand Down Expand Up @@ -170,7 +170,6 @@ URI will work (for example ``http://example.com/callback``)

from lyricsgenius import OAuth2, Genius

# you can also use OAuth2.full_code_exchange()
auth = OAuth2.client_only_app(
'my_client_id',
'my_redirect_uri',
Expand Down Expand Up @@ -199,14 +198,18 @@ Authenticating another user
'my_client_id',
'my_redirect_uri',
'my_client_secret',
scope='all'
scope='all',
state='some_unique_value'
)

# this part is the same
url_for_user = auth.url
print('Redirecting you to ' + url_for_user)
redirected_url = 'https://example.com/?code=some_code'
token = auth.get_user_token(redirected_url)

# If we were using Flask:
code = request.args.get('code')
state = request.args.get('state')
token = auth.get_user_token(code, state)

genius = Genius(token)

Expand Down
151 changes: 151 additions & 0 deletions docs/src/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,67 @@ Classes
:nosignatures:

Stats
Track

.. autoclass:: Stats
:members:
:member-order: bysource
:no-show-inheritance:

.. autoclass:: Track
:members:
:member-order: bysource
:no-show-inheritance:


Album
------
An album from Genius that has the album's songs and their lyrics.

Attributes
^^^^^^^^^^
.. list-table::
:header-rows: 1

* - Attribute
- Type

* - _type
- :obj:`str`

* - api_path
- :obj:`str`

* - artist
- :class:`Artist`

* - cover_art_thumbnail_url
- :obj:`str`

* - cover_art_url
- :obj:`str`

* - full_title
- :obj:`str`

* - id
- :obj:`int`

* - name
- :obj:`str`

* - name_with_artist
- :obj:`str`

* - release_date_components
- :class:`datetime`

* - tracks
- :obj:`list` of :class:`Track`

* - url
- :obj:`str`


Methods
^^^^^^^^
Expand All @@ -59,6 +109,41 @@ Artist
The Artist object which holds the details of the artist
and the `Song`_ objects of that artist.

Attributes
^^^^^^^^^^
.. list-table::
:header-rows: 1

* - Attribute
- Type


* - api_path
- :obj:`str`

* - header_image_url
- :obj:`str`

* - id
- :obj:`int`

* - image_url
- :obj:`str`

* - is_meme_verified
- :obj:`bool`

* - is_verified
- :obj:`bool`

* - name
- :obj:`str`

* - songs
- :obj:`list`

* - url
- :obj:`str`

Methods
^^^^^^^^
Expand All @@ -83,6 +168,72 @@ Song
----
This is the Song object which holds the details of the song.

Attributes
^^^^^^^^^^
.. list-table::
:header-rows: 1

* - Attribute
- Type


* - annotation_count
- :obj:`int`

* - api_path
- :obj:`str`

* - artist
- :obj:`str`

* - full_title
- :obj:`str`

* - header_image_thumbnail_url
- :obj:`str`

* - header_image_url
- :obj:`str`

* - id
- :obj:`int`

* - lyrics
- :obj:`str`

* - lyrics_owner_id
- :obj:`int`

* - lyrics_state
- :obj:`str`

* - path
- :obj:`str`

* - primary_artist
- :class:`Artist`

* - pyongs_count
- :obj:`int`

* - song_art_image_thumbnail_url
- :obj:`str`

* - song_art_image_url
- :obj:`str`

* - stats
- :class:`Stats`

* - title
- :obj:`str`

* - title_with_featured
- :obj:`str`

* - url
- :obj:`str`

Methods
^^^^^^^^
.. autosummary::
Expand Down
51 changes: 51 additions & 0 deletions docs/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,56 @@

Release notes
=============
3.0.0 (2021-02-08)
------------------
New
***

- All requests now go through the ``Sender`` object. This provides
features such as retries ``genius.retries`` and handling HTTP and
timeout errors. For more info have a look at the guide about `request
error handling`_.
- Added ``OAuth2`` class to help with OAuth2 authentication.
- Added ``PublicAPI`` class to allow accessing methods of the public
API (genius.com/api). Check `this page`_ for a list of available
methods.
- Added the ``Album`` type and the ``genius.search_album()`` method.
- Added the ``genius.tag()`` method to get songs by tag.
- All API endpoints are now supported (e.g. ``upvote_annotation``).
- New additions to the docs.

Changed
*******

- ``GENIUS_CLIENT_ACCESS_TOKEN`` env var has been renamed to
``GENIUS_ACCESS_TOKEN``.
- ``genius.client_access_token`` has been renamed to
``genius.access_token``.
- ``genius.search_song()`` will also accept ``song_id``.
- Lyrics won't be fetched for instrumental songs and their lyrics will
be set to ``""``. You can check to see if a song is instrumental
using ``Song.instrumental``.
- Renamed all interface methods to remove redundant ``get_``
(``genius.get_song`` is now ``genius.song``).
- Renamed the lyrics method to ``genius.lyrics()`` to allow use by
users. It accepts song URLs and song IDs.
- Reformatted the types. Some attributes won't be available anymore.
More info on the `types page`_.
- ``save_lyrics()`` will save songs with ``utf8`` encoding when
``extension='txt'``.
- Using ``Genius()`` will check for the env var
``GENIUS_ACCESS_TOKEN``.

Other (CI, etc)
***************

- Bumped ``Sphinx`` to 3.3.0

.. _request error handling: https://lyricsgenius.readthedocs.io/en/master/other_guides.html#request-errors
.. _this page: https://lyricsgenius.readthedocs.io/en/latest/reference/genius.html
.. _types page: https://lyricsgenius.readthedocs.io/en/latest/reference/types.html#types


2.0.2 (2020-09-26)
------------------
Added
Expand All @@ -15,6 +65,7 @@ Added
:meth:`Artist.save_lyrics <types.Artist.save_lyrics>`
and :meth:`Artist.to_json <types.Artist.to_json>`


2.0.1 (2020-09-20)
------------------
Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/src/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Search for five songs by ‘The Beatles’ and save the lyrics:
python3 -m lyricsgenius artist "The Beatles" --max-songs 5 --save


There also examples under the docs of some methods.
You might also like checking out the :ref:`snippets` page.


.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion lyricsgenius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
__url__ = 'https://github.com/johnwmillr/LyricsGenius'
__description__ = 'A Python wrapper around the Genius API'
__license__ = 'MIT'
__version__ = '2.0.2'
__version__ = '3.0.0'
8 changes: 7 additions & 1 deletion lyricsgenius/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def artist_songs(self, artist_id, per_page=None, page=None, sort='title'):
Args:
artist_id (:obj:`int`): Genius artist ID
sort (:obj:`str`, optional): Sorting preference.
Either based on 'title' or 'popularity'.
Either based on 'title', 'popularity' or 'release_date'.
per_page (:obj:`int`, optional): Number of results to
return per request. It can't be more than 50.
page (:obj:`int`, optional): Paginated offset (number of the page).
Expand Down Expand Up @@ -526,11 +526,17 @@ def __init__(
retries=0,
**kwargs
):

# If PublicAPI was instantiated directly
# there is no need for a token anymore
public_api_constructor = False if self.__class__.__name__ == 'Genius' else True

# Genius PublicAPI Constructor
super().__init__(
response_format=response_format,
timeout=timeout,
sleep_time=sleep_time,
retries=retries,
public_api_constructor=public_api_constructor,
**kwargs
)