crustymonkey / py-sonic

A python library to wrap the Subsonic REST API
http://stuffivelearned.org/doku.php?id=programming:python:py-sonic
GNU General Public License v3.0
56 stars 26 forks source link

Search artists and albums returns IDs that cannot be used for getArtist(), and getAlbum(). #2

Closed n1ck3 closed 11 years ago

n1ck3 commented 11 years ago

Using:

The album IDs obtained from earching for albums and the looking at the albums in the results of getArtist() seem to correspond with the ones in the Subsonic web interface. However, they cannot be used for getAlbum().

When I do a getSong(), the artist and album IDs returned are different and the ones that can be used with getArtist() and getAlbum().

This small python script demonstrates the issue:

#!/usr/bin/env python2

import libsonic
import json

conn = libsonic.Connection('http://example.com' , 'username' , 'password', port=8080)

print "IS THE ARTIST ERIC CLAPTON"
print 50*"#"
print json.dumps(conn.getArtist(114), sort_keys=True, indent=2)

print "\n\n"

print "SOULD BE THE ARTIST ERIC CLAPTON ACCORDING TO SUBSONIC WEB INTERFACE"
print 50*"#"
print json.dumps(conn.getArtist(72), sort_keys=True, indent=2)

print "\n\n"

print "IS THE ALBUM UNPLUGGED"
print 50*"#"
print json.dumps(conn.getAlbum(1000), sort_keys=True, indent=2)

print "\n\n"

print "SHOULD BE THE ALBUM UNPLUGGED ACCORDING TO SUBSONIC WEB INTERFACE"
print 50*"#"
print json.dumps(conn.getAlbum(16012), sort_keys=True, indent=2)

$ ./test.py

IS THE ARTIST ERIC CLAPTON
##################################################
{
  "artist": {
    "album": {
      "artist": "Eric Clapton",
      "artistId": 114,
      "coverArt": "al-1000",
      "created": "2013-02-24T20:38:08",
      "duration": 3698,
      "id": 1000,
      "name": "Unplugged",
      "songCount": 14
    },
    "albumCount": 1,
    "coverArt": "ar-114",
    "id": 114,
    "name": "Eric Clapton"
  },
  "status": "ok",
  "version": "1.8.0",
  "xmlns": "http://subsonic.org/restapi"
}

SOULD BE THE ARTIST ERIC CLAPTON ACCORDING TO SUBSONIC WEB INTERFACE
##################################################
{
  "artist": {
    "albumCount": 1,
    "coverArt": "ar-72",
    "id": 72,
    "name": "DutchReleaseTeam"
  },
  "status": "ok",
  "version": "1.8.0",
  "xmlns": "http://subsonic.org/restapi"
}

IS THE ALBUM UNPLUGGED
##################################################
{
  "album": {
    "artist": "Eric Clapton",
    "artistId": 114,
    "coverArt": "al-1000",
    "created": "2013-02-24T20:38:08",
    "duration": 3698,
    "id": 1000,
    "name": "Unplugged",
    "song": [
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 192,
        "id": 16013,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/01 Signe.mp3",
        "size": 3113301,
        "suffix": "mp3",
        "title": "Signe",
        "track": 1,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 224,
        "id": 16014,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/02 Before You Accuse Me.mp3",
        "size": 3623226,
        "suffix": "mp3",
        "title": "Before You Accuse Me",
        "track": 2,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:07",
        "discNumber": 1,
        "duration": 196,
        "id": 16015,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/03 Hey Hey.mp3",
        "size": 3177669,
        "suffix": "mp3",
        "title": "Hey Hey",
        "track": 3,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:07",
        "discNumber": 1,
        "duration": 276,
        "id": 16016,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/04 Tears in Heaven.mp3",
        "size": 4453706,
        "suffix": "mp3",
        "title": "Tears in Heaven",
        "track": 4,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 328,
        "id": 16017,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/05 Lonely Stranger.mp3",
        "size": 5272070,
        "suffix": "mp3",
        "title": "Lonely Stranger",
        "track": 5,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 229,
        "id": 16018,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/06 Nobody Knows You When You're Down & Out.mp3",
        "size": 3702230,
        "suffix": "mp3",
        "title": "Nobody Knows You When You're Down & Out",
        "track": 6,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 286,
        "id": 16019,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/07 Layla.mp3",
        "size": 4614192,
        "suffix": "mp3",
        "title": "Layla",
        "track": 7,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 390,
        "id": 16020,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/08 Running on Faith.mp3",
        "size": 6270158,
        "suffix": "mp3",
        "title": "Running on Faith",
        "track": 8,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 217,
        "id": 16021,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/09 Walkin' Blues.mp3",
        "size": 3513714,
        "suffix": "mp3",
        "title": "Walkin' Blues",
        "track": 9,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 222,
        "id": 16022,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/10 Alberta.mp3",
        "size": 3593120,
        "suffix": "mp3",
        "title": "Alberta",
        "track": 10,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:07",
        "discNumber": 1,
        "duration": 203,
        "id": 16023,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/11 San Francisco Bay Blues.mp3",
        "size": 3289280,
        "suffix": "mp3",
        "title": "San Francisco Bay Blues",
        "track": 11,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 217,
        "id": 16024,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/12 Malted Milk.mp3",
        "size": 3499501,
        "suffix": "mp3",
        "title": "Malted Milk",
        "track": 12,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 471,
        "id": 16025,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/13 Old Love.mp3",
        "size": 7564569,
        "suffix": "mp3",
        "title": "Old Love",
        "track": 13,
        "type": "music",
        "year": 1992
      },
      {
        "album": "Unplugged",
        "albumId": 1000,
        "artist": "Eric Clapton",
        "artistId": 114,
        "bitRate": 128,
        "contentType": "audio/mpeg",
        "coverArt": 16012,
        "created": "2013-02-24T20:38:08",
        "discNumber": 1,
        "duration": 247,
        "id": 16026,
        "isDir": false,
        "isVideo": false,
        "parent": 16012,
        "path": "Eric Clapton/Unplugged/14 Rollin' & Tumblin'.mp3",
        "size": 3984343,
        "suffix": "mp3",
        "title": "Rollin' & Tumblin'",
        "track": 14,
        "type": "music",
        "year": 1992
      }
    ],
    "songCount": 14
  },
  "status": "ok",
  "version": "1.8.0",
  "xmlns": "http://subsonic.org/restapi"
}

SHOULD BE THE ALBUM UNPLUGGED ACCORDING TO SUBSONIC WEB INTERFACE
##################################################
Traceback (most recent call last):
  File "./test.py", line 28, in <module>
    print json.dumps(conn.getAlbum(16012), sort_keys=True, indent=2)
  File "/home/nicke/src/crusty/libsonic/connection.py", line 1500, in getAlbum
    self._checkStatus(res)
  File "/home/nicke/src/crusty/libsonic/connection.py", line 1888, in _checkStatus
    raise exc(result['error']['message'])
libsonic.errors.DataNotFoundError: Album not found.
crustymonkey commented 11 years ago

After taking a look at this again, I remember what the issue is here. The subsonic API version 1.8.0 introduced a number of new methods that operate on the ID3 tags vs. the old way of a simple directory structure. If you used the id number with the getMusicDirectory() method, you should end up getting the results you want. So, this would work:

c = Connection('https://music.example.com' , 'user' , 'password')
s = c.search2('tribe called quest' , 1 , 0 , 0 , 0 , 0)
json.dumps(c.getMusicDirectory(ret['searchResult2']['artist']['id']) , 
    sort_keys=True , indent=2)

I'm currently updating the documentation at https://stuffivelearned.org/doku.php?id=programming:python:py-sonic with all the 1.8.0 API version items, but until I'm done a pydoc libsonic.connection will show you basically the same thing. Anything that has a reference to "using ID3 tags" will not be compatible with the older methods of using the simple directory structure. I'm going to make a note of that on the aforementioned documentation page as well as even I had completely forgotten about that.

To use the getArtist(), getAlbum(), etc. You would probably want to start with a getArtists() call and manually search for what you want to display.

crustymonkey commented 11 years ago

Oh, I should have also mentioned that search3() will return results by ID3 tag.

crustymonkey commented 11 years ago

I've update the documentation at https://stuffivelearned.org/doku.php?id=programming:python:py-sonic with the API 1.8.0 docs as well as a specific warning about mixing methods: https://stuffivelearned.org/doku.php?id=programming:python:py-sonic