{"action":"created","issue":{"url":"https://api.github.com/repos/pithos/pithos/issues/248","labels_url":"https://api.github.com/repos/pithos/pithos/issues/248/labels{/name}","comments_url":"https://api.github.com/repos/pithos/pithos/issues/248/comments","events_url":"https://api.github.com/repos/pithos/pithos/issues/248/events","html_url":"https://github.com/pithos/pithos/pull/248","id":113136161,"number":248,"title":"Create temporary local album arts files for MPRIS","user":{"login":"dbfin","id":3341119,"avatar_url":"https://avatars.githubusercontent.com/u/3341119?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfin","html_url":"https://github.com/dbfin","followers_url":"https://api.github.com/users/dbfin/followers","following_url":"https://api.github.com/users/dbfin/following{/other_user}","gists_url":"https://api.github.com/users/dbfin/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfin/subscriptions","organizations_url":"https://api.github.com/users/dbfin/orgs","repos_url":"https://api.github.com/users/dbfin/repos","events_url":"https://api.github.com/users/dbfin/events{/privacy}","received_events_url":"https://api.github.com/users/dbfin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-10-24T04:53:15Z","updated_at":"2015-10-24T23:33:43Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pithos/pithos/pulls/248","html_url":"https://github.com/pithos/pithos/pull/248","diff_url":"https://github.com/pithos/pithos/pull/248.diff","patch_url":"https://github.com/pithos/pithos/pull/248.patch"},"body":"Related to issue #245 \r\n\r\nThe commit consists of the following changes:\r\n\r\npithos.py\r\n\r\nNote, that chronologically the code works as ENTER > 1 > (5 > 2 > 4)* > 1 > EXIT\r\n\r\n1. Creating a temporary directory, lines 237-243, and removing it on exit, lines 1120-1125.\r\n\r\n2. get_album_art function, lines 92-114.\r\n\r\n    a. We accept an additional parameter tmpfile, which contains the file name and handle for the temporary file.\r\n    b. We try to right the original image (before resizing) to the file. At first, I thought we could have done this in art_callback, but there we would have only the image 96x96, not the original 500x500.\r\n    c. We return an additional parameter after pixbuf, which is the file name or None, depending on whether writing to the file was successful.\r\n\r\n3. A new signal \"song-art-changed\", line 133, is needed to let MPRIS know when the arts for the current song was downloaded if it started playing a song before that (for example, the first song).\r\n\r\n4. Function art_callback, lines 603-612. As was mentioned above, an additional parameter is now returned to the art_callback, so if it is not None, there is a file with the arts, and we reassign song.artFile and issue the signal, so MPRIS will know.\r\n\r\n5. Function callback, changed lines 622-629. This function is called when the playlist is created or updated. For each new song (variable i) we first set i.artFile=None and try to create a temporary file to store the image. If the file is created successfully, as was mentioned above, we pass it to get_album_art, and if it successfully writes the image to the file, it will return the file name to art_callback, which will update song.artFile and issue the signal. Before all this happens, i.artFile should be None, as there is no file yet, should MPRIS already start playing this song.\r\n\r\n_mpris.py\r\n\r\n1. Line 42, connect to the new signal to know when the album arts are downloaded.\r\n\r\n2. Line 53, use artFile instead of artUrl for the local image.\r\n\r\n3. Lines 57-65, update the album arts link, only if it was changed for the currently playing song.\r\n\r\nAdditional comments:\r\n\r\n- Without the new signal and signal handling, the album arts is not shown for the first song, and when one quickly switches from the 3rd song to the 5th, or from the 7th to the 9th etc. (when a new portion of the list is still being downloaded). And if we pass the name of the future file right away, it won't be updated in the sound menu even when the file is downloaded, so we need to pass None at first, and then update it using the signal.\r\n\r\n- At first, I thought to delete the temporary image files as soon as a song finishes, but it leads to unnecessary complications. Anyway, the files are small, so even if you listen to hundred songs, the arts won't take more than several megabytes. So, we can delete them all at once in the end."},"comment":{"url":"https://api.github.com/repos/pithos/pithos/issues/comments/150872119","html_url":"https://github.com/pithos/pithos/pull/248#issuecomment-150872119","issue_url":"https://api.github.com/repos/pithos/pithos/issues/248","id":150872119,"user":{"login":"dbfin","id":3341119,"avatar_url":"https://avatars.githubusercontent.com/u/3341119?v=3","gravatar_id":"","url":"https://api.github.com/users/dbfin","html_url":"https://github.com/dbfin","followers_url":"https://api.github.com/users/dbfin/followers","following_url":"https://api.github.com/users/dbfin/following{/other_user}","gists_url":"https://api.github.com/users/dbfin/gists{/gist_id}","starred_url":"https://api.github.com/users/dbfin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbfin/subscriptions","organizations_url":"https://api.github.com/users/dbfin/orgs","repos_url":"https://api.github.com/users/dbfin/repos","events_url":"https://api.github.com/users/dbfin/events{/privacy}","received_events_url":"https://api.github.com/users/dbfin/received_events","type":"User","site_admin":false},"created_at":"2015-10-24T23:33:43Z","updated_at":"2015-10-24T23:33:43Z","body":"@TingPing I have already removed Python 2.x support. What about the points 1 and 2 above. It is literally 4 additional lines of code, but makes it foolproof against many possible scenarios and future bugs."}}