Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[beets] Add ScriptCollection support #42

Merged
merged 1 commit into from about 1 year ago

3 participants

Uwe L. Korn Hugo Lindström Teo Mrnjavac
Uwe L. Korn
Collaborator

This depends on sampsyo/beets#240

Teo Mrnjavac

Minor nitpick: could you please prettify the url that ends up in the description? Something like https://github.com/tomahawk-player/tomahawk-resolvers/blob/master/subsonic/content/contents/code/subsonic.js#L412 would be great.

Collaborator

The host in Beets is just the DNS Name or IP where beet web is running, there is nothing to prettify like in Subsonic.

Hugo Lindström hugolm84 commented on the diff
beets/content/contents/code/beets-resolver.js
((7 lines not shown))
111 112
         this.host = userConfig.host || 'localhost';
112 113
         this.port = parseInt(userConfig.port, 10);
113 114
         if (isNaN(this.port) || !this.port) {
114 115
             this.port = 8337;
115 116
         }
  117
+        // Check if /artist/ is available and we can get enough information for ScriptCollection support
  118
+        xmlHttpRequest.open('GET', this.baseUrl() + '/artist/', true);
1
Hugo Lindström Collaborator
hugolm84 added a note

We should add a fail callback in Tomahawk.async for this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Hugo Lindström hugolm84 merged commit 5a32e7c into from
Hugo Lindström hugolm84 closed this
Uwe L. Korn xhochy deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 01, 2013
Uwe L. Korn [beets] Add ScriptCollection support 00cb29d
This page is out of date. Refresh to see the latest.
93  beets/content/contents/code/beets-resolver.js
@@ -107,13 +107,104 @@ var BeetsResolver = Tomahawk.extend(TomahawkResolver, {
107 107
         this.init();
108 108
     },
109 109
     init: function () {
110  
-        var userConfig = this.getUserConfig();
  110
+        var userConfig = this.getUserConfig(),
  111
+            xmlHttpRequest = new XMLHttpRequest();
111 112
         this.host = userConfig.host || 'localhost';
112 113
         this.port = parseInt(userConfig.port, 10);
113 114
         if (isNaN(this.port) || !this.port) {
114 115
             this.port = 8337;
115 116
         }
  117
+        // Check if /artist/ is available and we can get enough information for ScriptCollection support
  118
+        xmlHttpRequest.open('GET', this.baseUrl() + '/artist/', true);
  119
+        xmlHttpRequest.onreadystatechange = function() {
  120
+            if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
  121
+                Tomahawk.reportCapabilities(TomahawkResolverCapability.Browsable);
  122
+            } else if (xmlHttpRequest.readyState === 4) {
  123
+                Tomahawk.reportCapabilities();
  124
+            }
  125
+        }
  126
+        xmlHttpRequest.send(null);
  127
+    },
  128
+
  129
+    // Script Collection Support
  130
+
  131
+    artists: function (qid) {
  132
+        var url = this.baseUrl() + '/artist/';
  133
+        Tomahawk.asyncRequest(url, function (xhr) {
  134
+            var response = JSON.parse(xhr.responseText);
  135
+            Tomahawk.addArtistResults({
  136
+                qid: qid,
  137
+                artists: response.artist_names
  138
+            });
  139
+        });
  140
+    },
  141
+
  142
+    albums: function (qid, artist) {
  143
+        var url = this.baseUrl() + '/album/artist/' + encodeURIComponent(artist);
  144
+        Tomahawk.asyncRequest(url, function (xhr) {
  145
+            var response = JSON.parse(xhr.responseText),
  146
+                results = [];
  147
+            response.results.forEach(function (item) {
  148
+                results.push(item.album);
  149
+            });
  150
+            Tomahawk.addAlbumResults({
  151
+                qid: qid,
  152
+                artist: artist,
  153
+                albums: results
  154
+            });
  155
+        });
  156
+    },
  157
+
  158
+    tracks: function (qid, artist, album) {
  159
+        var url = this.baseUrl() + '/item/query/' + encodeURIComponent('artist:' + artist) + '/' + encodeURIComponent('album:' + album),
  160
+            baseUrl = this.baseUrl();
  161
+        Tomahawk.asyncRequest(url, function (xhr) {
  162
+            var response = JSON.parse(xhr.responseText),
  163
+                searchResults = [];
  164
+            response.results.forEach(function (item) {
  165
+                var type_info = AUDIO_TYPES[item.format];
  166
+                searchResults.push({
  167
+                    artist: item.artist,
  168
+                    album: item.album,
  169
+                    track: item.title,
  170
+                    albumpos: item.track,
  171
+                    source: "beets",
  172
+                    url: baseUrl + '/item/' + item.id + '/file',
  173
+                    bitrate: Math.floor(item.bitrate / 1024),
  174
+                    duration: Math.floor(item.length),
  175
+                    size: (item.size || 0),
  176
+                    score: 1.0,
  177
+                    extension: type_info[0],
  178
+                    mimetype: type_info[1],
  179
+                    year: item.year
  180
+                });
  181
+            });
  182
+            searchResults.sort(function (a, b) {
  183
+                if (a.albumpos < b.albumpos) {
  184
+                    return -1;
  185
+                } else if (a.albumpos > b.albumpos) {
  186
+                    return 1;
  187
+                } else {
  188
+                    return 0;
  189
+                }
  190
+            });
  191
+            Tomahawk.addAlbumTrackResults({
  192
+                qid: qid,
  193
+                artist: artist,
  194
+                album: album,
  195
+                results: searchResults
  196
+            });
  197
+        });
116 198
     },
  199
+
  200
+    collection: function () {
  201
+        // TODO: trackcount
  202
+        return {
  203
+            prettyname: "Beets",
  204
+            description: this.host,
  205
+            iconfile: 'beets-icon.png'
  206
+        };
  207
+    }
117 208
 });
118 209
 
119 210
 Tomahawk.resolver.instance = BeetsResolver;
4  beets/content/metadata.json
@@ -3,7 +3,7 @@
3 3
     "pluginName": "beets",
4 4
     "author": "Adrian and Uwe",
5 5
     "email": "uwelk@xhochy.com",
6  
-    "version": "0.3",
  6
+    "version": "0.4",
7 7
     "website": "http://gettomahawk.com",
8 8
     "description": "Connects to a beets server and resolves tracks",
9 9
     "type": "resolver/javascript",
@@ -12,7 +12,7 @@
12 12
         "scripts": [],
13 13
         "icon": "contents/images/icon.png",
14 14
         "resources": [
15  
-            "contents/code/config.ui"
  15
+            "contents/code/config.ui",
16 16
             "contents/code/beets-icon.png"
17 17
         ]
18 18
     }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.