New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probem returning tracks to mopidy through JSON-RPC interface #501

Closed
fatg3erman opened this Issue Aug 25, 2013 · 5 comments

Comments

2 participants
@fatg3erman
Contributor

fatg3erman commented Aug 25, 2013

For a lot of tracks in my library, I can't get them to play if I use the following Javascript code (using the mopidy.js library)

        mopidy.tracklist.getTlTracks().then( function (tracklist) {
                mopidy.playback.play(tracklist[1],1).then( function() {}, consoleError);
        });

(Assuming in this example that 1 is a valid index.)

The issue seems to be that these tracks have no 'Date' ID3 tag. When I run this code I get an assertion from mopidy on line 384 of playback.py

Sent WebSocket message to 127.0.0.1:1111: '{"jsonrpc": "2.0", "id": 72, "error": {"message": "Application error", "code": 0, "data":
{"message": "", "traceback":
"Traceback (most recent call last):
  File \\"/Library/Python/2.7/site-packages/mopidy/utils/jsonrpc.py\\", line 130, in _handle_single_request
    result = self._unwrap_result(result)
  File \\"/Library/Python/2.7/site-packages/mopidy/utils/jsonrpc.py\\", line 219, in _unwrap_result
    result = result.get()
  File \\"/Library/Python/2.7/site-packages/pykka/future.py\\", line 299, in get
    exec(\'raise exc_info[0], exc_info[1], exc_info[2]\')
  File \\"/Library/Python/2.7/site-packages/pykka/actor.py\\", line 200, in _actor_loop
    response = self._handle_receive(message)
  File \\"/Library/Python/2.7/site-packages/pykka/actor.py\\", line 294, in _handle_receive
    return callee(*message[\'args\'], **message[\'kwargs\'])
  File \\"/Library/Python/2.7/site-packages/mopidy/core/playback.py\\", line 384, in play
    assert tl_track in self.core.tracklist.tl_tracks
  AssertionError\\n", "type": "AssertionError"}}}'

The code looks like

        if tl_track is not None:
            assert tl_track in self.core.tracklist.tl_tracks

So it looks like mopidy thinks the track I've returned to it isn't in its tracklist.

I'm guessing that, because the Date tags are missing, that the JSON data I'm sent has that field completely missing (it does), but the internal data held by mopidy has some kind of null value in that field and so the two objects don't match.

Simply adding a date tag to the offending files cures the problem, but obviously this isn't a solution, I reckon I've got a few thousand of them... :)

This is mopidy 0.14.2 installed from pip on Mac OS 10.7

@ghost ghost assigned jodal Sep 15, 2013

@jodal

This comment has been minimized.

Member

jodal commented Sep 15, 2013

Your theory sounds plausible, but the decoding from JSON without the date information to Python objects seems to produce objects that are equal to objects created directly in Python without a date field:

>>> import json
>>> from mopidy.models import Track, model_json_decoder
>>> orig_track = Track(name='foo')
>>> json_track = json.loads(
...     '{"__model__": "Track", "name": "foo"}',
...     object_hook=model_json_decoder)
>>> orig_track == json_track
True

If you can provide the following, I should be able to figure this out:

  • An example of a dateless track from your tag_cache file (or your entire tag_cache file), and
  • The JSON representation of a dateless track. For example, run mopidy -v and provide the incoming message from the HTTP client that tries to play a dateless track. In other words, the JSON-RPC message before the exception response to the HTTP client you've already included.

Thanks!

@fatg3erman

This comment has been minimized.

Contributor

fatg3erman commented Sep 15, 2013

Thanks for looking into the problem. On further perusal, it looks like I wasn't completely accurate in my description.
To be more precise, the 'Date' tags in these files exist but the tag itself is empty - i.e. it has no value.
Here's an example from my tag cache:

info_begin
mpd_version: 0.17.0
fs_charset: UTF-8
info_end
directory: Baba
mtime: 1376868182
begin: Baba
directory: Baba/The Rap Canterbury Tales
mtime: 1377377433
begin: The Rap Canterbury Tales
songList begin
key: 01 - Genral Prologue.mp3
file: Baba/The%20Rap%20Canterbury%20Tales/01%20-%20Genral%20Prologue.mp3
Time: 247
Artist: Baba Brinkman
Title: Genral Prologue
Album: The Rap Canterbury Tales
Track: 1
Date: 
mtime: 1347834331

And here, pasted from the Javascript console of my browser, is the JSON data that I'm sending to mopidy: (reformatted by @jodal)

Object {track: Object, __model__: "TlTrack", tlid: 9}

__model__: "TlTrack"
tlid: 9
track: Object
__model__: "Track"
album: Object
  __model__: "Album"
  artists: Array[1]
    0: Object
      __model__: "Artist"
      name: "Baba Brinkman"
      __proto__: Object
    length: 1
    __proto__: Array[0]
  name: "The Rap Canterbury Tales"
__proto__: Object
artists: Array[1]
  0: Object
    __model__: "Artist"
    name: "Baba Brinkman"
    __proto__: Object
  length: 1
  __proto__: Array[0]
length: 247000
name: "Genral Prologue"
track_no: 1
uri: "file:///Users/bob/Untagged/Baba/The%20Rap%20Canterbury%20Tales/01%20-%20Genral%20Prologue.mp3"

And here's the data from mopidy -v (reformatted by @jodal)

Received WebSocket message from 127.0.0.1:1111:
'{
  "method":"core.playback.play",
  "params":[
    {
      "track":{
        "album":{"__model__":"Album","name":"The Rap Canterbury Tales","artists":[{"__model__":"Artist","name":"Baba Brinkman"}]},
        "__model__":"Track",
        "name":"Genral Prologue",
        "uri":"file:///Users/bob/Untagged/Baba/The%20Rap%20Canterbury%20Tales/01%20-%20Genral%20Prologue.mp3",
        "length":247000,
        "track_no":1,
        "artists":[{"__model__":"Artist","name":"Baba Brinkman"}]
      },
      "__model__":"TlTrack"
    },
   1
  ],
  "jsonrpc":"2.0","id":6
}'

DEBUG    2013-09-15 22:44:57,575 [1617:WebSocket client at 192.168.0.2:49357] mopidy.frontends.http
  Sent WebSocket message to 127.0.0.1:1111: '{"jsonrpc": "2.0", "id": 6, "error": {"message": "Application error", "code": 0, "data": {"message": "", "traceback": "Traceback (most recent call last):\\n  File \\"/Library/Python/2.7/site-packages/mopidy/utils/jsonrpc.py\\", line 130, in _handle_single_request\\n    result = self._unwrap_result(result)\\n  File \\"/Library/Python/2.7/site-packages/mopidy/utils/jsonrpc.py\\", line 219, in _unwrap_result\\n    result = result.get()\\n  File \\"/Library/Python/2.7/site-packages/pykka/future.py\\", line 299, in get\\n    exec(\'raise exc_info[0], exc_info[1], exc_info[2]\')\\n  File \\"/Library/Python/2.7/site-packages/pykka/actor.py\\", line 200, in _actor_loop\\n    response = self._handle_receive(message)\\n  File \\"/Library/Python/2.7/site-packages/pykka/actor.py\\", line 294, in _handle_receive\\n    return callee(*message[\'args\'], **message[\'kwargs\'])\\n  File \\"/Library/Python/2.7/site-packages/mopidy/core/playback.py\\", line 384, in play\\n    assert tl_track in self.core.tracklist.tl_tracks\\nAssertionError\\n", "type": "AssertionError"}}}'

@fatg3erman fatg3erman closed this Sep 15, 2013

@fatg3erman fatg3erman reopened this Sep 15, 2013

@jodal

This comment has been minimized.

Member

jodal commented Sep 15, 2013

After heavily reformatting the JSON data I noticed that the TlTrack you're sending from the browser to Mopidy doesn't have the required tlid field, but just a track field. How do you get hold of the tracklist you're getting the TlTrack object from?

@fatg3erman

This comment has been minimized.

Contributor

fatg3erman commented Sep 15, 2013

Well spotted :)
I'm getting the tracklist using mopidy.tracklist.getTlTracks(). What you've spotted looks like a separate bug - I've tried it on several playlists and it's always the same - the track with tlid 0 doesn't have the tlid field when I receive the tracklist data from mopidy.

Trying the same thing with another track in the playlist, also with an empty Date ID3 tag, here is the JSON data. The important thing here is that the tlid is set for this track, but the date field isn't, and I get the same assertion.

    Received WebSocket message from 127.0.0.1:1111: 
    '{"method":"core.playback.play", 
        "params":[
            {
                "track":{
                    "album":{"__model__":"Album", "name":"The Rap Canterbury Tales", "artists":[{"__model__":"Artist", "name":"Baba Brinkman"}]},
                    "__model__":"Track",
                    "name":"Rhyme Renaissance Prologue",
                    "uri":"file:///Users/bob/Untagged/Baba/The%20Rap%20Canterbury%20Tales/07%20-%20Rhyme%20Renaissance%20Prologue.mp3",
                    "length":180000,
                    "track_no":7,"
                    artists":[{"__model__":"Artist","name":"Baba Brinkman"}]
                },
                "__model__":"TlTrack",
                "tlid":6
            },
        1
        ],
        "jsonrpc":"2.0","id":39
    }'

Here is that track's entry in my tag cache

    key: 07 - Rhyme Renaissance Prologue.mp3
    file: Baba/The%20Rap%20Canterbury%20Tales/07%20-%20Rhyme%20Renaissance%20Prologue.mp3
    Time: 180
    Artist: Baba Brinkman
    Title: Rhyme Renaissance Prologue
    Album: The Rap Canterbury Tales
    Track: 7
    Date: 
    mtime: 1347834331

@jodal jodal closed this in e830f31 Sep 16, 2013

@jodal

This comment has been minimized.

Member

jodal commented Sep 16, 2013

@fatg3erman I believe the fix for the tlid field may resolve the date issue as well. Please reopen if it doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment