From 7b2d585d5a0947495ba12df665f60977c9ed0f83 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 28 Mar 2022 10:06:23 -0500 Subject: improve VBR, CBR filtering. add lossless --- src/web/src/lib/search.js | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/web/src/lib/search.js b/src/web/src/lib/search.js index ab0742ce..a581c3ea 100644 --- a/src/web/src/lib/search.js +++ b/src/web/src/lib/search.js @@ -19,32 +19,6 @@ export const getResponses = async ({ id }) => { return response; }; -export const isConstantBitRate = (bitRate) => { - switch (bitRate) { - case 8: - case 16: - case 24: - case 32: - case 40: - case 48: - case 56: - case 64: - case 80: - case 96: - case 112: - case 128: - case 144: - case 160: - case 192: - case 224: - case 256: - case 320: - return true; - default: - return false; - } -} - export const parseFiltersFromString = (string) => { const filters = { minBitRate: 0, @@ -54,7 +28,8 @@ export const parseFiltersFromString = (string) => { include: [], exclude: [], isVBR: false, - isCBR: false + isCBR: false, + isLossless: false, }; const getNthMatch = (string, regex, n) => { @@ -72,9 +47,10 @@ export const parseFiltersFromString = (string) => { filters.isVBR = !!string.match(/isvbr/i); filters.isCBR = !!string.match(/iscbr/i); + filters.isLossless = !!string.match(/islossless/i); let terms = string.toLowerCase().split(' ') - .filter(term => !term.includes(':') && term !== 'isvbr' && term !== 'iscbr'); + .filter(term => !term.includes(':') && term !== 'isvbr' && term !== 'iscbr' && term !== 'islossless'); filters.include = terms.filter(term => !term.startsWith('-')); filters.exclude = terms.filter(term => term.startsWith('-')).map(term => term.slice(1)); @@ -90,7 +66,8 @@ export const filterResponse = ({ include: [], exclude: [], isVBR: false, - isCBR: false + isCBR: false, + isLossless: false, }, response = { files: [], @@ -104,11 +81,12 @@ export const filterResponse = ({ } const filterFiles = (files) => files.filter(file => { - const { bitRate, size, length, filename } = file; - const { isCBR, isVBR, minBitRate, minFileSize, minLength, include = [], exclude = [] } = filters; + const { bitRate, size, length, filename, sampleRate, bitDepth, isVariableBitRate } = file; + const { isCBR, isVBR, isLossless, minBitRate, minFileSize, minLength, include = [], exclude = [] } = filters; - if (isCBR && !isConstantBitRate(bitRate)) return false; - if (isVBR && isConstantBitRate(bitRate)) return false; + if (isCBR && (isVariableBitRate === undefined || isVariableBitRate)) return false; + if (isVBR && (isVariableBitRate === undefined || !isVariableBitRate)) return false; + if (isLossless && (!sampleRate || !bitDepth)) return false; if (bitRate < minBitRate) return false; if (size < minFileSize) return false; if (length < minLength) return false; -- cgit v1.2.3 From 928491c7f313226ca56d5ad82cd5ee85e5f50dac Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 28 Mar 2022 20:56:53 -0500 Subject: add islossless to filter placeholder --- src/web/src/components/Search/Search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js index ef08306d..5b473c99 100644 --- a/src/web/src/components/Search/Search.js +++ b/src/web/src/components/Search/Search.js @@ -262,7 +262,7 @@ class Search extends Component { Date: Tue, 29 Mar 2022 07:42:29 -0500 Subject: add islossy filter --- src/web/src/components/Search/Search.js | 2 +- src/web/src/lib/search.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Search/Search.js b/src/web/src/components/Search/Search.js index 5b473c99..713bfe26 100644 --- a/src/web/src/components/Search/Search.js +++ b/src/web/src/components/Search/Search.js @@ -262,7 +262,7 @@ class Search extends Component { { isVBR: false, isCBR: false, isLossless: false, + isLossy: false, }; const getNthMatch = (string, regex, n) => { @@ -48,9 +49,10 @@ export const parseFiltersFromString = (string) => { filters.isVBR = !!string.match(/isvbr/i); filters.isCBR = !!string.match(/iscbr/i); filters.isLossless = !!string.match(/islossless/i); + filters.isLossy = !!string.match(/islossy/i); let terms = string.toLowerCase().split(' ') - .filter(term => !term.includes(':') && term !== 'isvbr' && term !== 'iscbr' && term !== 'islossless'); + .filter(term => !term.includes(':') && term !== 'isvbr' && term !== 'iscbr' && term !== 'islossless' && term !== 'islossy'); filters.include = terms.filter(term => !term.startsWith('-')); filters.exclude = terms.filter(term => term.startsWith('-')).map(term => term.slice(1)); @@ -68,6 +70,7 @@ export const filterResponse = ({ isVBR: false, isCBR: false, isLossless: false, + isLossy: false, }, response = { files: [], @@ -82,11 +85,14 @@ export const filterResponse = ({ const filterFiles = (files) => files.filter(file => { const { bitRate, size, length, filename, sampleRate, bitDepth, isVariableBitRate } = file; - const { isCBR, isVBR, isLossless, minBitRate, minFileSize, minLength, include = [], exclude = [] } = filters; - + const { isCBR, isVBR, isLossless, isLossy, minBitRate, minFileSize, minLength, include = [], exclude = [] } = filters; + + console.log(filters); + if (isCBR && (isVariableBitRate === undefined || isVariableBitRate)) return false; if (isVBR && (isVariableBitRate === undefined || !isVariableBitRate)) return false; if (isLossless && (!sampleRate || !bitDepth)) return false; + if (isLossy && (sampleRate || bitDepth)) return false; if (bitRate < minBitRate) return false; if (size < minFileSize) return false; if (length < minLength) return false; -- cgit v1.2.3 From 373f63258eb6ffbd4868efda36d21f3c064023ec Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 31 Mar 2022 07:35:23 -0500 Subject: remove log --- src/web/src/lib/search.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/web/src/lib/search.js b/src/web/src/lib/search.js index ee2f80ca..306c7041 100644 --- a/src/web/src/lib/search.js +++ b/src/web/src/lib/search.js @@ -87,8 +87,6 @@ export const filterResponse = ({ const { bitRate, size, length, filename, sampleRate, bitDepth, isVariableBitRate } = file; const { isCBR, isVBR, isLossless, isLossy, minBitRate, minFileSize, minLength, include = [], exclude = [] } = filters; - console.log(filters); - if (isCBR && (isVariableBitRate === undefined || isVariableBitRate)) return false; if (isVBR && (isVariableBitRate === undefined || !isVariableBitRate)) return false; if (isLossless && (!sampleRate || !bitDepth)) return false; -- cgit v1.2.3 From 0ec6a8228c0723710c84cc3c63d4ae627f34cdd2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 31 Mar 2022 07:41:02 -0500 Subject: fix tests --- src/web/src/lib/search.test.js | 73 ++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/web/src/lib/search.test.js b/src/web/src/lib/search.test.js index 85e1d5f6..68afe91c 100644 --- a/src/web/src/lib/search.test.js +++ b/src/web/src/lib/search.test.js @@ -1,34 +1,11 @@ import * as search from './search'; -describe('isConstantBitRate', () => { - it('returns true given a valid MPEG-3 bitrate', () => { - const bitrates = [8,16,24,32,40,48,56,64,80,96,112,128,144,160,192,224,256,320]; - - bitrates.forEach(br => { - expect(search.isConstantBitRate(br)).toBe(true); - }); - }); - - it('returns false given an invalid MPEG-3 bitrate', () => { - const bitrates = [5,7,65,150,321]; - - bitrates.forEach(br => { - expect(search.isConstantBitRate(br)).toBe(false); - }); - }); - - it('returns false given null or undefined', () => { - expect(search.isConstantBitRate(null)).toBe(false); - expect(search.isConstantBitRate()).toBe(false); - }); -}); - describe('filterResponse', () => { it('removes VBR files if "iscbr" is specified', () => { const response = { files: [ - { bitRate: 123 }, - { bitRate: 320 } + { bitRate: 123, isVariableBitRate: true }, + { bitRate: 320, isVariableBitRate: false } ] }; @@ -36,7 +13,7 @@ describe('filterResponse', () => { expect(search.filterResponse({ response, filters })).toMatchObject({ files: [ - { bitRate: 320 } + { bitRate: 320, isVariableBitRate: false } ] }); }); @@ -44,8 +21,8 @@ describe('filterResponse', () => { it('removes CBR files if "isvbr" is specified', () => { const response = { files: [ - { bitRate: 123 }, - { bitRate: 320 } + { bitRate: 123, isVariableBitRate: true }, + { bitRate: 320, isVariableBitRate: false } ] }; @@ -53,7 +30,7 @@ describe('filterResponse', () => { expect(search.filterResponse({ response, filters })).toMatchObject({ files: [ - { bitRate: 123 } + { bitRate: 123, isVariableBitRate: true } ] }); }); @@ -61,8 +38,8 @@ describe('filterResponse', () => { it('removes all files if "iscbr" and "isvbr" are both specified', () => { const response = { files: [ - { bitRate: 123 }, - { bitRate: 320 } + { isVariableBitrate: true }, + { isVariableBitrate: false } ] }; @@ -73,6 +50,40 @@ describe('filterResponse', () => { }); }); + it('removes lossy files if "islossless" is specified', () => { + const response = { + files: [ + { sampleRate: 41000, bitDepth: 16 }, + { bitRate: 320, isVariableBitRate: false } + ] + }; + + const filters = { isLossless: true }; + + expect(search.filterResponse({ response, filters })).toMatchObject({ + files: [ + { sampleRate: 41000, bitDepth: 16 } + ] + }); + }); + + it('removes lossless files if "islossy" is specified', () => { + const response = { + files: [ + { sampleRate: 41000, bitDepth: 16 }, + { bitRate: 320, isVariableBitRate: false } + ] + }; + + const filters = { isLossy: true }; + + expect(search.filterResponse({ response, filters })).toMatchObject({ + files: [ + { bitRate: 320, isVariableBitRate: false } + ] + }); + }); + it('removes files with bitRate less than minBitRate', () => { const response = { files: [ -- cgit v1.2.3