1- import { SearchVideo } from 'youtube-ext ' ;
1+ import { Video } from '@distube/ytsr ' ;
22import { YoutubeHeuristics } from './heuristics' ;
33
4- export const ytTrack = ( overrides ?: Partial < SearchVideo > ) : Partial < SearchVideo > => ( {
5- title : 'Black Sabbath - Paranoid' ,
6- channel : {
4+ export const ytTrack = ( overrides ?: Partial < Video > ) : Partial < Video > => ( {
5+ name : 'Black Sabbath - Paranoid' ,
6+ author : {
77 name : 'Black Sabbath'
8- } as SearchVideo [ 'channel '] ,
9- duration : { text : '172' , pretty : '2:12' } ,
8+ } as Video [ 'author '] ,
9+ duration : '172' ,
1010 ...overrides
1111} ) ;
1212
1313describe ( 'Search heuristics' , ( ) => {
1414 it ( 'finds a verbatim match' , ( ) => {
1515 const tracks = [
1616 ytTrack ( {
17- title : 'Ozzy Osbourne - Crazy Train'
17+ name : 'Ozzy Osbourne - Crazy Train'
1818 } ) ,
1919 ytTrack ( {
20- title : 'Frank Zappa - Muffin Man'
20+ name : 'Frank Zappa - Muffin Man'
2121 } ) ,
2222 ytTrack ( {
23- title : 'Black Sabbath - Paranoid'
23+ name : 'Black Sabbath - Paranoid'
2424 } ) ,
2525 ytTrack ( {
26- title : 'The White Stripes - Seven Nation Army'
26+ name : 'The White Stripes - Seven Nation Army'
2727 } )
2828 ] ;
2929
@@ -40,13 +40,13 @@ describe('Search heuristics', () => {
4040 it ( 'prefers titles that contain the artist and title verbatim' , ( ) => {
4141 const tracks = [
4242 ytTrack ( {
43- title : 'Rammstein - Zick Zack (Official Video)'
43+ name : 'Rammstein - Zick Zack (Official Video)'
4444 } ) ,
4545 ytTrack ( {
46- title : 'Rammstein - Zeit (Official Video)'
46+ name : 'Rammstein - Zeit (Official Video)'
4747 } ) ,
4848 ytTrack ( {
49- title : 'Rammstein - Zeig Dich (Official Lyric Video)'
49+ name : 'Rammstein - Zeig Dich (Official Lyric Video)'
5050 } )
5151 ] ;
5252
@@ -64,10 +64,10 @@ describe('Search heuristics', () => {
6464 it ( 'prefers a closer match in case of a partial match' , ( ) => {
6565 const tracks = [
6666 ytTrack ( {
67- title : 'Johnny Cash - The Mercy Seat'
67+ name : 'Johnny Cash - The Mercy Seat'
6868 } ) ,
6969 ytTrack ( {
70- title : 'Nick Cave - The Mercy Seat'
70+ name : 'Nick Cave - The Mercy Seat'
7171 } )
7272 ] ;
7373
@@ -83,13 +83,13 @@ describe('Search heuristics', () => {
8383 it ( 'tolerates typos' , ( ) => {
8484 const tracks = [
8585 ytTrack ( {
86- title : 'The Whte Stipes - Sevn Natn Ary'
86+ name : 'The Whte Stipes - Sevn Natn Ary'
8787 } ) ,
8888 ytTrack ( {
89- title : 'The Whte Stripes - Sevn Nation Army'
89+ name : 'The Whte Stripes - Sevn Nation Army'
9090 } ) ,
9191 ytTrack ( {
92- title : 'Arctic Monkeys - Do I Wanna Know'
92+ name : 'Arctic Monkeys - Do I Wanna Know'
9393 } )
9494 ] ;
9595
@@ -110,10 +110,10 @@ describe('Search heuristics', () => {
110110 it ( 'prefers an official video' , ( ) => {
111111 const tracks = [
112112 ytTrack ( {
113- title : 'Ozzy Osbourne - Crazy Train (crappy bootleg)'
113+ name : 'Ozzy Osbourne - Crazy Train (crappy bootleg)'
114114 } ) ,
115115 ytTrack ( {
116- title : 'Ozzy Osbourne - Crazy Train - Official Video'
116+ name : 'Ozzy Osbourne - Crazy Train - Official Video'
117117 } )
118118 ] ;
119119
@@ -130,13 +130,13 @@ describe('Search heuristics', () => {
130130 it ( 'prefers high quality videos' , ( ) => {
131131 const tracks = [
132132 ytTrack ( {
133- title : 'Ozzy Osbourne - Crazy Train (crappy bootleg)'
133+ name : 'Ozzy Osbourne - Crazy Train (crappy bootleg)'
134134 } ) ,
135135 ytTrack ( {
136- title : 'Ozzy Osbourne - Crazy Train (HQ)'
136+ name : 'Ozzy Osbourne - Crazy Train (HQ)'
137137 } ) ,
138138 ytTrack ( {
139- title : 'Ozzy Osbourne - Crazy Train - High Quality'
139+ name : 'Ozzy Osbourne - Crazy Train - High Quality'
140140 } )
141141 ] ;
142142
@@ -157,20 +157,20 @@ describe('Search heuristics', () => {
157157 it ( 'prefers videos with closest duration' , ( ) => {
158158 const tracks = [
159159 ytTrack ( {
160- title : 'Frank Zappa - Peaches en Regalia' ,
161- duration : { text : '180' , pretty : '3:00' }
160+ name : 'Frank Zappa - Peaches en Regalia' ,
161+ duration : '180'
162162 } ) ,
163163 ytTrack ( {
164- title : 'Frank Zappa - Peaches en Regalia' ,
165- duration : { text : '219' , pretty : '3:39' }
164+ name : 'Frank Zappa - Peaches en Regalia' ,
165+ duration : '219'
166166 } ) ,
167167 ytTrack ( {
168- title : 'Frank Zappa - Peaches en Regalia' ,
169- duration : { text : '300' , pretty : '5:00' }
168+ name : 'Frank Zappa - Peaches en Regalia' ,
169+ duration : '300'
170170 } ) ,
171171 ytTrack ( {
172- title : 'Frank Zappa - Peaches en Regalia' ,
173- duration : { text : '360' , pretty : '6:00' }
172+ name : 'Frank Zappa - Peaches en Regalia' ,
173+ duration : '360'
174174 } )
175175 ] ;
176176
@@ -193,10 +193,10 @@ describe('Search heuristics', () => {
193193 it ( 'ranks videos with full albums lower' , ( ) => {
194194 const tracks = [
195195 ytTrack ( {
196- title : 'Black Sabbath - Paranoid (Full album)'
196+ name : 'Black Sabbath - Paranoid (Full album)'
197197 } ) ,
198198 ytTrack ( {
199- title : 'Black Sabbath - Paranoid (random addition to the title)'
199+ name : 'Black Sabbath - Paranoid (random addition to the title)'
200200 } )
201201 ] ;
202202
@@ -216,10 +216,10 @@ describe('Search heuristics', () => {
216216 it ( 'ranks live videos lower' , ( ) => {
217217 const tracks = [
218218 ytTrack ( {
219- title : 'Black Sabbath - Paranoid (Live)'
219+ name : 'Black Sabbath - Paranoid (Live)'
220220 } ) ,
221221 ytTrack ( {
222- title : 'Black Sabbath - Paranoid (Something else)'
222+ name : 'Black Sabbath - Paranoid (Something else)'
223223 } )
224224 ] ;
225225
@@ -238,13 +238,13 @@ describe('Search heuristics', () => {
238238 it ( 'ranks live videos normally if they also appear in the search query title' , ( ) => {
239239 const tracks = [
240240 ytTrack ( {
241- title : 'Black Sabbath - Paranoid'
241+ name : 'Black Sabbath - Paranoid'
242242 } ) ,
243243 ytTrack ( {
244- title : 'Black Sabbath - Paranoid (Live)'
244+ name : 'Black Sabbath - Paranoid (Live)'
245245 } ) ,
246246 ytTrack ( {
247- title : 'Black Sabbath - Paranoid (Random addition to the title)'
247+ name : 'Black Sabbath - Paranoid (Random addition to the title)'
248248 } )
249249 ] ;
250250
@@ -265,10 +265,10 @@ describe('Search heuristics', () => {
265265 it ( 'ranks remix videos lower' , ( ) => {
266266 const tracks = [
267267 ytTrack ( {
268- title : 'Black Sabbath - Paranoid (Remix)'
268+ name : 'Black Sabbath - Paranoid (Remix)'
269269 } ) ,
270270 ytTrack ( {
271- title : 'Black Sabbath - Paranoid (Random addition to the title)'
271+ name : 'Black Sabbath - Paranoid (Random addition to the title)'
272272 } )
273273 ] ;
274274
@@ -289,16 +289,16 @@ describe('Search heuristics', () => {
289289 it ( 'ranks videos whose channel names include the artist name higher' , ( ) => {
290290 const tracks = [
291291 ytTrack ( {
292- title : 'Savant - Valkyrie' ,
293- channel : {
292+ name : 'Savant - Valkyrie' ,
293+ author : {
294294 name : 'EssentialEDMusic'
295- } as SearchVideo [ 'channel ']
295+ } as Video [ 'author ']
296296 } ) ,
297297 ytTrack ( {
298- title : 'Savant - Orakel - Valkyrie' ,
299- channel : {
298+ name : 'Savant - Orakel - Valkyrie' ,
299+ author : {
300300 name : 'SAVANT'
301- } as SearchVideo [ 'channel ']
301+ } as Video [ 'author ']
302302 } )
303303 ] ;
304304
@@ -318,16 +318,16 @@ describe('Search heuristics', () => {
318318 it ( 'ranks videos whose names match the track title exactly, and channel names match artist name exactly higher' , ( ) => {
319319 const tracks = [
320320 ytTrack ( {
321- title : 'Savant - Wildstyle' ,
322- channel : {
321+ name : 'Savant - Wildstyle' ,
322+ author : {
323323 name : 'Tasty'
324- } as SearchVideo [ 'channel ']
324+ } as Video [ 'author ']
325325 } ) ,
326326 ytTrack ( {
327- title : 'Firestarter' ,
328- channel : {
327+ name : 'Firestarter' ,
328+ author : {
329329 name : 'SAVANT'
330- } as SearchVideo [ 'channel ']
330+ } as Video [ 'author ']
331331 } )
332332 ] ;
333333
0 commit comments