@@ -90,7 +90,9 @@ def sync_release(item, references, attachments, token, lp_date, index):
9090 url = release_url (info )
9191 title = info ["title" ]
9292 year = info .get ("year" ) or ""
93- artists = [clean_artist (a ["name" ]) for a in info .get ("artists" , []) if a .get ("name" )]
93+ artists = [
94+ clean_artist (a ["name" ]) for a in info .get ("artists" , []) if a .get ("name" )
95+ ]
9496
9597 existing = index .get (url .rstrip ("/" ))
9698 if existing :
@@ -107,16 +109,21 @@ def sync_release(item, references, attachments, token, lp_date, index):
107109 ext = os .path .splitext (cover .split ("?" )[0 ])[1 ] or ".jpeg"
108110 cover_file = f"{ base } { ext } "
109111 try :
110- vaultlib .download (cover , os .path .join (attachments , cover_file ),
111- {"User-Agent" : UA , "Authorization" : f"Discogs token={ token } " })
112+ vaultlib .download (
113+ cover ,
114+ os .path .join (attachments , cover_file ),
115+ {"User-Agent" : UA , "Authorization" : f"Discogs token={ token } " },
116+ )
112117 except Exception as e :
113118 print (f" war: cover download failed for { title } : { e } " , file = sys .stderr )
114119 cover_file = None
115120
116121 for a in artists :
117122 vaultlib .ensure_person_note (references , a , "Artists" )
118123
119- vaultlib .write_note (path , album_note (title , year , artists , cover_file , url , lp_date ))
124+ vaultlib .write_note (
125+ path , album_note (title , year , artists , cover_file , url , lp_date )
126+ )
120127 index [url .rstrip ("/" )] = path
121128 kind = "owned" if lp_date else "wishlist"
122129 print (f" new album ({ kind } ): { os .path .basename (path )} ({ ', ' .join (artists )} )" )
@@ -132,10 +139,14 @@ def main(username, token, vault, include_wantlist):
132139 index = vaultlib .index_by_field (references , "discogs" )
133140 created = updated = 0
134141
135- collection = urljoin (BASE_URL , f"/users/{ username } /collection/folders/0/releases?sort=artist" )
142+ collection = urljoin (
143+ BASE_URL , f"/users/{ username } /collection/folders/0/releases?sort=artist"
144+ )
136145 for item in paginate (collection , token , "releases" ):
137146 date_added = (item .get ("date_added" ) or "" )[:10 ] # ISO ts -> YYYY-MM-DD
138- result = sync_release (item , references , attachments , token , date_added or None , index )
147+ result = sync_release (
148+ item , references , attachments , token , date_added or None , index
149+ )
139150 created += result == "new"
140151 updated += result == "updated"
141152
@@ -149,11 +160,23 @@ def main(username, token, vault, include_wantlist):
149160
150161
151162if __name__ == "__main__" :
152- p = argparse .ArgumentParser (description = "Sync Discogs collection + wantlist into vault Album notes." )
153- p .add_argument ("-u" , "--username" , default = os .environ .get ("DISCOGS_USERNAME" , "ngalaiko" ))
163+ p = argparse .ArgumentParser (
164+ description = "Sync Discogs collection + wantlist into vault Album notes."
165+ )
166+ p .add_argument (
167+ "-u" , "--username" , default = os .environ .get ("DISCOGS_USERNAME" , "ngalaiko" )
168+ )
154169 p .add_argument ("-t" , "--token" , default = os .environ .get ("DISCOGS_TOKEN" ))
155- p .add_argument ("--vault" , default = os .environ .get ("OBSIDIAN_VAULT_DIR" , "/var/lib/assistant/Vault" ))
156- p .add_argument ("--no-wantlist" , dest = "wantlist" , action = "store_false" , help = "skip the wantlist (owned records only)" )
170+ p .add_argument (
171+ "--vault" ,
172+ default = os .environ .get ("OBSIDIAN_VAULT_DIR" , "/var/lib/assistant/Vault" ),
173+ )
174+ p .add_argument (
175+ "--no-wantlist" ,
176+ dest = "wantlist" ,
177+ action = "store_false" ,
178+ help = "skip the wantlist (owned records only)" ,
179+ )
157180 args = p .parse_args ()
158181 if not args .token :
159182 sys .exit ("discogs: no token (set DISCOGS_TOKEN or pass --token)" )
0 commit comments