package Ġju ke bot . audio . source managers . spotify . loaders Ċ Ċ import Ġcom . gr ack . nano json . JsonObject Ċ import Ġcom . gr ack . nano json . Json Parser Ċ import Ġcom . sed mell uq . discord . lav ap layer . track . Audio Item Ċ import Ġju ke bot . audio . source managers . spotify . Spot ify Audio Source Manager Ċ import Ġorg . apache . http . HttpStatus Ċ import Ġjava . util . regex . Matcher Ċ Ċ class ĠSpotify Track Loader Ġ: ĠLoader Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġpattern () Ġ= ĠTR ACK _ PATTERN ĊĊĠĠĠ Ġoverride Ġfun Ġload ( source Manager : ĠSpotify Audio Source Manager , Ġmatcher : ĠMatcher ): ĠAudio Item ? Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtrack Id Ġ= Ġmatcher . group ( 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġspot ify Track Ġ= Ġfetch Track Info ( source Manager , Ġtrack Id ) ĊĠĠĠĠĠĠĠ Ġval Ġtrack Art ists Ġ= Ġspot ify Track . get Array (" artists ") ĊĠĠĠĠĠĠĠ Ġval Ġtrack Artist Ġ= Ġif Ġ( track Art ists . isEmpty ()) Ġ"" Ġelse Ġtrack Art ists . getObject ( 0 ). getString (" name ") ĊĠĠĠĠĠĠĠ Ġval Ġtrack Title Ġ= Ġspot ify Track . getString (" name ") ĊĊĠĠĠĠĠĠĠ Ġreturn Ġsource Manager . do Y outube Search (" yt search :$ track Artist Ġ$ track Title ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġfetch Track Info ( source Manager : ĠSpotify Audio Source Manager , Ġtrack Id : ĠString ): ĠJsonObject Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġsource Manager . request (" https :// api . spotify . com / v 1 / tracks /$ track Id ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Header (" Authorization ", Ġ" Bearer Ġ${ source Manager . accessToken }") ĊĠĠĠĠĠĠĠ Ġ}. use Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcheck ( it . status Line . statusCode Ġ== ĠHttpStatus . SC _ OK ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Received Ġcode Ġ${ it . status Line . statusCode } Ġfrom ĠSpotify Ġwhile Ġfetching Ġtrack Ġinformation " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠJson Parser .` object ` (). from ( it . entity . content ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠTR ACK _ PATTERN Ġ= Ġ"^ (?: https ? :// (?: open \\. )? spotify \\. com | spotify ) ([ /: ]) track \\ 1 ([ a - zA - Z 0 - 9 ]+) ". to Pattern () ĊĠĠĠ Ġ} Ċ } Ċ