2015-07-17 20 views
6

Non riesco a capire come interrogare correttamente mpd da mpc.mpd mpc query language

Per esempio: io so come elencare tutti gli album

mpc list album 

ma voglio ottenere di più quindi il nome.

Come è possibile interrogare mpd per nome album, percorso album, artista, numero traccia, lunghezza e così via. Preferibilmente in una query ma più query vanno bene.

Ho provato a leggere la pagina man di mpc e la documentazione ufficiale di mpd ma non riesco a capirlo.

risposta

2

mpc non (come di questa scrittura, v0.27-1) hanno tutti i comandi che ti danno tutti i metadati per una canzone, identificato di uri. È sorprendente che non lo sia, ma non lo è.

L'MPD communication protocol, tuttavia, restituisce informazioni complete su ogni brano.

Se io emetto mpc current ho solo questa risposta:

Afro Celt Sound System - Release 

Tuttavia, se io mando il comando currentsong MPD (non MPC), allora ottengo questa risposta da MPD:

file: gavin/Compilations/Volume 2 _ Release/01 Release.m4a 
Last-Modified: 2005-03-02T14:16:51Z 
Artist: Afro Celt Sound System 
Album: Volume 2 : Release 
Title: Release 
Track: 1/11 
Genre:World 
Date: 1999 
Composer: Simon Emerson, James McNally, Iarla O Lionaird, Martin Russell & Sinead O'Connor/Sinéad O'Connor 
Disc: 1/1 
Time: 456 
Pos: 0 
Id: 53616 

Se Invio il comando MPD playlistid 49312 Ricevo questa risposta:

file: gavin/ATB/Future Memories/16 Missing 1.m4a 
Last-Modified: 2013-11-17T21:14:43Z 
Artist: ATB 
Album: Future Memories 
Title: Missing 
Track: 16/29 
Genre: Dance 
Date: 2009-05-01T07:00:00Z 
Composer: Tracey Thorn & Ben Watt 
Disc: 1/1 
AlbumArtist: ATB 
Time: 256 
Pos: 10 
Id: 49312 

Se invio il comando search file surfing ottengo questa risposta (diversi brani sono delimitati da una nuova file:):

file: doza/Air/06 Surfing On a Rocket.m4a 
Last-Modified: 2015-11-20T15:56:00Z 
Time: 223 
Artist: Air 
Album: Talkie Walkie 
Title: Surfing On a Rocket 
Track: 6/10 
Genre: Electronic 
Date: 2004-01-26T08:00:00Z 
Disc: 1/1 
AlbumArtist: Air 
file: gavin/Air/Surfing On a Rocket EP/06 Surfing on a rocket (remixed by Joakim).m4a 
Last-Modified: 2015-01-13T15:31:39Z 
Time: 393 
Artist: Air 
Album: Surfing On a Rocket EP 
Title: Surfing on a rocket (remixed by Joakim) 
Track: 6/7 
Genre: Dance 
Date: 2004-09-10T07:00:00Z 
Composer: Jean-Benoit Dunckel & Nicolas Godin 
Disc: 1/1 
AlbumArtist: Air 
file: gavin/The Beach Boys/Greatest Surfing Songs!/02 Little Deuce Coupe.mp3 
Last-Modified: 2009-09-10T04:32:49Z 
Time: 111 
Artist: The Beach Boys 
Title: Little Deuce Coupe 
Album: Greatest Surfing Songs! 
Track: 2 
Genre: Sunshine Pop 

E se io mando il comando MPD listplaylistinfo Thump, ottengo questa risposta:

