Permalink
Browse files

Enable incremental subscription checking and updating.

* New tracks are indicated as "unplayed" until played in the tracklist and sidebar.
* Refactored YQL XML->JSON URL construction to use variable substitution.
* Refactored source building, selecting and playing.
* No longer update the track's metadata based on the source, only the duration, and don't persist.
* Marked some candidates for View layer refactoring.
* Removed unimplemented public/private/sharing stubs from Playlist class.
* Moved Playdar response caches to PlaylistTrack from Track.
  • Loading branch information...
jwheare committed Dec 21, 2009
1 parent 2908e7d commit 9b8059bc572f54f66c5ecad1b2303f3df8d7aac3
View
@@ -170,6 +170,9 @@ ul.playlists li a.playlist {
text-decoration: none;
background: #e8f9bb;
}
+ul.playlists li.unplayed a.playlist {
+ background: #d2f380;
+}
ul.playlists li a.create {
background: #d2f380;
}
@@ -624,6 +627,9 @@ ul#lastfm_playlists img {
.trackList li.paused:hover {
background-color: #a8d840;
}
+.trackList li.unplayed {
+ background: #d2f380;
+}
.trackList li.error {
background: #FFAF59;
}
@@ -110,6 +110,7 @@ Playlist.prototype = {
var subscriptionElements = [];
var that = this;
var playlists = MODELS.Playlist.fetchAll(function callback (playlist) {
+ that.checkSubscription(playlist);
var element = playlist.element.get()[0];
if (playlist.isAlbum()) {
albumElements.push(element);
@@ -492,16 +493,26 @@ Playlist.prototype = {
}
}
if (added.length) {
- console.log(playlist.toString(), playlist.isIncrementalSubscription());
- UTIL.sortByMethod(added, 'get_position');
- $.each(added, function (i, playlist_track) {
- console.info(playlist_track.toString());
- });
+ // console.log(playlist.toString());
+ if (playlist.isIncrementalSubscription()) {
+ // Prepend the new tracks
+ UTIL.sortByMethod(added, 'get_position', true);
+ $.each(added, function (i, playlist_track) {
+ // console.info(playlist_track.toString());
+ playlist.add_track(playlist_track.track, {
+ unplayed: true
+ }, true);
+ });
+ playlist.save();
+ } else {
+ // TODO replace all tracks
+ }
+ // TODO message that shit
}
});
args.push(function exceptionHandler (exception) {
// show a warning icon and message?
- console.warn(exception);
+ // console.log(playlist.toString());
exception.diagnose();
});
IMPORTERS[sub.namespace][sub.method].apply(this, args);
View
@@ -1,8 +1,6 @@
IMPORTERS = {
YQL_URL: "http://query.yahooapis.com/v1/public/yql?callback=?",
- yqlSelectXML: function (url) {
- return 'select * from xml where url="' + url + '"';
- },
+ YQL_SELECT_XML: 'select * from xml where url=@url',
/**
* getJson(url, params, callback, exception[, exceptionHandler])
* - url (String): URL to a JSON document
@@ -56,7 +54,8 @@ IMPORTERS = {
**/
getJsonFomXml: function (url, callback, exception, exceptionHandler) {
IMPORTERS.getJson(IMPORTERS.YQL_URL, {
- q: IMPORTERS.yqlSelectXML(url),
+ url: url,
+ q: IMPORTERS.YQL_SELECT_XML,
format: 'json'
}, function (json, requestUrl, requestParams) {
if (!json.query || !json.query.results) {
@@ -71,13 +70,14 @@ IMPORTERS = {
delay: 200,
dataType: "jsonp",
extraParams: {
- q: function () {
+ url: function () {
var queryUrl = url;
if (params) {
queryUrl += '?' + Playdar.Util.toQueryString(params());
}
- return IMPORTERS.yqlSelectXML(queryUrl);
+ return queryUrl;
},
+ q: IMPORTERS.YQL_SELECT_XML,
format: 'json'
},
cacheLength: 1,
@@ -289,7 +289,6 @@ IMPORTERS = {
},
defaultExceptionHandler: function (exception) {
if (PLAYLICK.debug) {
- console.warn(exception);
exception.diagnose();
}
},
@@ -12,13 +12,17 @@ Exception.prototype = {
* Log diagnostics to the console
**/
diagnose: function () {
+ if (!PLAYLICK.debug) {
+ return false;
+ }
console.warn(this.toString());
- if (this.diagnostics) {
- if (typeof this.diagnostics == 'string') {
- console.log(this.diagnostics);
- } else {
- console.dir(this.diagnostics);
- }
+ if (!this.diagnostics) {
+ return;
+ }
+ if (typeof this.diagnostics == 'string') {
+ console.log(this.diagnostics);
+ } else {
+ console.dir(this.diagnostics);
}
}
};
View
@@ -61,62 +61,6 @@ var PLAYLICK = {
}
},
- /**
- * Playlist state
- **/
-
- selectSource: function (playlist_track, tbody) {
- // Check radio button
- var radio = tbody.find('input[name=choice]');
- radio.attr('checked', true);
- // Highlight result
- tbody.siblings().removeClass('choice');
- tbody.addClass('choice');
- // Update track with result data
- var result = tbody.data('result');
- PLAYLICK.update_track(playlist_track, result);
- if (!Playdar.player.is_now_playing()) {
- PLAYDAR.playTrack(playlist_track);
- }
- playlist_track.element.addClass('perfectMatch');
- },
- // Update a track's data and persist
- update_track: function (playlist_track, result, batch) {
- var track = playlist_track.track;
- // If the track name or artist changed, update it and persist
- if (!UTIL.compareString(track.name, result.track)
- || !UTIL.compareString(track.artist, result.artist)
- || !UTIL.compareString(track.album, result.album)) {
- track.name = result.track;
- track.artist = result.artist;
- track.album = result.album;
- // Persist
- if (batch) {
- PLAYLICK.batch_save = true;
- } else {
- playlist_track.playlist.save();
- }
- // Update DOM
- playlist_track.element.find('.fn')
- .text(UTIL.truncateString(track.name))
- .attr('title', track.name);
- playlist_track.element.find('.contributor')
- .text(UTIL.truncateString(track.artist))
- .attr('title', track.artist);
- }
- // If the duration changed, update it
- if (track.duration != result.duration) {
- playlist_track.set_track_duration(result.duration);
- playlist_track.element.find('.elapsed').text(track.get_duration_string());
- }
- // If the sid has changed, stop the stream if it's playing
- if (track.playdar_sid && track.playdar_sid != result.sid) {
- Playdar.player.stop_stream(track.playdar_sid);
- }
- track.playdar_sid = result.sid;
- track.video = result.video;
- },
-
/**
* Import
**/
View
@@ -26,7 +26,7 @@ CONTROLLERS.Playlist.trackListElem.click(function (e) {
var tbody = target.closest('tbody.result');
if (tbody.size()) {
track_item.removeClass('open');
- PLAYLICK.selectSource(playlist_track, tbody);
+ PLAYDAR.playSource(playlist_track, tbody);
}
// Remove track from playlist
@@ -47,11 +47,11 @@ CONTROLLERS.Playlist.trackListElem.click(function (e) {
e.preventDefault();
if (track_item.is('li.open')) {
track_item.removeClass('open');
- } else if (track_item.is('li.perfectMatch') && playlist_track.track.playdar_sid) {
+ } else if (track_item.is('li.perfectMatch')) {
PLAYDAR.playTrack(playlist_track);
} else if (track_item.is('li.match')) {
track_item.toggleClass('open');
- } else if (playlist_track.track.playdar_qid) {
+ } else if (playlist_track.playdar_qid) {
PLAYDAR.recheck_track(playlist_track);
} else {
PLAYDAR.resolve_track(playlist_track, true);
Oops, something went wrong.

0 comments on commit 9b8059b

Please sign in to comment.