Repository navigation
Expand file tree
/
Copy pathexample_rym_usage.py
More file actions
112 lines (95 loc) · 3.55 KB
/
Copy pathexample_rym_usage.py
File metadata and controls
112 lines (95 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""
Example script demonstrating RYM metadata integration with streamrip.
This script shows how to:
1. Configure RYM metadata enrichment
2. Create album metadata
3. Enrich it with RateYourMusic data
4. See the results
"""
import asyncio
import os
import tempfile
from streamrip.config import RymConfig
from streamrip.metadata.rym_service import RymMetadataService
from streamrip.metadata.album import AlbumMetadata, AlbumInfo
from streamrip.metadata.covers import Covers
async def main():
print("🎵 RYM Metadata Integration Example\n")
# Create RYM configuration
rym_config = RymConfig(
enabled=True,
genre_mode="replace", # "replace" or "append"
proxy_enabled=False,
proxy_host="",
proxy_port_start=8080,
proxy_port_end=8090,
proxy_username="",
proxy_password="",
proxy_rotation_method="port",
session_type="sticky",
auto_rotate_on_failure=True
)
# Create RYM service
with tempfile.TemporaryDirectory() as cache_dir:
rym_service = RymMetadataService(rym_config, cache_dir)
# Create example album metadata
info = AlbumInfo(
id="test_album",
quality=2,
container="FLAC"
)
album = AlbumMetadata(
info=info,
album="OK Computer",
albumartist="Radiohead",
year="1997",
genre=["Alternative Rock"], # Original genre from streaming service
covers=Covers(),
tracktotal=12
)
print("📀 Original Album Metadata:")
print(f" Artist: {album.albumartist}")
print(f" Album: {album.album}")
print(f" Year: {album.year}")
print(f" Original Genres: {album.genre}")
print(f" RYM Descriptors: {album.rym_descriptors}")
print()
# Enrich with RYM data
print("🌐 Enriching with RateYourMusic metadata...")
await album.enrich_with_rym(rym_service)
print("✨ Enriched Album Metadata:")
print(f" Artist: {album.albumartist}")
print(f" Album: {album.album}")
print(f" Year: {album.year}")
print(f" Enriched Genres: {album.genre}")
print(f" RYM Descriptors: {album.rym_descriptors}")
print()
# Show how genres are handled based on configuration
print("🔧 Genre Mode Configuration:")
print(f" Current mode: {rym_config.genre_mode}")
if rym_config.genre_mode == "replace":
print(" → RYM genres replace original genres")
elif rym_config.genre_mode == "append":
print(" → RYM genres are added to original genres")
print()
# Cleanup
await rym_service.close()
print("💾 The enriched metadata would be tagged to audio files with:")
print(" FLAC: RYM_DESCRIPTORS tag")
print(" MP3: TXXX:RYM_DESCRIPTORS tag")
print(" MP4: ----:com.apple.iTunes:RYM_DESCRIPTORS tag")
if __name__ == "__main__":
print("Note: This example requires internet access to fetch RYM data.")
print("Set RYM proxy configuration in the script if needed for your setup.\n")
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\n❌ Interrupted by user")
except Exception as e:
print(f"\n❌ Error: {e}")
print("\nThis might happen if:")
print("- No internet connection")
print("- RateYourMusic is blocking requests")
print("- Album not found on RYM")
print("- Proxy configuration needed")