@@ -15,11 +15,27 @@ class Program
1515 static void Main ( string [ ] args )
1616 {
1717 string path = args [ 0 ] ;
18- string [ ] paths = path . Split ( new char [ ] { Path . DirectorySeparatorChar } ) ;
1918
20- string artistName = paths [ paths . Length - 2 ] ;
21- string albumName = paths [ paths . Length - 1 ] ;
19+ int depth = 0 ;
20+ DirectoryInfo dir = new DirectoryInfo ( path ) ;
21+ DirectoryInfo [ ] children = dir . GetDirectories ( ) ;
22+ while ( children . Length > 0 )
23+ {
24+ depth ++ ;
25+ children = children [ 0 ] . GetDirectories ( ) ;
26+ }
2227
28+ if ( depth > 0 )
29+ {
30+ Console . WriteLine ( $ "Child directories found, detected depth is { depth } . Press Y to continue") ;
31+ if ( Console . ReadKey ( ) . Key != ConsoleKey . Y )
32+ {
33+ return ;
34+ }
35+ Console . WriteLine ( ) ;
36+ Console . WriteLine ( ) ;
37+ }
38+
2339 CredentialsAuth auth = new CredentialsAuth ( "c04cdb49f2e34e25989458ff1653e194" , "e8c464ee20d1453aa03330669f4ed2d9" ) ;
2440 Task < Token > task = auth . GetToken ( ) ;
2541 task . Wait ( ) ;
@@ -28,52 +44,78 @@ static void Main(string[] args)
2844 {
2945 TokenType = "Bearer" ,
3046 AccessToken = task . Result . AccessToken
31- } ;
47+ } ;
48+
49+ ProcessDirectory ( api , dir , depth ) ;
50+ }
51+
52+ public static void ProcessDirectory ( SpotifyWebAPI api , DirectoryInfo dir , int depth )
53+ {
54+ if ( depth != 0 )
55+ {
56+ depth -- ;
57+ foreach ( DirectoryInfo di in dir . GetDirectories ( ) )
58+ {
59+ ProcessDirectory ( api , di , depth ) ;
60+ }
61+ return ;
62+ }
63+
64+ string path = dir . FullName ;
65+ string [ ] paths = path . Split ( new char [ ] { Path . DirectorySeparatorChar } ) ;
66+
67+ string artistName = paths [ paths . Length - 2 ] ;
68+ string albumName = paths [ paths . Length - 1 ] ;
3269
3370 Console . WriteLine ( $ "Searching for { artistName } - { albumName } ") ;
3471
3572 List < KeyValuePair < FullAlbum , FullArtist > > albums = new List < KeyValuePair < FullAlbum , FullArtist > > ( ) ;
3673
3774 var search = api . SearchItems ( artistName , SpotifyAPI . Web . Enums . SearchType . Artist ) ;
38- SimpleAlbum exactMatch = null ;
75+ bool hasExactMatch = false ;
3976 foreach ( FullArtist a in search . Artists . Items )
4077 {
41- bool artistDisplayed = false ;
42-
4378 List < SimpleAlbum > searchAlbums = api . GetArtistsAlbums ( a . Id , SpotifyAPI . Web . Enums . AlbumType . Album ) . Items ;
4479 foreach ( SimpleAlbum album in searchAlbums )
4580 {
4681 if ( a . Name . Equals ( artistName , StringComparison . InvariantCultureIgnoreCase ) &&
4782 album . Name . Equals ( albumName , StringComparison . InvariantCultureIgnoreCase ) )
4883 {
49- exactMatch = album ;
84+ hasExactMatch = true ;
5085 break ;
5186 }
5287 }
5388
5489 foreach ( SimpleAlbum album in searchAlbums )
5590 {
56- if ( exactMatch != null && exactMatch != album )
57- {
58- continue ;
59- }
60- else if ( exactMatch == album )
61- {
62- Console . WriteLine ( "Exact Match" ) ;
63- }
91+ bool exactMatch =
92+ a . Name . Equals ( artistName , StringComparison . InvariantCultureIgnoreCase ) &&
93+ album . Name . Equals ( albumName , StringComparison . InvariantCultureIgnoreCase ) ;
6494
65- if ( ! artistDisplayed )
66- {
67- Console . WriteLine ( "--------------------" ) ;
68- Console . WriteLine ( $ "Name: { a . Name } ") ;
69- Console . WriteLine ( $ "Id: { a . Id } ") ;
70- Console . WriteLine ( $ "{ a . Type } { a . Uri } { a . Href } ") ;
95+ bool qualifyingMatch =
96+ a . Name . StartsWith ( artistName , StringComparison . InvariantCultureIgnoreCase ) &&
97+ album . Name . StartsWith ( albumName , StringComparison . InvariantCultureIgnoreCase ) ;
7198
72- Console . WriteLine ( " Albums:" ) ;
73- artistDisplayed = true ;
99+ if ( hasExactMatch )
100+ {
101+ if ( ! qualifyingMatch )
102+ {
103+ continue ;
104+ }
105+ else
106+ {
107+ if ( exactMatch )
108+ {
109+ Console . WriteLine ( "Exact Match" ) ;
110+ }
111+ else
112+ {
113+ Console . WriteLine ( "Qualifying Match" ) ;
114+ }
115+ }
74116 }
75117
76- Console . WriteLine ( $ "#{ albums . Count + 1 } { album . Name } - { album . ReleaseDate } - { album . Type } ") ;
118+ Console . WriteLine ( $ "#{ albums . Count + 1 } - { a . Name } - \" { album . Name } \" - { album . ReleaseDate } - { album . Type } ") ;
77119
78120 FullAlbum fullAlbum = api . GetAlbum ( album . Id ) ;
79121 albums . Add ( new KeyValuePair < FullAlbum , FullArtist > ( fullAlbum , a ) ) ;
@@ -86,7 +128,7 @@ static void Main(string[] args)
86128
87129 FullAlbum selectedAlbum = null ;
88130 FullArtist selectedArtist = null ;
89-
131+
90132 if ( albums . Count > 0 )
91133 {
92134 Console . WriteLine ( "Type album number to accept album info" ) ;
@@ -180,7 +222,10 @@ static void Main(string[] args)
180222 tagFile . Save ( ) ;
181223 }
182224
183- Console . WriteLine ( "Done" ) ;
225+ Console . WriteLine ( $ "{ artistName } - { artistName } Complete") ;
226+ Console . WriteLine ( "-------------------------------------" ) ;
227+ Console . WriteLine ( ) ;
228+ Console . Clear ( ) ;
184229 }
185230 }
186231 }
0 commit comments