audio streaming app
plyr.fm
1#!/usr/bin/env python
2"""publish permission set lexicon to ATProto repo with specific rkey."""
3
4import asyncio
5from pathlib import Path
6
7from atproto import AsyncClient
8from pydantic import Field
9from pydantic_settings import BaseSettings, SettingsConfigDict
10
11ROOT = Path(__file__).parent.parent
12
13
14class Settings(BaseSettings):
15 model_config = SettingsConfigDict(env_file=str(ROOT / ".env"), extra="ignore")
16
17 plyrfm_handle: str = Field(validation_alias="PLYRFM_HANDLE")
18 plyrfm_password: str = Field(validation_alias="PLYRFM_PASSWORD")
19 namespace: str = Field(default="fm.plyr", validation_alias="NAMESPACE")
20
21
22async def main():
23 settings = Settings()
24
25 client = AsyncClient()
26 await client.login(settings.plyrfm_handle, settings.plyrfm_password)
27
28 permission_set_id = f"{settings.namespace}.authFullApp"
29
30 record = {
31 "$type": "com.atproto.lexicon.schema",
32 "lexicon": 1,
33 "id": permission_set_id,
34 "defs": {
35 "main": {
36 "type": "permission-set",
37 "title": "Full plyr.fm Access",
38 "detail": "Provides full access to all plyr.fm features including uploading and managing tracks, playlists, likes, and comments.",
39 "permissions": [
40 {
41 "type": "permission",
42 "resource": "repo",
43 "action": ["create", "update", "delete"],
44 "collection": [
45 f"{settings.namespace}.track",
46 f"{settings.namespace}.like",
47 f"{settings.namespace}.comment",
48 f"{settings.namespace}.list",
49 f"{settings.namespace}.actor.profile",
50 ],
51 }
52 ],
53 }
54 },
55 }
56
57 result = await client.com.atproto.repo.put_record(
58 {
59 "repo": client.me.did,
60 "collection": "com.atproto.lexicon.schema",
61 "rkey": permission_set_id,
62 "record": record,
63 }
64 )
65
66 print(f"created: {result.uri}")
67 print(f"cid: {result.cid}")
68
69
70if __name__ == "__main__":
71 asyncio.run(main())