File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,13 @@ const validQueryDomains = new Set([
2222 'music.youtube.com' ,
2323 'gaming.youtube.com' ,
2424] ) ;
25- const validPathDomains = / ^ h t t p s ? : \/ \/ ( y o u t u \. b e \/ | ( w w w \. ) ? y o u t u b e .c o m \/ ( e m b e d | v | s h o r t s ) \/ ) / ;
25+ const validPathDomains = / ^ h t t p s ? : \/ \/ ( y o u t u \. b e \/ | ( w w w \. ) ? y o u t u b e \ .c o m \/ ( e m b e d | v | s h o r t s ) \/ ) / ;
2626exports . getURLVideoID = link => {
2727 const parsed = new URL ( link ) ;
2828 let id = parsed . searchParams . get ( 'v' ) ;
2929 if ( validPathDomains . test ( link ) && ! id ) {
3030 const paths = parsed . pathname . split ( '/' ) ;
31- id = paths [ paths . length - 1 ] ;
31+ id = parsed . host === 'youtu.be' ? paths [ 1 ] : paths [ 2 ] ;
3232 } else if ( parsed . hostname && ! validQueryDomains . has ( parsed . hostname ) ) {
3333 throw Error ( 'Not a YouTube domain' ) ;
3434 }
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ describe('getURLVideoID()', () => {
1919 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
2020 id = getVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
2121 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
22+ id = getVideoID ( 'http://youtube.com/v/RAW_VIDEOID/FakeVideoID' ) ;
23+ assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
2224 id = getVideoID ( 'https://music.youtube.com/watch?v=RAW_VIDEOID&list=RDAMVMmtLgabce8KQ' ) ;
2325 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
2426 id = getVideoID ( 'https://gaming.youtube.com/watch?v=RAW_VIDEOID' ) ;
@@ -59,6 +61,8 @@ describe('getVideoID()', () => {
5961 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
6062 id = getVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
6163 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
64+ id = getVideoID ( 'http://youtube.com/v/RAW_VIDEOID/FakeVideoID' ) ;
65+ assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
6266 id = getVideoID ( '_LENGTH_11_' ) ;
6367 assert . strictEqual ( id , '_LENGTH_11_' ) ;
6468 assert . throws ( ( ) => {
You can’t perform that action at this time.
0 commit comments