@ -39,6 +39,7 @@ var (
)
var dl_atmos = false
var dl_select = false
var artist_select = false
type Config struct {
MediaUserToken string ` yaml:"media-user-token" `
@ -66,6 +67,7 @@ type Config struct {
GetM3u8FromDevice bool ` yaml:"get-m3u8-from-device" `
AlacMax int ` yaml:"alac-max" `
AtmosMax int ` yaml:"atmos-max" `
LimitMax int ` yaml:"limit-max" `
UseSongInfoForPlaylist bool ` yaml:"use-songinfo-for-playlist" `
DlAlbumcoverForPlaylist bool ` yaml:"dl-albumcover-for-playlist" `
}
@ -101,6 +103,13 @@ func loadConfig() error {
return nil
}
func LimitString ( s string ) string {
if len ( [ ] rune ( s ) ) > config . LimitMax {
return string ( [ ] rune ( s ) [ : config . LimitMax ] )
}
return s
}
func ( s * SongInfo ) Duration ( ) ( ret uint64 ) {
for i := range s . samples {
ret += uint64 ( s . samples [ i ] . duration )
@ -796,12 +805,12 @@ func writeM4a(w *mp4.Writer, info *SongInfo, meta *AutoGenerated, data []byte, t
if len ( meta . Data ) > 0 {
album := meta . Data [ 0 ]
err = addMeta ( mp4 . BoxType { 'a' , 'A' , 'R' , 'T' } , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . ArtistName )
err = addMeta ( mp4 . BoxType { 'a' , 'A' , 'R' , 'T' } , meta . Data [ 0 ] . Attributes . ArtistName )
if err != nil {
return err
}
err = addMeta ( mp4 . BoxType { 's' , 'o' , 'a' , 'a' } , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . ArtistName )
err = addMeta ( mp4 . BoxType { 's' , 'o' , 'a' , 'a' } , meta . Data [ 0 ] . Attributes . ArtistName )
if err != nil {
return err
}
@ -1105,6 +1114,10 @@ func checkArtist(artistUrl string, token string) ([]string, error) {
for i , option := range options {
fmt . Printf ( "%02d: %s\n" , i + 1 , option )
}
if artist_select {
fmt . Println ( "You have selected all options:" )
return urls , nil
}
reader := bufio . NewReader ( os . Stdin )
fmt . Println ( "Please select from the following options (multiple options separated by commas, ranges supported, or type 'all' to select all)" )
fmt . Print ( "Enter your choice: " )
@ -1344,12 +1357,12 @@ func rip(albumId string, token string, storefront string, userToken string) erro
) . Replace ( config . ArtistFolderFormat )
} else if len ( meta . Data [ 0 ] . Relationships . Artists . Data ) > 0 {
singerFoldername = strings . NewReplacer (
"{ArtistName}" , meta . Data [ 0 ] . Attributes . ArtistName ,
"{ArtistName}" , LimitString ( meta . Data [ 0 ] . Attributes . ArtistName ) ,
"{ArtistId}" , meta . Data [ 0 ] . Relationships . Artists . Data [ 0 ] . ID ,
) . Replace ( config . ArtistFolderFormat )
} else {
singerFoldername = strings . NewReplacer (
"{ArtistName}" , meta . Data [ 0 ] . Attributes . ArtistName ,
"{ArtistName}" , LimitString ( meta . Data [ 0 ] . Attributes . ArtistName ) ,
"{ArtistId}" , "" ,
) . Replace ( config . ArtistFolderFormat )
}
@ -1408,7 +1421,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
if strings . Contains ( albumId , "pl." ) {
albumFolder = strings . NewReplacer (
"{ArtistName}" , "Apple Music" ,
"{PlaylistName}" , meta . Data [ 0 ] . Attributes . Name ,
"{PlaylistName}" , LimitString ( meta . Data [ 0 ] . Attributes . Name ) ,
"{PlaylistId}" , albumId ,
"{Quality}" , Quality ,
"{Codec}" , Codec ,
@ -1418,8 +1431,8 @@ func rip(albumId string, token string, storefront string, userToken string) erro
albumFolder = strings . NewReplacer (
"{ReleaseDate}" , meta . Data [ 0 ] . Attributes . ReleaseDate ,
"{ReleaseYear}" , meta . Data [ 0 ] . Attributes . ReleaseDate [ : 4 ] ,
"{ArtistName}" , meta . Data [ 0 ] . Attributes . ArtistName ,
"{AlbumName}" , meta . Data [ 0 ] . Attributes . Name ,
"{ArtistName}" , LimitString ( meta . Data [ 0 ] . Attributes . ArtistName ) ,
"{AlbumName}" , LimitString ( meta . Data [ 0 ] . Attributes . Name ) ,
"{UPC}" , meta . Data [ 0 ] . Attributes . Upc ,
"{RecordLabel}" , meta . Data [ 0 ] . Attributes . RecordLabel ,
"{Copyright}" , meta . Data [ 0 ] . Attributes . Copyright ,
@ -1574,7 +1587,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
songName := strings . NewReplacer (
"{SongId}" , track . ID ,
"{SongNumer}" , fmt . Sprintf ( "%02d" , trackNum ) ,
"{SongName}" , track . Attributes . Name ,
"{SongName}" , LimitString ( track . Attributes . Name ) ,
"{DiscNumber}" , fmt . Sprintf ( "%0d" , track . Attributes . DiscNumber ) ,
"{TrackNumber}" , fmt . Sprintf ( "%0d" , track . Attributes . TrackNumber ) ,
"{Quality}" , Quality ,
@ -1675,7 +1688,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt . Sprintf ( "album_artist=%s" , meta . Data [ 0 ] . Attributes . ArtistName ) ,
fmt . Sprintf ( "composer=%s" , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . ComposerName ) ,
fmt . Sprintf ( "writer=%s" , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . ComposerName ) ,
fmt . Sprintf ( "performer=%s" , meta . Data [ 0 ] . Attributes . ArtistName ) ,
fmt . Sprintf ( "performer=%s" , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . ArtistName ) ,
fmt . Sprintf ( "copyright=%s" , meta . Data [ 0 ] . Attributes . Copyright ) ,
fmt . Sprintf ( "ISRC=%s" , meta . Data [ 0 ] . Relationships . Tracks . Data [ index ] . Attributes . Isrc ) ,
fmt . Sprintf ( "UPC=%s" , meta . Data [ 0 ] . Attributes . Upc ) ,
@ -1756,6 +1769,8 @@ func main() {
dl_atmos = true
} else if strings . Contains ( arg , "--select" ) {
dl_select = true
} else if strings . Contains ( arg , "--all-album" ) {
artist_select = true
} else {
dlArgs = append ( dlArgs , arg )
}