mirror of https://github.com/calzoneman/sync.git
For convenience, queue next bumps if the item is already on the playlist
This commit is contained in:
parent
c8ce8b530a
commit
eee17f9daa
27
playlist.js
27
playlist.js
|
@ -169,21 +169,36 @@ Playlist.prototype.makeItem = function(media) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Playlist.prototype.add = function(item, pos) {
|
Playlist.prototype.add = function(item, pos) {
|
||||||
if(this.items.length >= 4000)
|
var self = this;
|
||||||
|
if(this.items.length >= 4000) {
|
||||||
return "Playlist limit reached (4,000)";
|
return "Playlist limit reached (4,000)";
|
||||||
|
}
|
||||||
|
|
||||||
if(this.items.findVideoId(item.media.id))
|
var it = this.items.findVideoId(item.media.id);
|
||||||
return "This item is already on the playlist";
|
if(it) {
|
||||||
|
if(pos === "append" || it == this.current) {
|
||||||
|
return "This item is already on the playlist";
|
||||||
|
}
|
||||||
|
|
||||||
|
self.remove(it.uid, function () {
|
||||||
|
self.channel.sendAll("delete", {
|
||||||
|
uid: it.uid
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(pos == "append") {
|
if(pos == "append") {
|
||||||
if(!this.items.append(item))
|
if(!this.items.append(item)) {
|
||||||
return "Playlist failure";
|
return "Playlist failure";
|
||||||
|
}
|
||||||
} else if(pos == "prepend") {
|
} else if(pos == "prepend") {
|
||||||
if(!this.items.prepend(item))
|
if(!this.items.prepend(item)) {
|
||||||
return "Playlist failure";
|
return "Playlist failure";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!this.items.insertAfter(item, pos))
|
if(!this.items.insertAfter(item, pos)) {
|
||||||
return "Playlist failure";
|
return "Playlist failure";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.items.length == 1) {
|
if(this.items.length == 1) {
|
||||||
|
|
|
@ -175,7 +175,7 @@ ULList.prototype.findVideoId = function (id) {
|
||||||
var item = this.first;
|
var item = this.first;
|
||||||
while(item !== null) {
|
while(item !== null) {
|
||||||
if(item.media && item.media.id === id)
|
if(item.media && item.media.id === id)
|
||||||
return true;
|
return item;
|
||||||
item = item.next;
|
item = item.next;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue