2025-05-20 13:18:38 +01:00
import "should" ;
import * as ytmusic from "../../lib/services/ytmusic/index.js" ;
2021-01-16 23:03:41 +01:00
2025-05-20 13:18:38 +01:00
describe ( "ytmusic" , function ( ) {
describe ( "lookupId" , ( ) => {
it ( "should find album by ID" , async function testV ( ) {
const result = await ytmusic . lookupId (
"OLAK5uy_kalBoqyqQmbtZKCBV43Qipcoe2O2Hg_to" ,
"album"
) ;
result . name . should . equal ( "Carne de Pescoço" ) ;
2021-01-17 00:29:05 +01:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find track by ID" , async function ( ) {
const result = await ytmusic . lookupId ( "9zrYXvUXiQk" , "track" ) ;
result . name . should . equal ( "One Vision" ) ;
result . artist . name . should . equal ( "Queen" ) ;
result . album . name . should . equal ( "A Kind Of Magic" ) ;
2021-06-02 20:31:40 +02:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find track by ID" , async function ( ) {
const result = await ytmusic . lookupId ( "rAzfNuU1f8E" , "track" ) ;
result . name . should . equal ( "Erre (Live)" ) ;
result . artist . name . should . equal ( "Boogarins" ) ;
2021-06-02 20:31:40 +02:00
// The copyright notice is too long and is the only place where the album name is.
2025-05-20 13:18:38 +01:00
result . album . name . should . equal ( "" ) ;
2021-06-02 20:31:40 +02:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find track by ID" , async function ( ) {
const result = await ytmusic . lookupId ( "Wst0la_TgTY" , "track" ) ;
result . name . should . equal ( "Às Vezes Bate Uma Saudade" ) ;
2021-06-02 20:31:40 +02:00
// XXX: This is very odd. Sometimes, google will return the first artist "Rodrigo Alarcon", sometimes "Rodrigo Alarcon, Ana Muller & Mariana Froes" and sometimes
// "Rodrigo Alarcon, Ana Muller, Mariana Froes". Same API call, same everything. Go figure.
// result.artist.name.should.equal('Rodrigo Alarcon, Ana Muller, Mariana Froes');
2025-05-20 13:18:38 +01:00
result . artist . name . should . startWith ( "Rodrigo Alarcon" ) ;
result . album . name . should . equal ( "Taquetá Vol.1" ) ;
2021-01-17 00:29:05 +01:00
} ) ;
} ) ;
2025-05-20 13:18:38 +01:00
describe ( "search" , ( ) => {
it ( "should find album by search" , async function ( ) {
const result = await ytmusic . search ( {
type : "album" ,
artist : { name : "Jamie xx" } ,
name : "In Colour"
} ) ;
result . name . should . startWith ( "In Colour" ) ;
2021-01-17 02:03:23 +01:00
result . id . should . equal ( "MPREb_IbDz5pAZFvJ" ) ;
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find album with various artists by search" , async function ( ) {
const result = await ytmusic . search ( {
type : "album" ,
artist : { name : "Various Artists" } ,
name : "Sambabook João Nogueira"
} ) ;
result . name . should . equal ( "Sambabook João Nogueira" ) ;
result . id . should . equal ( "MPREb_iZt1VjORlv7" ) ;
2021-01-17 02:03:23 +01:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find album and make sure it makes sense by search" , async function ( ) {
const result = await ytmusic . search ( {
type : "album" ,
artist : { name : "The Beatles" } ,
name : "The Beatles"
} ) ;
result . name . should . equal ( "The Beatles" ) ;
result . id . should . equal ( "MPREb_S5TiUIYvI78" ) ;
2021-01-17 16:40:16 +01:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should find track by search" , async function ( ) {
const result = await ytmusic . search ( {
type : "track" ,
artist : { name : "Oasis" } ,
albumName : "Stop The Clocks" ,
name : "Wonderwall"
} ) ;
result . name . should . equal ( "Wonderwall" ) ;
result . id . should . equal ( "Gvfgut8nAgw" ) ;
2021-01-17 02:03:23 +01:00
} ) ;
} ) ;
2025-05-20 13:18:38 +01:00
describe ( "lookupUrl" , ( ) => {
describe ( "parseUrl" , ( ) => {
it ( "should parse track url into ID" , async function ( ) {
const result = await ytmusic . parseUrl (
"https://music.youtube.com/watch?v=YLp2cW7ICCU&feature=share"
) ;
2021-01-16 23:03:41 +01:00
result . id . should . equal ( "YLp2cW7ICCU" ) ;
2025-05-20 13:18:38 +01:00
result . streamUrl . should . equal (
"https://music.youtube.com/watch?v=YLp2cW7ICCU"
) ;
2021-01-16 23:03:41 +01:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should parse album url into ID" , async function ( ) {
const result = await ytmusic . parseUrl (
"https://music.youtube.com/browse/MPREb_9C36yscfgmJ"
) ;
2021-01-16 23:03:41 +01:00
result . id . should . equal ( "MPREb_9C36yscfgmJ" ) ;
2025-05-20 13:18:38 +01:00
result . streamUrl . should . equal (
"https://music.youtube.com/browse/MPREb_9C36yscfgmJ"
) ;
2021-01-16 23:03:41 +01:00
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should parse alternative album url into ID" , async function ( ) {
const result = await ytmusic . parseUrl (
"https://music.youtube.com/playlist?list=OLAK5uy_lx9K5RpiBEwd3E4C1GKqY7e06qTlwydvs"
) ;
2021-01-16 23:03:41 +01:00
result . id . should . equal ( "MPREb_9C36yscfgmJ" ) ;
} ) ;
2025-05-20 13:18:38 +01:00
it ( "should parse alternative album url into ID, regression" , async function ( ) {
const result = await ytmusic . parseUrl (
"https://music.youtube.com/playlist?list=OLAK5uy_kxepMtCUKFek54-bgWICIsmglK86HD0TM"
) ;
2021-06-08 19:06:36 +02:00
result . id . should . equal ( "MPREb_XmlDLpyWvMt" ) ;
} ) ;
2021-01-16 23:03:41 +01:00
} ) ;
} ) ;
} ) ;