Skip to content

Instantly share code, notes, and snippets.

@leo60228
Created February 6, 2024 02:49
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 leo60228/b4812d9d46afdea037876db7a3adce8a to your computer and use it in GitHub Desktop.
Save leo60228/b4812d9d46afdea037876db7a3adce8a to your computer and use it in GitHub Desktop.
#!/usr/bin/env nix-shell
#!nix-shell -i python -p python3 python3Packages.yt-dlp python3Packages.mpd2 python3Packages.pyyaml
from yt_dlp import YoutubeDL
import sys
import mpd
from yaml import dump
pl = []
with YoutubeDL({'logtostderr': True, 'extract_flat': True}) as ydl:
pl = [x['url'] for x in ydl.extract_info(sys.argv[1])['entries']]
client = mpd.MPDClient()
client.connect("localhost", 6600)
for song in client.playlistinfo():
track = int(song['track'])
title = song['title']
artists = song['artist'].split(' - ')
time = int(song['time'])
minutes = time // 60
seconds = time % 60
duration = f'{minutes}:{seconds:02}'
yaml = {
'Track': title,
'Artists': artists,
'Duration': duration,
'URLs': [pl[track - 1]],
}
print('---')
print(dump(yaml, sort_keys=False), end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment