sung 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sung-0.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
sung-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.1
2
+ Name: sung
3
+ Version: 0.0.2
4
+ Summary: Music data access
5
+ Home-page: https://github.com/thorwhalen/sung
6
+ Author: Thor Whalen
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: spotipy
12
+ Requires-Dist: tabled
13
+ Requires-Dist: glom
14
+
15
+ # sung
16
+
17
+ Music data access. Mainly sources from spotify and wikipedia.
18
+
19
+ To install: ```pip install sung```
20
+
21
+
22
+ # Examples
23
+
24
+ ```python
25
+ >>> from sung import search_tracks
26
+ >>> search_tracks('Autumn leaves', limit=3, genre='jazz') # doctest: +ELLIPSIS
27
+ ```
sung-0.0.2/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # sung
2
+
3
+ Music data access. Mainly sources from spotify and wikipedia.
4
+
5
+ To install: ```pip install sung```
6
+
7
+
8
+ # Examples
9
+
10
+ ```python
11
+ >>> from sung import search_tracks
12
+ >>> search_tracks('Autumn leaves', limit=3, genre='jazz') # doctest: +ELLIPSIS
13
+ ```
sung-0.0.2/setup.cfg ADDED
@@ -0,0 +1,28 @@
1
+ [metadata]
2
+ name = sung
3
+ version = 0.0.2
4
+ url = https://github.com/thorwhalen/sung
5
+ platforms = any
6
+ description_file = README.md
7
+ root_url = https://github.com/thorwhalen/
8
+ license = mit
9
+ author = Thor Whalen
10
+ description = Music data access
11
+ long_description = file:README.md
12
+ long_description_content_type = text/markdown
13
+ keywords =
14
+ display_name = sung
15
+
16
+ [options]
17
+ packages = find:
18
+ include_package_data = True
19
+ zip_safe = False
20
+ install_requires =
21
+ spotipy
22
+ tabled
23
+ glom
24
+
25
+ [egg_info]
26
+ tag_build =
27
+ tag_date = 0
28
+
sung-0.0.2/setup.py ADDED
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup() # Note: Everything should be in the local setup.cfg
@@ -0,0 +1,10 @@
1
+ """
2
+ Tools to get music metadata (from Spotify, Wikipedia, etc.)
3
+
4
+ >>> from sung import search_tracks
5
+ >>> search_tracks('Autumn leaves', limit=3, genre='jazz') # doctest: +ELLIPSIS
6
+
7
+ """
8
+
9
+ from sung.base import search_tracks, track_metadata
10
+ from sung.util import extractor
@@ -0,0 +1,102 @@
1
+ """Base functionalities for the sung package."""
2
+
3
+ from typing import Callable
4
+ from operator import itemgetter
5
+ from sung.util import get_spotify_client, ensure_client, DFLT_LIMIT, extractor
6
+
7
+
8
+ # TODO: Include all modifiers in the signature (only year and genre for now)?
9
+ # TODO: Make signature using Spotify.search signature
10
+ def search_tracks(
11
+ query: str,
12
+ egress: Callable = extractor('tracks.items'),
13
+ *,
14
+ search_type='track',
15
+ market=None,
16
+ year=None,
17
+ genre=None,
18
+ limit: int = DFLT_LIMIT,
19
+ offset: int = 0,
20
+ client=get_spotify_client,
21
+ ):
22
+ """
23
+ Search for tracks on Spotify.
24
+
25
+ Parameters:
26
+ - query - the search query (see how to write a query in the
27
+ official documentation https://developer.spotify.com/documentation/web-api/reference/search/) # noqa
28
+ - search_type - the types of items to return. One or more of 'artist', 'album',
29
+ 'track', 'playlist', 'show', and 'episode'. If multiple types are desired,
30
+ pass in a comma separated string; e.g., 'track,album,episode'.
31
+ - market - An ISO 3166-1 alpha-2 country code or the string
32
+ from_token.
33
+ - limit - the number of items to return (min = 1, default = 10, max = 50). The limit is applied
34
+ within each type, not on the total response.
35
+ - offset - the index of the first item to return
36
+
37
+ """
38
+ client = ensure_client(client)
39
+
40
+ # Build query
41
+ # TODO: Make function using spotify_search_modifiers to do this
42
+ query_string = query
43
+ if year:
44
+ query_string += f" year:{year}"
45
+ if genre:
46
+ query_string += f" genre:{genre}"
47
+
48
+ # Execute search
49
+ results = client.search(
50
+ q=query_string, type=search_type, market=market, limit=limit, offset=offset
51
+ )
52
+
53
+ # Extract tracks and return a list of song names with additional details
54
+
55
+ # return map(egress, results)
56
+ return egress(results)
57
+ # if 'tracks' in results:
58
+ # for item in results['tracks']['items']:
59
+ # yield item
60
+
61
+
62
+ track_spec = {
63
+ 'name': 'name',
64
+ 'artist': ('artists', [0, 'name']),
65
+ 'album': 'album.name',
66
+ 'release_date': 'album.release_date',
67
+ 'duration_ms': 'duration_ms',
68
+ 'popularity': 'popularity',
69
+ 'explicit': 'explicit',
70
+ 'external_url': 'external_urls.spotify',
71
+ 'preview_url': 'preview_url',
72
+ 'track_number': 'track_number',
73
+ 'album_total_tracks': 'album.total_tracks',
74
+ 'available_markets': 'available_markets',
75
+ 'album_images': 'album.images',
76
+ }
77
+
78
+
79
+ def track_metadata(track_id, *, client=get_spotify_client):
80
+ client = ensure_client(client)
81
+
82
+ # Get track details
83
+ track = client.track(track_id)
84
+
85
+ # Prepare metadata dictionary
86
+ metadata = {
87
+ 'name': track['name'],
88
+ 'artist': track['artists'][0]['name'],
89
+ 'album': track['album']['name'],
90
+ 'release_date': track['album']['release_date'],
91
+ 'duration_ms': track['duration_ms'],
92
+ 'popularity': track['popularity'],
93
+ 'explicit': track['explicit'],
94
+ 'external_url': track['external_urls']['spotify'],
95
+ 'preview_url': track['preview_url'], # 30s preview if available
96
+ 'track_number': track['track_number'],
97
+ 'album_total_tracks': track['album']['total_tracks'],
98
+ 'available_markets': track['available_markets'],
99
+ 'album_images': track['album']['images'],
100
+ }
101
+
102
+ return metadata
@@ -0,0 +1,69 @@
1
+ """Utility functions for the sung package."""
2
+
3
+ # TODO: use openAPI definition to create pydantic models for data
4
+ # see https://github.com/thorwhalen/sung/discussions/1#discussioncomment-10990012
5
+
6
+ from typing import Literal, T, Callable, TypeVar
7
+ from functools import partial
8
+ from spotipy import Spotify
9
+ from spotipy.oauth2 import SpotifyClientCredentials
10
+ from glom import glom, Spec
11
+
12
+ import os
13
+
14
+ DFLT_LIMIT = 20
15
+
16
+ # TODO: Get automatically from pydantic model when available
17
+ SearchTypeT = Literal['artist', 'album', 'track', 'playlist', 'show', 'episode']
18
+
19
+
20
+ def identity(x: T) -> T:
21
+ return x
22
+
23
+
24
+ Extractor = TypeVar('Extractor', bound=Callable) # TODO: Specify more precisely
25
+
26
+
27
+ def extractor(spec: Spec) -> Extractor:
28
+ return partial(glom, spec=spec)
29
+
30
+
31
+ def get_config(config_name: str) -> str:
32
+ """Get the value of a configuration variable."""
33
+ if config_name in os.environ:
34
+ return os.environ[config_name]
35
+ else:
36
+ raise ValueError(
37
+ f"Configuration variable {config_name} not found. "
38
+ "Please set it in the environment. To get your Spotify API credentials, "
39
+ "see https://developer.spotify.com/documentation/web-api/tutorials/getting-started"
40
+ )
41
+
42
+
43
+ def get_spotify_client() -> Spotify:
44
+ return Spotify(
45
+ auth_manager=SpotifyClientCredentials(
46
+ client_id=get_config('SPOTIFY_API_CLIENT_ID'),
47
+ client_secret=get_config('SPOTIFY_API_CLIENT_SECRET'),
48
+ )
49
+ )
50
+
51
+
52
+ spotify_search_modifiers = {
53
+ "album:": "Search within album titles.",
54
+ "artist:": "Search within artist names.",
55
+ "genre:": "Restrict search results to a specific genre. Example: genre:jazz.",
56
+ "track:": "Search within track names.",
57
+ "year:": "Filter by release year. Accepts ranges (e.g., year:2000-2020).",
58
+ "tag:new": "Search for newly released songs.",
59
+ "tag:hipster": "Search for music outside the mainstream (less popular).",
60
+ "isrc:": "Search using the International Standard Recording Code.",
61
+ "upc:": "Search using the Universal Product Code.",
62
+ }
63
+
64
+
65
+ def ensure_client(client) -> Spotify:
66
+ if callable(client):
67
+ client_factory = client
68
+ client = client_factory()
69
+ return client
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.1
2
+ Name: sung
3
+ Version: 0.0.2
4
+ Summary: Music data access
5
+ Home-page: https://github.com/thorwhalen/sung
6
+ Author: Thor Whalen
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: spotipy
12
+ Requires-Dist: tabled
13
+ Requires-Dist: glom
14
+
15
+ # sung
16
+
17
+ Music data access. Mainly sources from spotify and wikipedia.
18
+
19
+ To install: ```pip install sung```
20
+
21
+
22
+ # Examples
23
+
24
+ ```python
25
+ >>> from sung import search_tracks
26
+ >>> search_tracks('Autumn leaves', limit=3, genre='jazz') # doctest: +ELLIPSIS
27
+ ```
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ sung/__init__.py
6
+ sung/base.py
7
+ sung/util.py
8
+ sung.egg-info/PKG-INFO
9
+ sung.egg-info/SOURCES.txt
10
+ sung.egg-info/dependency_links.txt
11
+ sung.egg-info/not-zip-safe
12
+ sung.egg-info/requires.txt
13
+ sung.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,3 @@
1
+ spotipy
2
+ tabled
3
+ glom
@@ -0,0 +1 @@
1
+ sung