file: gavin/Muse/The 2nd Law (Deluxe Version)/02 Madness.m4a 
Last-Modified: 2013-11-17T22:30:54Z 
Artist: Muse 
Album: The 2nd Law (Deluxe Version) 
Title: Madness 
Track: 2/13 
Genre: Alternative 
Date: 2012-10-01T07:00:00Z 
Disc: 1/1 
AlbumArtist: Muse 
Time: 280 
file: gavin/U2/The Best Of 1990-2000/15 Numb (New Mix).mp3 
Last-Modified: 2003-09-24T14:31:05Z 
Artist: U2 
Title: Numb (New Mix) 
Album: The Best Of 1990-2000 
Track: 15/16 
Date: 2002 
Genre: Rock 
Composer: U2 
Time: 264 
file: gavin/Massive Attack/Mezzanine/03 Teardrop.m4a 
Last-Modified: 2012-09-05T19:38:14Z 
Artist: Massive Attack 
Album: Mezzanine 
Title: Teardrop 
Track: 3/11 
Genre: Electronic 
Date: 1998-04-20T07:00:00Z 
Disc: 1/1 
AlbumArtist: Massive Attack 
Time: 331 
file: gavin/Massive Attack/Mezzanine/01 Angel.m4a 
Last-Modified: 2012-09-05T19:38:17Z 
Artist: Massive Attack 
Album: Mezzanine 
Title: Angel 
Track: 1/11 
Genre: Electronic 
Date: 1998-04-20T07:00:00Z 
Disc: 1/1 
AlbumArtist: Massive Attack 
Time: 380 
file: gavin/Eels/Shrek 2/07 I Need Some Sleep.mp3 
Last-Modified: 2005-01-14T21:24:25Z 
Artist: Eels 
Title: I Need Some Sleep 
Album: Shrek 2 
Track: 7/14 
Date: 2004 
Genre: Soundtrack 
Time: 147 

Io personalmente uso la libreria ruby-mpd per fornire una comoda interfaccia per comunicare con MPD, in un modo ricco e completo.

4
import audioscrobbler 
import mpd 
import random 
import time 


lastsong = {} 

def timer_control(): 
    get_similar() 
    time.sleep(10) 
    timer_control() 

def get_similar(): 
    audioscrobbler 
    client = mpd.MPDClient() 
    client.connect("localhost", 6600) 
    mpdstatus = client.status() 
    prevsonginfo = client.currentsong() 
    global lastsong 
    if mpdstatus['state'] == "stop": return 
    if prevsonginfo == lastsong: return 

    lastsong = prevsonginfo 
    similarartists = "" 
    song = prevsonginfo 
    #if not song: break #No song, do nothing 
    prevartist = song['artist'] 

    # Is the info already cached? 
    similar_cache = {} 
    if similar_cache.has_key(prevartist): 
     similarartists = similar_cache[prevartist] 
    else: 
     #Not cached so fetch from Audioscrobbler 
     try: 
      similarartists = [artist.name for artist in audioscrobbler.AudioScrobblerQuery(artist=prevartist).similar()] 
      # Cache search results and save some time next search 
      similar_cache[prevartist] = similarartists 
     except audioscrobbler.AudioScrobblerError: 
      similar_cache[prevartist] = None # Empty cache 
      return # Do nothing! 

    if not similarartists: return # Empty list 

    # Split list in half and sort upper half 
    # this means good matches will have priority 
    # but makes sure artist A does not always result in artist B 
    half_idx = len(similarartists)/2 
    upperhalf = similarartists[:half_idx] 
    lowerhalf = similarartists[half_idx:] 
    random.shuffle(upperhalf) 
    artistlist = upperhalf 
    artistlist.extend(lowerhalf) 
    # Try each artist in order 
    for artist in artistlist: 
     try: 
      print "Trying:",artist 
      songs = client.search("artist", artist) 
      if not songs: continue 
      selected_song = random.sample(songs, 1)[0] 
      client.add(selected_song['file']) 
      print "Added", selected_song['title'],"by",selected_song['artist'] 
      # Delete old song from playlist? 
      break 
     except mpd.MPDError, e: 
      print "MPDError", e.message 
      continue 
     except ValueError, e: 
      print "ValueError:",e.message 
      continue 


timer_control() 

seguire questo articolo per ulteriori informazioni https://bbs.archlinux.org/viewtopic.php?id=49765 http://manpages.ubuntu.com/manpages/intrepid/man1/mpc.1.html

Problemi correlati