@@ -11,6 +11,7 @@ import {
11
11
createUserString ,
12
12
editOrReply ,
13
13
fetchMemberOrUserById ,
14
+ formatTime ,
14
15
} from '../../../utils' ;
15
16
16
17
@@ -23,72 +24,112 @@ export async function createMessage(
23
24
args : CommandArgs ,
24
25
) {
25
26
const isFromInteraction = ( context instanceof Interaction . InteractionContext ) ;
26
- const { error , result } = await audioToolsIdentify ( context , {
27
+ const songs = await audioToolsIdentify ( context , {
27
28
url : args . url ,
28
29
} ) ;
29
30
30
- if ( ! result ) {
31
- let content : string ;
32
- if ( error ) {
33
- content = `Error: ${ error . error_message } ` ;
34
- } else {
35
- content = 'Unable to identify any songs in the media provided' ;
36
- }
37
- return editOrReply ( context , { content, flags : MessageFlags . EPHEMERAL } ) ;
38
- }
31
+ if ( songs . length ) {
32
+ const pageLimit = songs . length || 1 ;
33
+ const paginator = new Paginator ( context , {
34
+ pageLimit,
35
+ onPage : ( page ) => {
36
+ const song = songs [ page - 1 ] ;
39
37
40
- const embed = ( isFromInteraction ) ? new Embed ( ) : createUserEmbed ( context . user ) ;
41
- embed . setColor ( EmbedColors . DEFAULT ) ;
42
- embed . setFooter ( 'Audd.io Result' , EmbedBrands . AUDD ) ;
43
- embed . setTitle ( result . title ) ;
44
- embed . setUrl ( result . song_link ) ;
45
-
46
- {
47
- const description : Array < string > = [ ] ;
48
- description . push ( `**Album**: ${ result . album } ` ) ;
49
- description . push ( `**Artist**: ${ result . artist } ` ) ;
50
- if ( result . label ) {
51
- description . push ( `**Label**: ${ result . label } ` ) ;
52
- }
53
- description . push ( `**Release Date**: ${ result . release_date } ` ) ;
54
- description . push ( `**Title**: ${ result . title } ` ) ;
55
- embed . setDescription ( description . join ( '\n' ) ) ;
56
- }
38
+ const embed = ( isFromInteraction ) ? new Embed ( ) : createUserEmbed ( context . user ) ;
39
+ embed . setColor ( EmbedColors . DEFAULT ) ;
40
+ embed . setTitle ( song . title ) ;
57
41
58
- {
59
- const urls : Array < string > = [ Markup . url ( 'lis.tn' , result . song_link ) ] ;
60
- if ( result . apple_music ) {
61
- urls . push ( Markup . url ( 'Apple Music' , result . apple_music . url ) ) ;
62
- }
63
- if ( result . deezer ) {
64
- urls . push ( Markup . url ( 'Deezer' , result . deezer . link ) ) ;
65
- }
66
- if ( result . napster ) {
67
-
68
- }
69
- if ( result . spotify ) {
70
- urls . push ( Markup . url ( 'Spotify' , result . spotify . external_urls . spotify ) ) ;
71
- }
72
- embed . addField ( 'Direct Links' , urls . join ( ', ' ) ) ;
73
- }
42
+ {
43
+ let footer : string ;
44
+ if ( pageLimit === 1 ) {
45
+ footer = 'Audio Recognition Result' ;
46
+ } else {
47
+ footer = `Page ${ page } /${ pageLimit } of Audio Recognition Results` ;
48
+ }
49
+ embed . setFooter ( footer , EmbedBrands . NOTSOBOT ) ;
50
+ }
51
+
52
+ let thumbnail : string | undefined ;
53
+ for ( let key in song . platforms ) {
54
+ const platform = ( song . platforms as any ) [ key ] ;
55
+ if ( platform && platform . album && platform . album . cover_url ) {
56
+ thumbnail = platform . album . cover_url ;
57
+ break ;
58
+ }
59
+ }
60
+
61
+ if ( thumbnail ) {
62
+ embed . setThumbnail ( thumbnail ) ;
63
+ }
74
64
75
- {
76
- const urls : Array < string > = [ ] ;
77
- if ( result . apple_music && result . apple_music . previews . length ) {
78
- urls . push ( Markup . url ( 'Apple Music' , result . apple_music . previews [ 0 ] . url ) ) ;
79
- }
80
- if ( result . deezer && result . deezer . preview ) {
81
- urls . push ( Markup . url ( 'Deezer' , result . deezer . preview ) ) ;
82
- }
83
- if ( result . spotify ) {
84
- urls . push ( Markup . url ( 'Spotify' , result . spotify . preview_url || result . spotify . external_urls . spotify ) ) ;
85
- }
86
- if ( urls . length ) {
87
- embed . addField ( 'Preview Links' , urls . join ( ', ' ) ) ;
88
- }
65
+ {
66
+ const description : Array < string > = [ ] ;
67
+ description . push ( `**Album**: ${ song . album . name } ` ) ;
68
+ description . push ( `**Artist**: ${ song . artists [ 0 ] ! . name } ` ) ;
69
+ description . push ( `**Duration**: ${ formatTime ( song . duration ) } ` ) ;
70
+ if ( song . label ) {
71
+ description . push ( `**Label**: ${ song . label } ` ) ;
72
+ }
73
+ if ( song . genres . length ) {
74
+ description . push ( `**Genres**: ${ song . genres . join ( ', ' ) } ` ) ;
75
+ }
76
+ description . push ( `**Match**: ${ song . score } %` ) ;
77
+ if ( song . release_date ) {
78
+ description . push ( `**Release Date**: ${ song . release_date } ` ) ;
79
+ }
80
+ if ( song . timestamp ) {
81
+ description . push ( `**Timestamp**: ${ formatTime ( song . timestamp ) } ` ) ;
82
+ }
83
+ description . push ( `**Title**: ${ song . title } ` ) ;
84
+ embed . setDescription ( description . join ( '\n' ) ) ;
85
+ }
86
+
87
+ {
88
+ const urls : Array < string > = [ ] ;
89
+ if ( song . platforms . apple_music && song . platforms . apple_music . url ) {
90
+ urls . push ( Markup . url ( 'Apple Music' , song . platforms . apple_music . url ) ) ;
91
+ }
92
+ if ( song . platforms . deezer && song . platforms . deezer . url ) {
93
+ urls . push ( Markup . url ( 'Deezer' , song . platforms . deezer . url ) ) ;
94
+ }
95
+ if ( song . platforms . musicbrainz && song . platforms . musicbrainz . url ) {
96
+ urls . push ( Markup . url ( 'MusicBrainz' , song . platforms . musicbrainz . url ) ) ;
97
+ }
98
+ if ( song . platforms . spotify && song . platforms . spotify . url ) {
99
+ urls . push ( Markup . url ( 'Spotify' , song . platforms . spotify . url ) ) ;
100
+ }
101
+ if ( song . platforms . youtube && song . platforms . youtube . url ) {
102
+ urls . push ( Markup . url ( 'YouTube' , song . platforms . youtube . url ) ) ;
103
+ }
104
+ embed . addField ( 'Platform Links' , urls . join ( ', ' ) ) ;
105
+ }
106
+
107
+ {
108
+ const urls : Array < string > = [ ] ;
109
+ if ( song . platforms . apple_music && song . platforms . apple_music . preview_url ) {
110
+ urls . push ( Markup . url ( 'Apple Music' , song . platforms . apple_music . preview_url ) ) ;
111
+ }
112
+ if ( song . platforms . deezer && song . platforms . deezer . preview_url ) {
113
+ urls . push ( Markup . url ( 'Deezer' , song . platforms . deezer . preview_url ) ) ;
114
+ }
115
+ if ( song . platforms . spotify && song . platforms . spotify . preview_url ) {
116
+ urls . push ( Markup . url ( 'Spotify' , song . platforms . spotify . preview_url ) ) ;
117
+ }
118
+ if ( urls . length ) {
119
+ embed . addField ( 'Preview Links' , urls . join ( ', ' ) ) ;
120
+ }
121
+ }
122
+
123
+ return embed ;
124
+ } ,
125
+ } ) ;
126
+ return await paginator . start ( ) ;
89
127
}
90
128
91
- return editOrReply ( context , { embed} ) ;
129
+ return editOrReply ( context , {
130
+ content : 'Couldn\'t identify any songs' ,
131
+ flags : MessageFlags . EPHEMERAL ,
132
+ } ) ;
92
133
/*
93
134
const pages = [result.apple_music];
94
135
const pageLimit = activities.length || 1;
0 commit comments