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 lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './provider/allocine';
export * from './provider/canalplus';
export * from './provider/coub';
export * from './provider/dailymotion';
export * from './provider/googledrive';
export * from './provider/loom';
export * from './provider/soundcloud';
export * from './provider/teachertube';
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require('./provider/vimeo');
require('./provider/wistia');
require('./provider/youku');
require('./provider/youtube');
require('./provider/googledrive');
require('./provider/soundcloud');
require('./provider/teachertube');
require('./provider/tiktok');
Expand Down
14 changes: 14 additions & 0 deletions lib/provider/googledrive.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { VideoInfo } from '../urlParser';

export interface GoogledriveUrlParameters {
start?: number;
[key: string]: any;
}

export type GoogledriveMediaTypes = 'video';

export interface GoogledriveVideoInfo extends VideoInfo<GoogledriveUrlParameters, GoogledriveMediaTypes> {
provider: 'googledrive';
}

export type GoogledriveParseResult = GoogledriveVideoInfo | undefined;
72 changes: 72 additions & 0 deletions lib/provider/googledrive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {
combineParams,
getTime,
} = require('../util');

function Googledrive() {
this.provider = 'googledrive';
this.defaultFormat = 'long';
this.formats = {
long: this.createLongUrl,
};
this.mediaTypes = {
VIDEO: 'video',
};
}

module.exports = Googledrive;


Googledrive.prototype.parseUrl = function(url) {
var match = url.match(/(?:\/file\/d\/)([A-Za-z0-9]+)(?:\/view)/i);
// https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view
return match ? match[1] : undefined;
};

Googledrive.prototype.parseParameters = function(params, result) {
if (params.start || params.t) {
params.start = getTime(params.start || params.t);
delete params.t;
}
// if (params.v === result.id) {
// delete params.v;
// }
// if (params.list === result.id) {
// delete params.list;
// }

return params;
};

Googledrive.prototype.parse = function(url, params) {
var result = {
mediaType: this.mediaTypes.VIDEO,
id: this.parseUrl(url),
};
result.params = this.parseParameters(params, result);
return result.id ? result : undefined;
};

Googledrive.prototype.createLongUrl = function(vi, params) {
// Googledrive.prototype.createLongUrl = function(vi) {

//Create the url depending on the media type
if (vi.mediaType !== this.mediaTypes.VIDEO || !vi.id) {
// return 'https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view';
return undefined;
}

var url = 'https://drive.google.com/file/d/' + vi.id + '/view';
// Add query parameters back e.g.
// https://template.com/example/id/abcde?foo=bar&baz=qux

if (params.start) {
params.t = params.start;
delete (params.start);
}
url += combineParams(params);

return url;

};
require('../base').bind(new Googledrive());
51 changes: 51 additions & 0 deletions lib/provider/googledrive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const Googledrive = require('./googledrive');
const UrlParser = require('../urlParser');
const {
testUrls,
} = require('../testUrls');

function newParser() {
const parser = new UrlParser();
parser.bind(new Googledrive());
return parser;
}

test('Googledrive: undefined', () => {
expect(newParser().parse('https://drive.google.com')).toBe(undefined);
expect(newParser().create({ videoInfo: { provider: 'googledrive' } })).toBe(undefined);
expect(newParser().create({ videoInfo: { provider: 'googledrive', mediaType: 'video' } })).toBe(undefined);
});

test('Googledrive: urls', () => {
testUrls(newParser(), {
videoInfo: {
provider: 'googledrive',
id: '9OPhkjOO8I140ABwWtyY0cG0riyVB89B',
mediaType: 'video',
},
formats: {
long: 'https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view',
},
urls: [
'https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view',
],
});
});
test('Googledrive: timed url', () => {
testUrls(newParser(), {
videoInfo: {
provider: 'googledrive',
id: '9OPhkjOO8I140ABwWtyY0cG0riyVB89B',
mediaType: 'video',
params: {
start: 100,
},
},
formats: {
long: 'https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view?t=100',
},
urls: [
'https://drive.google.com/file/d/9OPhkjOO8I140ABwWtyY0cG0riyVB89B/view?t=100',
],
});
});
6 changes: 6 additions & 0 deletions lib/urlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function UrlParser() {
module.exports = UrlParser;

UrlParser.prototype.parseProvider = function(url) {
var googleDriveMatch = url.match(
/(?:(?:https?:)?\/\/)?(drive\.google)\./i
);
if (googleDriveMatch) {
return 'googledrive';
}
var match = url.match(
/(?:(?:https?:)?\/\/)?(?:[^.]+\.)?(\w+)\./i
);
Expand Down