Skip to content

Instantly share code, notes, and snippets.

@cosven
Last active January 5, 2021 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosven/e0be79b7794e183ccfa163c06d7bc189 to your computer and use it in GitHub Desktop.
Save cosven/e0be79b7794e183ccfa163c06d7bc189 to your computer and use it in GitHub Desktop.
导出虾米歌单到 ~/.FeelUOwn/collections 目录并自动刷新 UI,运行方式:fuo exec < xiami_to_fuo_collection.py
import os
from tomlkit import document, value, dumps
from fuocore.models.uri import reverse
from fuo_xiami import provider
user = provider._user
if user is None:
raise Exception('你可能没有登录')
playlists = user.playlists
for playlist in playlists:
reader = playlist.create_songs_g()
songs = reader.readall()
lines = []
for song in songs:
lines.append(reverse(song, as_line=True))
identifier = playlist.identifier
# generate metadata for fuo playlist
doc = document()
doc.add('title', playlist.name)
doc.add('description', value(f'"""\n{playlist.desc}\n"""'))
filename = f'~/.FeelUOwn/collections/xiami-{identifier}.fuo'
filepath = os.path.expanduser(filename)
with open(filepath, 'w') as f:
# write metadata
f.write('+++\n')
f.write(dumps(doc))
f.write('\n+++\n')
# write contents
f.write('\n'.join(lines))
# pretty
f.write('\n')
print(f'playlist {playlist.name} saved in {filename}')
app.coll_uimgr.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment