Permalink
Browse files

Add provider 'asciinema'

  • Loading branch information...
marcomontalbano committed Dec 14, 2018
1 parent 89508fd commit b8962cdef83cee09d3abac8b590c8fd8c83ee28b
@@ -34,8 +34,10 @@ You just need to paste the video url in the field above and you will get the mar
List of supported video providers:

- Youtube
- Facebook (low-quality)
- Dailymotion
- Vimeo
- Asciinema


## Hosting
Binary file not shown.
@@ -92,6 +92,7 @@ <h2>Features</h2>
<div class="provider"><i class="fas fa-check"></i><span>Facebook (low-quality)</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Dailymotion</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Vimeo</span></div>
<div class="provider"><i class="fas fa-check"></i><span>Asciinema</span></div>
</div>
</section>

@@ -13,6 +13,7 @@ const videoIcons = {
facebook: require('./images/providers/facebook.png'),
vimeo: require('./images/providers/vimeo.png'),
youtube: require('./images/providers/youtube.png'),
asciinema: require('./images/providers/asciinema.png'),
};

NProgress.configure({
@@ -0,0 +1,20 @@
import VideoProvider from '../VideoProvider';

// https://asciinema.org/

export default class Asciinema extends VideoProvider {
static get regex() {
return [
// - //asciinema.org/a/113463
/https?\:\/\/asciinema\.org\/a\/([0-9]+)/
];
}

static get useCloudinary() {
return false
}

getThumbnail_asUrl() {
return new Promise(resolve => resolve(`${this.url}.png`));
}
}
@@ -0,0 +1,20 @@
import Asciinema from './Asciinema';

describe('Asciinema', () => {
it('"regex" must be correct.', () => {
expect(Asciinema.getVideoId('https://asciinema.org/a/113463')).toBe('113463');
});

it('all methods must work.', () => {
const url = 'https://asciinema.org/a/113463';
const video = new Asciinema(url);

// static methods
expect(Asciinema.check(url)).toBe(true);

// instance methods
expect(video.getId()).toBe('113463');
expect(video.providerName).toBe('asciinema');
expect(video.url).toBe(url);
});
})
@@ -5,6 +5,8 @@ const { CLOUDINARY_CLOUD_NAME } = process.env;
export default class VideoProvider {
static get regex() {}

static get useCloudinary() { return true }

static check(url) {
return this.getVideoId(url) ? true : false;
}
@@ -37,19 +39,19 @@ export default class VideoProvider {
getThumbnail_asBuffer() {
return this.getThumbnail_asUrl()
.then(url => {
this.log('getThumbnail_asUrl', url);
return this.fetchCloudinary(url)
this.log('getThumbnail', this.getThumbnail_validateUrl(url));

return fetch(this.getThumbnail_validateUrl(url))
.then(response => response.buffer());
})
}

fetchCloudinary(url) {
let fetchUrl = url;
if (CLOUDINARY_CLOUD_NAME) {
fetchUrl = `http://res.cloudinary.com/${CLOUDINARY_CLOUD_NAME}/image/fetch/h_720/l_video_to_markdown:${this.providerName}_play,g_center/${encodeURIComponent(url)}`;
getThumbnail_validateUrl(url) {
if (this.constructor.useCloudinary && CLOUDINARY_CLOUD_NAME) {
return `http://res.cloudinary.com/${CLOUDINARY_CLOUD_NAME}/image/fetch/h_720/l_video_to_markdown:${this.providerName}_play,g_center/${encodeURIComponent(url)}`;
}
this.log('fetchCloudinary', fetchUrl);
return fetch(fetchUrl)
.then(response => response.buffer())

return url;
}

constructor(url) {
@@ -5,6 +5,7 @@ export default class VideoWrapper {
require('./Providers/Facebook'),
require('./Providers/Youtube'),
require('./Providers/Vimeo'),
require('./Providers/Asciinema'),
];
}

0 comments on commit b8962cd

Please sign in to comment.