Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mimetypes #572

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,32 @@ export const VIDEO_SUFFIX_REMOVAL_PATTERN = RegExp(`\\.(${COMMON_VIDEO_EXTENSION
// eslint-disable-next-line no-control-regex
export const URL_PATTERN = RegExp('https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\+.~#?&/=]*)');


export const CONTAINER_MIME_TYPES = {
dash: ['application/dash+xml'],
hls: ['application/x-mpegURL'],
mpd: ['application/dash+xml'],
m3u8: ['application/x-mpegURL']
hls: 'application/x-mpegURL',
dash: 'application/dash+xml',

// See: https://docs.videojs.com/utils_mimetypes.js.html
opus: 'video/ogg',
ogv: 'video/ogg',
mp4: 'video/mp4',
mov: 'video/mp4',
m4v: 'video/mp4',
mkv: 'video/x-matroska',
m4a: 'audio/mp4',
mp3: 'audio/mpeg',
aac: 'audio/aac',
caf: 'audio/x-caf',
flac: 'audio/flac',
oga: 'audio/ogg',
wav: 'audio/wav',
m3u8: 'application/x-mpegURL',
mpd: 'application/dash+xml',
jpg: 'image/jpeg',
jpeg: 'image/jpeg',
gif: 'image/gif',
png: 'image/png',
svg: 'image/svg+xml',
webp: 'image/webp'
};

export const FORMAT_MAPPINGS = {
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/cloudinary/models/video-source/video-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ class VideoSource extends BaseSource {
}

generateRawSource(url, type) {
const t = type || url.split('.').pop();
const isAdaptive = !!CONTAINER_MIME_TYPES[t];
if (isAdaptive) {
type = CONTAINER_MIME_TYPES[t][0];
type = type || url.split('.').pop();

const isAdaptive = ['hls', 'dash', 'mpd', 'm3u8'].indexOf(type) !== -1;
tsi marked this conversation as resolved.
Show resolved Hide resolved

if (CONTAINER_MIME_TYPES[type]) {
type = CONTAINER_MIME_TYPES[type];
} else {
type = type ? `video/${type}` : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import { some } from '../../../../utils/array';

export function formatToMimeTypeAndTransformation(format) {
const [container, codec] = format.toLowerCase().split('\/');
let result = CONTAINER_MIME_TYPES[container];
let transformation = null;

if (!result) {
result = [`video/${container}`, transformation];
}
const mimetype = CONTAINER_MIME_TYPES[container] || `video/${container}`;
let result = [mimetype];
tsi marked this conversation as resolved.
Show resolved Hide resolved

if (codec) {
transformation = codecToSrcTransformation(codec);
result = [`${result[0]}; codecs="${codecShorthandTrans(codec)}"`, transformation];
const transformation = codecToSrcTransformation(codec);
result = [`${CONTAINER_MIME_TYPES[container]}; codecs="${codecShorthandTrans(codec)}"`, transformation];
tsi marked this conversation as resolved.
Show resolved Hide resolved
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/cloudinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const setError = (that, res) => {
};

const setVideoSrc = (that, srcs) => {
console.log('Trying urls: ' + JSON.stringify(srcs));
console.log('Trying sources: ', srcs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it was previously there but can we get rid of it or hide it behind some debug mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to do that, but we don't have dev-mode yet (I plan to add it) and this is logged only on error and is now much less noisy and helps debugging, so I guess it's ok for now

srcs.forEach(s => {
s.try = true;
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/videoSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Raw url tests', () => {
let source = new VideoSource(url, sourceDef);
let srcs = source.generateSources();
expect(srcs[0].src).toEqual(url);
expect(srcs[0].type).toEqual(null);
expect(srcs[0].type).toEqual('video/mp4');
expect(srcs[0].isAdaptive).toEqual(false);
});
it('Test raw url with transformations', () => {
Expand All @@ -169,7 +169,7 @@ describe('Raw url tests', () => {
let source = new VideoSource(url, sourceDef);
let srcs = source.generateSources();
expect(srcs[0].src).toEqual(url);
expect(srcs[0].type).toEqual(null);
expect(srcs[0].type).toEqual('video/mp4');
expect(srcs[0].isAdaptive).toEqual(false);
});
it('Test raw url without extension', () => {
Expand Down
Loading