Skip to content

Commit

Permalink
v0.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Jan 25, 2018
1 parent 357ef1b commit b54537e
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-video-url-parser",
"version": "0.2.5",
"version": "0.2.6",
"homepage": "https://github.com/Zod-/jsVideoUrlParser",
"main": "dist/jsVideoUrlParser.js",
"authors": [{
Expand Down
136 changes: 136 additions & 0 deletions dist/jsVideoUrlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,142 @@ YouTube.prototype.createLongImageUrl = function (vi, params) {

base.bind(new YouTube());

var combineParams$9 = util.combineParams;
var getTime$6 = util.getTime;

function SoundCloud() {
this.provider = 'soundcloud';
this.defaultFormat = 'long';
this.formats = {
long: this.createLongUrl,
embed: this.createEmbedUrl
};
this.mediaTypes = {
TRACK: 'track',
PLAYLIST: 'playlist',
APITRACK: 'apitrack',
APIPLAYLIST: 'apiplaylist'
};
}

SoundCloud.prototype.parseUrl = function (url, result) {
var match = url.match(/soundcloud\.com\/(?:([\w-]+)\/(sets\/)?)([\w-]+)/i);

if (!match) {
return result;
}

result.channel = match[1];

if (match[1] === 'playlists' || match[2]) {
//playlist
result.list = match[3];
} else {
//track
result.id = match[3];
}

return result;
};

SoundCloud.prototype.parseParameters = function (params) {
if (params.t) {
params.start = getTime$6(params.t);
delete params.t;
}

return params;
};

SoundCloud.prototype.parseMediaType = function (result) {
if (result.id) {
if (result.channel === 'tracks') {
delete result.channel;
delete result.params.url;
result.mediaType = this.mediaTypes.APITRACK;
} else {
result.mediaType = this.mediaTypes.TRACK;
}
}

if (result.list) {
if (result.channel === 'playlists') {
delete result.channel;
delete result.params.url;
result.mediaType = this.mediaTypes.APIPLAYLIST;
} else {
result.mediaType = this.mediaTypes.PLAYLIST;
}
}

return result;
};

SoundCloud.prototype.parse = function (url, params) {
var result = {};
result = this.parseUrl(url, result);
result.params = this.parseParameters(params);
result = this.parseMediaType(result);

if (!result.id && !result.list) {
return undefined;
}

return result;
};

SoundCloud.prototype.createLongUrl = function (vi, params) {
var url = '';
var startTime = params.start;
delete params.start;

if (vi.mediaType === this.mediaTypes.TRACK) {
url = 'https://soundcloud.com/' + vi.channel + '/' + vi.id;
}

if (vi.mediaType === this.mediaTypes.PLAYLIST) {
url = 'https://soundcloud.com/' + vi.channel + '/sets/' + vi.list;
}

if (vi.mediaType === this.mediaTypes.APITRACK) {
url = 'https://api.soundcloud.com/tracks/' + vi.id;
}

if (vi.mediaType === this.mediaTypes.APIPLAYLIST) {
url = 'https://api.soundcloud.com/playlists/' + vi.list;
}

url += combineParams$9({
params: params
});

if (startTime) {
url += '#t=' + startTime;
}

return url;
};

SoundCloud.prototype.createEmbedUrl = function (vi, params) {
var url = 'https://w.soundcloud.com/player/';
delete params.start;

if (vi.mediaType === this.mediaTypes.APITRACK) {
params.url = 'https%3A//api.soundcloud.com/tracks/' + vi.id;
}

if (vi.mediaType === this.mediaTypes.APIPLAYLIST) {
params.url = 'https%3A//api.soundcloud.com/playlists/' + vi.list;
}

url += combineParams$9({
params: params
});
return url;
};

base.bind(new SoundCloud());

var lib = base;

return lib;
Expand Down
2 changes: 1 addition & 1 deletion dist/jsVideoUrlParser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-video-url-parser",
"version": "0.2.5",
"version": "0.2.6",
"description": "A parser to extract provider, video id, starttime and others from YouTube, Vimeo, ... urls",
"main": "lib/index.js",
"repository": {
Expand Down

0 comments on commit b54537e

Please sign in to comment.