Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/gallium
4 changes: 2 additions & 2 deletions lib/provider/soundcloud.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('SoundCloud: api track urls', () => {
},
formats: {
long: 'https://api.soundcloud.com/tracks/388050272',
embed: 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/388050272',
embed: 'https://w.soundcloud.com/player/?url=https%253A%2F%2Fapi.soundcloud.com%2Ftracks%2F388050272',
},
urls: [
'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/388050272',
Expand All @@ -107,7 +107,7 @@ test('SoundCloud: api playlist urls', () => {
},
formats: {
long: 'https://api.soundcloud.com/playlists/430366544',
embed: 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/430366544',
embed: 'https://w.soundcloud.com/player/?url=https%253A%2F%2Fapi.soundcloud.com%2Fplaylists%2F430366544',
},
urls: [
'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/430366544',
Expand Down
9 changes: 5 additions & 4 deletions lib/provider/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ YouTube.prototype.createShortUrl = function(vi, params) {

var url = 'https://youtu.be/' + vi.id;
if (params.start) {
url += '#t=' + params.start;
url += '?t=' + params.start;
}
return url;
};
Expand Down Expand Up @@ -152,11 +152,12 @@ YouTube.prototype.createLongUrl = function(vi, params) {
params.list = vi.list;
}

url += combineParams(params);

if (vi.mediaType !== this.mediaTypes.PLAYLIST && startTime) {
url += '#t=' + startTime;
params.t = startTime;
}

url += combineParams(params);

return url;
};

Expand Down
8 changes: 4 additions & 4 deletions lib/provider/youtube.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ test('YouTube: regular urls', () => {
},
},
formats: {
long: 'https://www.youtube.com/watch?v=HRb7B9fPhfA#t=30',
long: 'https://www.youtube.com/watch?t=30&v=HRb7B9fPhfA',
embed: 'https://www.youtube.com/embed/HRb7B9fPhfA?start=30',
short: 'https://youtu.be/HRb7B9fPhfA#t=30',
short: 'https://youtu.be/HRb7B9fPhfA?t=30',
},
urls: [
'http://www.youtube.com/watch?v=HRb7B9fPhfA#t=30s',
Expand Down Expand Up @@ -100,7 +100,7 @@ test('YouTube: playlist urls', () => {
},
},
formats: {
long: 'https://www.youtube.com/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100',
long: 'https://www.youtube.com/watch?list=PL46F0A159EC02DF82&t=100&v=yQaAGmHNn9s',
embed: 'https://www.youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100',
},
urls: [
Expand Down Expand Up @@ -157,7 +157,7 @@ test('YouTube: playlist urls', () => {
},
},
formats: {
long: 'https://www.youtube.com/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A#t=100',
long: 'https://www.youtube.com/watch?index=25&list=PL46F0A159EC02DF82&t=100&v=6xLcSTDeB7A',
embed: 'https://www.youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100',
},
urls: [
Expand Down
26 changes: 6 additions & 20 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,15 @@ exports.getQueryParams = function getQueryParams(qs) {
};

exports.combineParams = function combineParams(params, hasParams) {
if (typeof params !== 'object') {
if (typeof params !== 'object' || Object.keys(params).length === 0) {
return '';
}
var combined = '';
var i = 0;
var keys = Object.keys(params);

if (keys.length === 0) {
return '';
}
const urlParams = new URLSearchParams(params);
urlParams.sort();
const combined = urlParams.toString();

//always have parameters in the same order
keys.sort();

if (!hasParams) {
combined += '?' + keys[0] + '=' + params[keys[0]];
i += 1;
}

for (; i < keys.length; i += 1) {
combined += '&' + keys[i] + '=' + params[keys[i]];
}
return combined;
return `${hasParams === true ? '&' : '?'}${combined}`;
};

//parses strings like 1h30m20s to seconds
Expand Down Expand Up @@ -101,4 +87,4 @@ exports.getTime = function getTime(timeString) {
return getColonTime(timeString);
}
return 0;
};
};
Loading