spotify-genius 0.1.0__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.
- spotify_genius-0.1.0/LICENSE +21 -0
- spotify_genius-0.1.0/PKG-INFO +12 -0
- spotify_genius-0.1.0/README.md +71 -0
- spotify_genius-0.1.0/pyproject.toml +26 -0
- spotify_genius-0.1.0/setup.cfg +4 -0
- spotify_genius-0.1.0/src/spotify_genius/__init__.py +7 -0
- spotify_genius-0.1.0/src/spotify_genius/core/__init__.py +5 -0
- spotify_genius-0.1.0/src/spotify_genius/core/genius.py +41 -0
- spotify_genius-0.1.0/src/spotify_genius/main.py +26 -0
- spotify_genius-0.1.0/src/spotify_genius/platforms/__init__.py +10 -0
- spotify_genius-0.1.0/src/spotify_genius/platforms/linux.py +28 -0
- spotify_genius-0.1.0/src/spotify_genius/platforms/windows.py +71 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/PKG-INFO +12 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/SOURCES.txt +16 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/dependency_links.txt +1 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/entry_points.txt +2 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/requires.txt +8 -0
- spotify_genius-0.1.0/src/spotify_genius.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 André Ferreira
|
|
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.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spotify-genius
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open Genius lyrics for the currently playing Spotify track
|
|
5
|
+
Author: Andre Ferreira
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: unidecode
|
|
9
|
+
Requires-Dist: pywin32; platform_system == "Windows"
|
|
10
|
+
Requires-Dist: psutil; platform_system == "Windows"
|
|
11
|
+
Requires-Dist: dbus-python; platform_system == "Linux"
|
|
12
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Spotify/Genius Automation
|
|
2
|
+
|
|
3
|
+
This python script works as a listener to the music that is being played on the user's Spotify Desktop App for Windows.
|
|
4
|
+
|
|
5
|
+
The program gets the information of the currently playing song (artist and title) and automatically opens its respective page on Genius website, so the user can keep track of the song lyrics, besides taking advantage of other tools available on the website.
|
|
6
|
+
|
|
7
|
+
## How to download
|
|
8
|
+
|
|
9
|
+
Go to [releases](https://github.com/andrefcordeiro/spotify-genius-automation/releases) and download the latest version.
|
|
10
|
+
|
|
11
|
+
## Hot to run by yourself
|
|
12
|
+
|
|
13
|
+
### Requirements
|
|
14
|
+
|
|
15
|
+
- Python >=3.10
|
|
16
|
+
|
|
17
|
+
### Steps
|
|
18
|
+
|
|
19
|
+
1. Install dependencies
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
pip install .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Run
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
spotify-genius
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## How to generate the windows .exe
|
|
32
|
+
|
|
33
|
+
### Requirements
|
|
34
|
+
|
|
35
|
+
- Python >=3.10
|
|
36
|
+
|
|
37
|
+
### Steps
|
|
38
|
+
|
|
39
|
+
1. Install [PyInstaller](https://pyinstaller.org/en/stable/).
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
pip install pyinstaller
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. In the root folder of the project, run
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pyinstaller --onefile --icon=assets/spotify-genius.ico --name spotify-genius-win spotify-genius.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The binary `spotify-genius.exe` will be created in `dist`.
|
|
52
|
+
|
|
53
|
+
## How to generate linux executable
|
|
54
|
+
|
|
55
|
+
### Requirements
|
|
56
|
+
|
|
57
|
+
- Python >=3.10
|
|
58
|
+
|
|
59
|
+
### Steps
|
|
60
|
+
|
|
61
|
+
1. Install [PyInstaller](https://pyinstaller.org/en/stable/).
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
pip install pyinstaller
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2. In the root folder of the project, run
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
pyinstaller --onefile --name spotify-genius-linux src/spotify_genius/main.py
|
|
71
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "spotify-genius"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Open Genius lyrics for the currently playing Spotify track"
|
|
5
|
+
authors = [{ name = "Andre Ferreira" }]
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
|
|
8
|
+
dependencies = [
|
|
9
|
+
"unidecode",
|
|
10
|
+
"pywin32; platform_system == 'Windows'",
|
|
11
|
+
"psutil; platform_system == 'Windows'",
|
|
12
|
+
"dbus-python; platform_system == 'Linux'"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
spotify-genius = "spotify_genius.main:run"
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["setuptools", "wheel"]
|
|
20
|
+
build-backend = "setuptools.build_meta"
|
|
21
|
+
|
|
22
|
+
[tool.setuptools]
|
|
23
|
+
package-dir = {"" = "src"}
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from unidecode import unidecode
|
|
3
|
+
|
|
4
|
+
import webbrowser
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def remove_features(title_song: str) -> str:
|
|
8
|
+
return re.sub(
|
|
9
|
+
r"\s*\((feat|ft|with)[^)]*\)",
|
|
10
|
+
"",
|
|
11
|
+
title_song,
|
|
12
|
+
flags=re.IGNORECASE
|
|
13
|
+
).strip()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def generate_genius_slug(artist: str, title: str) -> str:
|
|
17
|
+
title = remove_features(title)
|
|
18
|
+
|
|
19
|
+
text = f"{artist} {title}"
|
|
20
|
+
|
|
21
|
+
text = text.replace("'", "")
|
|
22
|
+
|
|
23
|
+
text = text.replace('"', "")
|
|
24
|
+
|
|
25
|
+
text = text.replace("&", "and")
|
|
26
|
+
|
|
27
|
+
text = unidecode(text)
|
|
28
|
+
|
|
29
|
+
# Replace non-alphanumeric with hyphen
|
|
30
|
+
text = re.sub(r"[^a-zA-Z0-9]+", "-", text)
|
|
31
|
+
|
|
32
|
+
# Collapse multiple hyphens
|
|
33
|
+
text = re.sub(r"-+", "-", text)
|
|
34
|
+
|
|
35
|
+
return text.strip("-") + "-lyrics"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def open_genius(artist: str, title: str):
|
|
39
|
+
url = f"https://genius.com/{generate_genius_slug(artist, title)}"
|
|
40
|
+
print(f'Opening {url}')
|
|
41
|
+
webbrowser.open(url)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from spotify_genius.platforms import get_current_song
|
|
3
|
+
from spotify_genius.core import open_genius
|
|
4
|
+
|
|
5
|
+
def run():
|
|
6
|
+
previous = None
|
|
7
|
+
|
|
8
|
+
while True:
|
|
9
|
+
artist, title = get_current_song()
|
|
10
|
+
|
|
11
|
+
if not artist or not title:
|
|
12
|
+
time.sleep(2)
|
|
13
|
+
continue
|
|
14
|
+
|
|
15
|
+
current = (artist, title)
|
|
16
|
+
|
|
17
|
+
if current != previous:
|
|
18
|
+
previous = current
|
|
19
|
+
print(f'Now playing: {artist} - {title}')
|
|
20
|
+
|
|
21
|
+
open_genius(artist, title)
|
|
22
|
+
|
|
23
|
+
time.sleep(2)
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
run()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import platform
|
|
2
|
+
|
|
3
|
+
if platform.system() == "Windows":
|
|
4
|
+
from .windows import get_current_song
|
|
5
|
+
elif platform.system() == "Linux":
|
|
6
|
+
from .linux import get_current_song
|
|
7
|
+
else:
|
|
8
|
+
raise RuntimeError("Unsupported operating system")
|
|
9
|
+
|
|
10
|
+
__all__ = ["get_current_song"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import dbus
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_current_song():
|
|
5
|
+
try:
|
|
6
|
+
session_bus = dbus.SessionBus()
|
|
7
|
+
spotify_bus = session_bus.get_object(
|
|
8
|
+
"org.mpris.MediaPlayer2.spotify",
|
|
9
|
+
"/org/mpris/MediaPlayer2"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
interface = dbus.Interface(
|
|
13
|
+
spotify_bus,
|
|
14
|
+
"org.freedesktop.DBus.Properties"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
metadata = interface.Get(
|
|
18
|
+
"org.mpris.MediaPlayer2.Player",
|
|
19
|
+
"Metadata"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
artist = str(metadata["xesam:artist"][0])
|
|
23
|
+
title = str(metadata["xesam:title"])
|
|
24
|
+
|
|
25
|
+
return artist, title
|
|
26
|
+
|
|
27
|
+
except Exception:
|
|
28
|
+
return None, None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
import win32gui
|
|
3
|
+
import win32process
|
|
4
|
+
import psutil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
GetWindowText = ctypes.windll.user32.GetWindowTextW
|
|
8
|
+
GetWindowTextLength = ctypes.windll.user32.GetWindowTextLengthW
|
|
9
|
+
IsWindowVisible = ctypes.windll.user32.IsWindowVisible
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _get_spotify_pids():
|
|
13
|
+
spotify_pids = []
|
|
14
|
+
|
|
15
|
+
for proc in psutil.process_iter(["name"]):
|
|
16
|
+
try:
|
|
17
|
+
if proc.info["name"] and "Spotify.exe" in proc.info["name"]:
|
|
18
|
+
spotify_pids.append(proc.pid)
|
|
19
|
+
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
return spotify_pids
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _get_hwnds_for_pid(pid):
|
|
26
|
+
hwnds = []
|
|
27
|
+
|
|
28
|
+
def callback(hwnd, _):
|
|
29
|
+
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
|
|
30
|
+
if found_pid == pid:
|
|
31
|
+
hwnds.append(hwnd)
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
win32gui.EnumWindows(callback, None)
|
|
35
|
+
return hwnds
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _get_window_title(hwnd):
|
|
39
|
+
length = GetWindowTextLength(hwnd)
|
|
40
|
+
buff = ctypes.create_unicode_buffer(length + 1)
|
|
41
|
+
GetWindowText(hwnd, buff, length + 1)
|
|
42
|
+
return buff.value
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_current_song():
|
|
46
|
+
"""
|
|
47
|
+
Returns (artist, title) if Spotify is playing.
|
|
48
|
+
Returns (None, None) otherwise.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
pids = _get_spotify_pids()
|
|
52
|
+
|
|
53
|
+
for pid in pids:
|
|
54
|
+
hwnds = _get_hwnds_for_pid(pid)
|
|
55
|
+
|
|
56
|
+
for hwnd in hwnds:
|
|
57
|
+
if IsWindowVisible(hwnd):
|
|
58
|
+
title = _get_window_title(hwnd)
|
|
59
|
+
|
|
60
|
+
if " - " not in title:
|
|
61
|
+
continue
|
|
62
|
+
|
|
63
|
+
parts = title.split(" - ")
|
|
64
|
+
|
|
65
|
+
if len(parts) != 2:
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
artist, song = parts
|
|
69
|
+
return artist.strip(), song.strip()
|
|
70
|
+
|
|
71
|
+
return None, None
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spotify-genius
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open Genius lyrics for the currently playing Spotify track
|
|
5
|
+
Author: Andre Ferreira
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: unidecode
|
|
9
|
+
Requires-Dist: pywin32; platform_system == "Windows"
|
|
10
|
+
Requires-Dist: psutil; platform_system == "Windows"
|
|
11
|
+
Requires-Dist: dbus-python; platform_system == "Linux"
|
|
12
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/spotify_genius/__init__.py
|
|
5
|
+
src/spotify_genius/main.py
|
|
6
|
+
src/spotify_genius.egg-info/PKG-INFO
|
|
7
|
+
src/spotify_genius.egg-info/SOURCES.txt
|
|
8
|
+
src/spotify_genius.egg-info/dependency_links.txt
|
|
9
|
+
src/spotify_genius.egg-info/entry_points.txt
|
|
10
|
+
src/spotify_genius.egg-info/requires.txt
|
|
11
|
+
src/spotify_genius.egg-info/top_level.txt
|
|
12
|
+
src/spotify_genius/core/__init__.py
|
|
13
|
+
src/spotify_genius/core/genius.py
|
|
14
|
+
src/spotify_genius/platforms/__init__.py
|
|
15
|
+
src/spotify_genius/platforms/linux.py
|
|
16
|
+
src/spotify_genius/platforms/windows.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
spotify_genius
|