-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathsong.js
More file actions
95 lines (77 loc) · 3.13 KB
/
song.js
File metadata and controls
95 lines (77 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
define(function (require) {
'use strict';
var SongType = require('background/enum/songType');
var Utility = require('common/utility');
var Song = Backbone.Model.extend({
defaults: {
// ID is a YouTube Video ID.
id: '',
// Title is immutable. PlaylistItem might support editing the title, but applied to the PlaylistItem and not to Song.
title: '',
author: '',
// Duration in seconds for the length of the given song.
duration: -1,
type: SongType.None,
// These are calculated:
prettyDuration: '',
url: '',
cleanTitle: ''
},
// Song is never saved to the server -- it gets flattened into a PlaylistItem
sync: function() {
return false;
},
initialize: function () {
this._setPrettyDuration(this.get('duration'));
this._setCleanTitle(this.get('title'));
this._setUrl(this.get('id'));
this.on('change:duration', this._onChangeDuration);
this.on('change:title', this._onChangeTitle);
this.on('change:id', this._onChangeId);
},
getSyncAttributes: function () {
return {
id: this.get('id'),
title: this.get('title'),
author: this.get('author'),
duration: this.get('duration'),
type: this.get('type')
};
},
copyUrl: function () {
var url = this.get('url');
Streamus.channels.clipboard.commands.trigger('copy:text', url);
Streamus.channels.notification.commands.trigger('show:notification', {
message: chrome.i18n.getMessage('urlCopied')
});
},
copyTitleAndUrl: function () {
var titleAndUrl = this.get('title') + ' - ' + this.get('url');
Streamus.channels.clipboard.commands.trigger('copy:text', titleAndUrl);
Streamus.channels.notification.commands.trigger('show:notification', {
message: chrome.i18n.getMessage('urlCopied')
});
},
_onChangeId: function (model, id) {
this._setUrl(id);
},
_onChangeTitle: function(model, title) {
this._setCleanTitle(title);
},
_onChangeDuration: function(model, duration) {
this._setPrettyDuration(duration);
},
// Calculate this value pre-emptively because when rendering I don't want to incur inefficiency
_setPrettyDuration: function (duration) {
this.set('prettyDuration', Utility.prettyPrintTime(duration));
},
// Useful for comparisons and other searching.
_setCleanTitle: function (title) {
this.set('cleanTitle', Utility.cleanTitle(title));
},
_setUrl: function (id) {
this.set('url', 'https://youtu.be/' + id);
}
});
return Song;
});