merging and cleaning up
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
Perfekt – dann ist eine Subsonic-kompatible Library genau das, was du suchst 👍
|
||||
|
||||
Für [[Python]] gibt es z. B. [`py-sonic`](https://github.com/crustymonkey/py-sonic).
|
||||
Die ist zwar nicht mehr super aktiv gepflegt, funktioniert aber mit [[Navidrome]] problemlos, weil Navidrome die [[Subsonic-API]] spricht.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install py-sonic
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Grund-Setup
|
||||
|
||||
```python
|
||||
from pysonic.connection import Connection
|
||||
|
||||
# Verbindung aufbauen
|
||||
conn = Connection(
|
||||
host="http://localhost:4533",
|
||||
username="meinuser",
|
||||
password="meinpass",
|
||||
api_version="1.16.1",
|
||||
client_name="pyclient"
|
||||
)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Anwendungsfälle
|
||||
|
||||
### 1. Playlist erstellen oder öffnen
|
||||
|
||||
```python
|
||||
# Neue Playlist
|
||||
playlist = conn.create_playlist("Importierte M3U Playlist")
|
||||
|
||||
# Alle Playlists abfragen
|
||||
all_playlists = conn.get_playlists()
|
||||
```
|
||||
|
||||
### 2. Tracks suchen (z. B. per Filename, Titel, Artist)
|
||||
|
||||
```python
|
||||
search = conn.search2(query="Songtitel", songCount=5)
|
||||
for song in search['song']:
|
||||
print(song['id'], song['title'], song['artist'])
|
||||
```
|
||||
|
||||
### 3. Track zur Playlist hinzufügen
|
||||
|
||||
```python
|
||||
conn.update_playlist(
|
||||
playlist_id=playlist['id'],
|
||||
song_id=["12345", "67890"] # mehrere IDs möglich
|
||||
)
|
||||
```
|
||||
|
||||
### 4. Stern vergeben
|
||||
|
||||
```python
|
||||
conn.star("12345") # Song-ID
|
||||
```
|
||||
|
||||
### 5. Bookmark setzen
|
||||
|
||||
```python
|
||||
conn.create_bookmark("12345", position=60000, comment="Kapitel 1")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Workflow: M3U importieren
|
||||
|
||||
Du kannst einfach durch deine `.m3u`-Datei iterieren, für jede Zeile versuchen, den Track im Navidrome zu finden, und dann Aktionen ausführen:
|
||||
|
||||
```python
|
||||
def import_m3u_to_navidrome(m3u_path, playlist_name):
|
||||
# Playlist anlegen
|
||||
playlist = conn.create_playlist(playlist_name)
|
||||
playlist_id = playlist['id']
|
||||
|
||||
with open(m3u_path, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if line.startswith("#") or not line.strip():
|
||||
continue
|
||||
filename = line.strip().split("/")[-1] # nur Dateiname
|
||||
|
||||
# Suche im Server
|
||||
search = conn.search2(query=filename, songCount=1)
|
||||
if 'song' in search and search['song']:
|
||||
song = search['song'][0]
|
||||
song_id = song['id']
|
||||
|
||||
# Playlist hinzufügen
|
||||
conn.update_playlist(playlist_id=playlist_id, song_id=[song_id])
|
||||
|
||||
# Stern setzen
|
||||
conn.star(song_id)
|
||||
|
||||
# Bookmark bei 0 (Startpunkt)
|
||||
conn.create_bookmark(song_id, position=0, comment="Importiert aus M3U")
|
||||
|
||||
print(f"→ {filename} gefunden und verarbeitet.")
|
||||
else:
|
||||
print(f"⚠ {filename} nicht gefunden.")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
👉 Damit hättest du ziemlich genau deinen beschriebenen Workflow:
|
||||
M3U → Tracks auflösen → Playlist + Sterne + Bookmarks automatisch setzen.
|
||||
|
||||
---
|
||||
|
||||
Soll ich dir ein **vollständiges Script** bauen, das direkt eine `.m3u` einliest, die passende Playlist erstellt und alle drei Aktionen (Playlist-Eintrag, Stern, Bookmark) in einem Durchlauf macht?
|
||||
Reference in New Issue
Block a user