Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Mar 1, 2019
1 parent 8b2d0e9 commit bcfe736
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 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.8",
"version": "0.3.0",
"homepage": "https://github.com/Zod-/jsVideoUrlParser",
"main": "dist/jsVideoUrlParser.js",
"authors": [{
Expand Down
56 changes: 47 additions & 9 deletions dist/jsVideoUrlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,15 +799,39 @@ function YouTube() {
this.mediaTypes = {
VIDEO: 'video',
PLAYLIST: 'playlist',
SHARE: 'share'
SHARE: 'share',
CHANNEL: 'channel'
};
}

YouTube.prototype.parseUrl = function (url) {
YouTube.prototype.parseVideoUrl = function (url) {
var match = url.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i);
return match ? match[1] : undefined;
};

YouTube.prototype.parseChannelUrl = function (url) {
// Match an opaque channel ID
var match = url.match(/\/channel\/([\w-]+)/);

if (match) {
return {
id: match[1],
mediaType: this.mediaTypes.CHANNEL
};
} // Match a vanity channel name or a user name. User urls are deprecated and
// currently redirect to the channel of that same name.


match = url.match(/\/(?:c|user)\/([\w-]+)/);

if (match) {
return {
name: match[1],
mediaType: this.mediaTypes.CHANNEL
};
}
};

YouTube.prototype.parseParameters = function (params, result) {
if (params.start || params.t) {
params.start = getTime$5(params.start || params.t);
Expand Down Expand Up @@ -847,13 +871,19 @@ YouTube.prototype.parseMediaType = function (result) {
};

YouTube.prototype.parse = function (url, params) {
var result = {
params: params,
id: this.parseUrl(url)
};
result.params = this.parseParameters(params, result);
result = this.parseMediaType(result);
return result;
var channelResult = this.parseChannelUrl(url);

if (channelResult) {
return channelResult;
} else {
var result = {
params: params,
id: this.parseVideoUrl(url)
};
result.params = this.parseParameters(params, result);
result = this.parseMediaType(result);
return result;
}
};

YouTube.prototype.createShortUrl = function (vi, params) {
Expand All @@ -871,6 +901,14 @@ YouTube.prototype.createLongUrl = function (vi, params) {
var startTime = params.start;
delete params.start;

if (vi.mediaType === this.mediaTypes.CHANNEL) {
if (vi.id) {
url += 'https://www.youtube.com/channel/' + vi.id;
} else if (vi.name) {
url += 'https://www.youtube.com/c/' + vi.name;
}
}

if (vi.mediaType === this.mediaTypes.PLAYLIST) {
params.feature = 'share';
url += 'https://youtube.com/playlist';
Expand Down
Loading

0 comments on commit bcfe736

Please sign in to comment.