-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusicpo.py
832 lines (759 loc) · 29.3 KB
/
musicpo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
# import requests
# import os
# # Replace these with your Spotify API credentials
# CLIENT_ID = '9a7cf55f463a473797efe87578dd08b2'
# CLIENT_SECRET = 'f0a5eb0dc489476abe7539474b1ca59c'
# def get_access_token(client_id, client_secret):
# auth_url = 'https://accounts.spotify.com/api/token'
# auth_response = requests.post(auth_url, {
# 'grant_type': 'client_credentials',
# 'client_id': client_id,
# 'client_secret': client_secret,
# })
# auth_response_data = auth_response.json()
# return auth_response_data['access_token']
# def download_album_cover(songs, save_dir='album_covers'):
# # Create the directory if it doesn't exist
# if not os.path.exists(save_dir):
# os.makedirs(save_dir)
# access_token = get_access_token(CLIENT_ID, CLIENT_SECRET)
# headers = {
# 'Authorization': f'Bearer {access_token}',
# }
# for artist, song in songs:
# search_query = f"{artist} {song}"
# search_url = 'https://api.spotify.com/v1/search'
# params = {
# 'q': search_query,
# 'type': 'album',
# 'limit': 1
# }
# response = requests.get(search_url, headers=headers, params=params)
# data = response.json()
# if data['albums']['items']:
# album = data['albums']['items'][0]
# album_name = album['name']
# album_cover_url = album['images'][0]['url']
# # Download the album cover
# cover_response = requests.get(album_cover_url)
# cover_filename = os.path.join(save_dir, f"{album_name}.jpg")
# with open(cover_filename, 'wb') as file:
# file.write(cover_response.content)
# print(f"Downloaded album cover for '{album_name}'")
# else:
# print(f"No album found for '{search_query}'")
# # List of songs to download covers for
# songs_list = [
# ('Ariana Grande', 'Thank U, Next'),
# ('Dua Lipa', 'Levitating'),
# ('Ed Sheeran', 'Shape of You'),
# ('Billie Eilish', 'Bad Guy'),
# ('Taylor Swift', 'Shake It Off'),
# ('Katy Perry', 'Firework'),
# ('Justin Bieber', 'Sorry'),
# ('The Weeknd', 'Blinding Lights'),
# ('Shawn Mendes', 'Stitches'),
# ('Olivia Rodrigo', 'drivers license'),
# ('Queen', 'Bohemian Rhapsody'),
# ('The Beatles', 'Hey Jude'),
# ('Nirvana', 'Smells Like Teen Spirit'),
# ('Led Zeppelin', 'Stairway to Heaven'),
# ('The Rolling Stones', 'Paint It, Black'),
# ('Coldplay', 'Fix You'),
# ('U2', 'With or Without You'),
# ('Linkin Park', 'In the End'),
# ('Foo Fighters', 'Everlong'),
# ('Green Day', 'Boulevard of Broken Dreams'),
# ('Alicia Keys', 'If I Ain\'t Got You'),
# ('Beyoncé', 'Halo'),
# ('Marvin Gaye', 'Sexual Healing'),
# ('SZA', 'Good Days'),
# ('John Legend', 'All of Me'),
# ('Whitney Houston', 'I Will Always Love You'),
# ('Frank Ocean', 'Thinkin Bout You'),
# ('Usher', 'Yeah!'),
# ('Rihanna', 'Umbrella'),
# ('Bruno Mars', 'Uptown Funk'),
# ('Drake', 'God\'s Plan'),
# ('Kendrick Lamar', 'HUMBLE.'),
# ('Kanye West', 'Stronger'),
# ('Cardi B', 'I Like It'),
# ('Post Malone', 'Circles'),
# ('Travis Scott', 'SICKO MODE'),
# ('Eminem', 'Lose Yourself'),
# ('Megan Thee Stallion', 'Savage'),
# ('Nicki Minaj', 'Super Bass'),
# ('J. Cole', 'Middle Child'),
# ('Taylor Swift', 'Love Story'),
# ('Blake Shelton', 'God\'s Country'),
# ('Kenny Chesney', 'American Kids'),
# ('Luke Bryan', 'Country Girl (Shake It for Me)'),
# ('Carrie Underwood', 'Before He Cheats'),
# ('Florida Georgia Line', 'Cruise'),
# ('Tim McGraw', 'Humble and Kind'),
# ('Johnny Cash', 'Ring of Fire'),
# ('Miranda Lambert', 'The House That Built Me'),
# ('Keith Urban', 'Blue Ain\'t Your Color'),
# ('Calvin Harris', 'Summer'),
# ('David Guetta ft. Sia', 'Titanium'),
# ('Avicii', 'Wake Me Up'),
# ('The Chainsmokers', 'Closer'),
# ('Zedd ft. Alessia Cara', 'Stay'),
# ('Marshmello ft. Bastille', 'Happier'),
# ('Dua Lipa', 'Physical'),
# ('Martin Garrix', 'Animals'),
# ('Major Lazer & DJ Snake ft. MØ', 'Lean On'),
# ('Kygo ft. Conrad Sewell', 'Firestone'),
# ('Imagine Dragons', 'Radioactive'),
# ('Tame Impala', 'The Less I Know the Better'),
# ('Vampire Weekend', 'A-Punk'),
# ('The Killers', 'Mr. Brightside'),
# ('Foster the People', 'Pumped Up Kicks'),
# ('Florence + The Machine', 'Shake It Out'),
# ('Lorde', 'Royals'),
# ('Arctic Monkeys', 'Do I Wanna Know?'),
# ('MGMT', 'Electric Feel'),
# ('The Strokes', 'Last Nite'),
# ('Bob Marley & The Wailers', 'No Woman, No Cry'),
# ('Shaggy', 'It Wasn\'t Me'),
# ('Sean Paul', 'Get Busy'),
# ('UB40', 'Red Red Wine'),
# ('Inner Circle', 'Bad Boys'),
# ('Damian Marley', 'Welcome to Jamrock'),
# ('Peter Tosh', 'Legalize It'),
# ('Tarrus Riley', 'She\'s Royal'),
# ('Beres Hammond', 'I Feel Good'),
# ('Steel Pulse', 'Your House'),
# ('Frank Sinatra', 'Fly Me to the Moon'),
# ('Billie Holiday', 'Strange Fruit'),
# ('Nina Simone', 'Feeling Good'),
# ('Ella Fitzgerald', 'Summertime'),
# ('Louis Armstrong', 'What a Wonderful World'),
# ('Etta James', 'At Last'),
# ('Ray Charles', 'Georgia on My Mind'),
# ('John Coltrane', 'Giant Steps'),
# ('B.B. King', 'The Thrill Is Gone'),
# ('Miles Davis', 'So What'),
# ('Bob Dylan', 'Blowin\' in the Wind'),
# ('Simon & Garfunkel', 'The Sound of Silence'),
# ('Fleet Foxes', 'White Winter Hymnal'),
# ('Mumford & Sons', 'Little Lion Man'),
# ('The Lumineers', 'Ho Hey'),
# ('Iron & Wine', 'Flightless Bird, American Mouth'),
# ('Johnny Cash', 'Folsom Prison Blues'),
# ('Ben Howard', 'Keep Your Head Up'),
# ('The Avett Brothers', 'I and Love and You'),
# ('First Aid Kit', 'Fireworks')
# ]
# # Download album covers for the list
# download_album_cover(songs_list)
# access_token = get_access_token('9a7cf55f463a473797efe87578dd08b2', 'f0a5eb0dc489476abe7539474b1ca59c')
# import os
# import requests
# def sanitize_filename(filename):
# # Replace characters that are not allowed in filenames
# return filename.replace('/', '_').replace(':', '-')
# def download_album_cover(album_names, save_dir='album_covers'):
# # Create the directory if it doesn't exist
# if not os.path.exists(save_dir):
# os.makedirs(save_dir)
# access_token = get_access_token('9a7cf55f463a473797efe87578dd08b2', 'f0a5eb0dc489476abe7539474b1ca59c')
# headers = {
# 'Authorization': f'Bearer {access_token}',
# }
# for album_name in album_names:
# search_url = 'https://api.spotify.com/v1/search'
# params = {
# 'q': album_name,
# 'type': 'album',
# 'limit': 1
# }
# response = requests.get(search_url, headers=headers, params=params)
# data = response.json()
# if data['albums']['items']:
# album = data['albums']['items'][0]
# album_name = album['name']
# album_cover_url = album['images'][0]['url']
# # Sanitize the album name for the filename
# sanitized_album_name = sanitize_filename(album_name)
# cover_filename = os.path.join(save_dir, f"{sanitized_album_name}.jpg")
# # Download the album cover
# cover_response = requests.get(album_cover_url)
# with open(cover_filename, 'wb') as file:
# file.write(cover_response.content)
# print(f"Downloaded album cover for '{album_name}'")
# else:
# print(f"No album found with name '{album_name}'")
# # Example usage
# songs_list = [
# # Pop
# 'Ariana Grande - Thank U, Next',
# 'Dua Lipa - Levitating',
# 'Ed Sheeran - Shape of You',
# 'Billie Eilish - Bad Guy',
# 'Taylor Swift - Shake It Off',
# 'Katy Perry - Firework',
# 'Justin Bieber - Sorry',
# 'The Weeknd - Blinding Lights',
# 'Shawn Mendes - Stitches',
# 'Olivia Rodrigo - drivers license',
# # Rock
# 'Queen - Bohemian Rhapsody',
# 'The Beatles - Hey Jude',
# 'Nirvana - Smells Like Teen Spirit',
# 'Led Zeppelin - Stairway to Heaven',
# 'The Rolling Stones - Paint It, Black',
# 'Coldplay - Fix You',
# 'U2 - With or Without You',
# 'Linkin Park - In the End',
# 'Foo Fighters - Everlong',
# 'Green Day - Boulevard of Broken Dreams',
# # R&B/Soul
# 'Alicia Keys - If I Ain\'t Got You',
# 'Beyoncé - Halo',
# 'Marvin Gaye - Sexual Healing',
# 'SZA - Good Days',
# 'John Legend - All of Me',
# 'Whitney Houston - I Will Always Love You',
# 'Frank Ocean - Thinkin Bout You',
# 'Usher - Yeah!',
# 'Rihanna - Umbrella',
# 'Bruno Mars - Uptown Funk',
# # Hip-Hop/Rap
# 'Drake - God\'s Plan',
# 'Kendrick Lamar - HUMBLE.',
# 'Kanye West - Stronger',
# 'Cardi B - I Like It',
# 'Post Malone - Circles',
# 'Travis Scott - SICKO MODE',
# 'Eminem - Lose Yourself',
# 'Megan Thee Stallion - Savage',
# 'Nicki Minaj - Super Bass',
# 'J. Cole - Middle Child',
# # Country
# 'Taylor Swift - Love Story',
# 'Blake Shelton - God\'s Country',
# 'Kenny Chesney - American Kids',
# 'Luke Bryan - Country Girl (Shake It for Me)',
# 'Carrie Underwood - Before He Cheats',
# 'Florida Georgia Line - Cruise',
# 'Tim McGraw - Humble and Kind',
# 'Johnny Cash - Ring of Fire',
# 'Miranda Lambert - The House That Built Me',
# 'Keith Urban - Blue Ain\'t Your Color',
# # Dance/Electronic
# 'Calvin Harris - Summer',
# 'David Guetta ft. Sia - Titanium',
# 'Avicii - Wake Me Up',
# 'The Chainsmokers - Closer',
# 'Zedd ft. Alessia Cara - Stay',
# 'Marshmello ft. Bastille - Happier',
# 'Dua Lipa - Physical',
# 'Martin Garrix - Animals',
# 'Major Lazer & DJ Snake ft. MØ - Lean On',
# 'Kygo ft. Conrad Sewell - Firestone',
# # Indie/Alternative
# 'Imagine Dragons - Radioactive',
# 'Tame Impala - The Less I Know the Better',
# 'Vampire Weekend - A-Punk',
# 'The Killers - Mr. Brightside',
# 'Foster the People - Pumped Up Kicks',
# 'Florence + The Machine - Shake It Out',
# 'Lorde - Royals',
# 'Arctic Monkeys - Do I Wanna Know?',
# 'MGMT - Electric Feel',
# 'The Strokes - Last Nite',
# # Reggae
# 'Bob Marley & The Wailers - No Woman, No Cry',
# 'Shaggy - It Wasn\'t Me',
# 'Sean Paul - Get Busy',
# 'UB40 - Red Red Wine',
# 'Inner Circle - Bad Boys',
# 'Damian Marley - Welcome to Jamrock',
# 'Peter Tosh - Legalize It',
# 'Tarrus Riley - She\'s Royal',
# 'Beres Hammond - I Feel Good',
# 'Steel Pulse - Your House',
# # Jazz/Blues
# 'Frank Sinatra - Fly Me to the Moon',
# 'Billie Holiday - Strange Fruit',
# 'Nina Simone - Feeling Good',
# 'Ella Fitzgerald - Summertime',
# 'Louis Armstrong - What a Wonderful World',
# 'Etta James - At Last',
# 'Ray Charles - Georgia on My Mind',
# 'John Coltrane - Giant Steps',
# 'B.B. King - The Thrill Is Gone',
# 'Miles Davis - So What',
# # Folk
# 'Bob Dylan - Blowin\' in the Wind',
# 'Simon & Garfunkel - The Sound of Silence',
# 'Fleet Foxes - White Winter Hymnal',
# 'Mumford & Sons - Little Lion Man',
# 'The Lumineers - Ho Hey',
# 'Iron & Wine - Flightless Bird, American Mouth',
# 'Johnny Cash - Folsom Prison Blues',
# 'Ben Howard - Keep Your Head Up',
# 'The Avett Brothers - I and Love and You',
# 'First Aid Kit - Fireworks'
# ]
# download_album_cover(songs_list)
# import os
# import requests
# def sanitize_filename(filename):
# return filename.replace('/', '_').replace(':', '-')
# def download_album_cover(album_names, save_dir='album_covers'):
# if not os.path.exists(save_dir):
# os.makedirs(save_dir)
# access_token = get_access_token('9a7cf55f463a473797efe87578dd08b2', 'f0a5eb0dc489476abe7539474b1ca59c')
# headers = {
# 'Authorization': f'Bearer {access_token}',
# }
# for album_name in album_names:
# try:
# search_url = 'https://api.spotify.com/v1/search'
# params = {
# 'q': album_name,
# 'type': 'album',
# 'limit': 1
# }
# response = requests.get(search_url, headers=headers, params=params)
# response.raise_for_status() # Raises an HTTPError for bad responses
# data = response.json()
# if data['albums']['items']:
# album = data['albums']['items'][0]
# album_name = album['name']
# album_cover_url = album['images'][0]['url']
# sanitized_album_name = sanitize_filename(album_name)
# cover_filename = os.path.join(save_dir, f"{sanitized_album_name}.jpg")
# cover_response = requests.get(album_cover_url)
# cover_response.raise_for_status()
# with open(cover_filename, 'wb') as file:
# file.write(cover_response.content)
# print(f"Downloaded album cover for '{album_name}'")
# else:
# print(f"No album found with name '{album_name}'")
# except requests.exceptions.RequestException as e:
# print(f"An error occurred: {e}")
# # Example usage
# songs_list = [
# # Pop
# 'Ariana Grande - Thank U, Next',
# 'Dua Lipa - Levitating',
# 'Ed Sheeran - Shape of You',
# 'Billie Eilish - Bad Guy',
# 'Taylor Swift - Shake It Off',
# 'Katy Perry - Firework',
# 'Justin Bieber - Sorry',
# 'The Weeknd - Blinding Lights',
# 'Shawn Mendes - Stitches',
# 'Olivia Rodrigo - drivers license',
# # Rock
# 'Queen - Bohemian Rhapsody',
# 'The Beatles - Hey Jude',
# 'Nirvana - Smells Like Teen Spirit',
# 'Led Zeppelin - Stairway to Heaven',
# 'The Rolling Stones - Paint It, Black',
# 'Coldplay - Fix You',
# 'U2 - With or Without You',
# 'Linkin Park - In the End',
# 'Foo Fighters - Everlong',
# 'Green Day - Boulevard of Broken Dreams',
# # R&B/Soul
# 'Alicia Keys - If I Ain\'t Got You',
# 'Beyoncé - Halo',
# 'Marvin Gaye - Sexual Healing',
# 'SZA - Good Days',
# 'John Legend - All of Me',
# 'Whitney Houston - I Will Always Love You',
# 'Frank Ocean - Thinkin Bout You',
# 'Usher - Yeah!',
# 'Rihanna - Umbrella',
# 'Bruno Mars - Uptown Funk',
# # Hip-Hop/Rap
# 'Drake - God\'s Plan',
# 'Kendrick Lamar - HUMBLE.',
# 'Kanye West - Stronger',
# 'Cardi B - I Like It',
# 'Post Malone - Circles',
# 'Travis Scott - SICKO MODE',
# 'Eminem - Lose Yourself',
# 'Megan Thee Stallion - Savage',
# 'Nicki Minaj - Super Bass',
# 'J. Cole - Middle Child',
# # Country
# 'Taylor Swift - Love Story',
# 'Blake Shelton - God\'s Country',
# 'Kenny Chesney - American Kids',
# 'Luke Bryan - Country Girl (Shake It for Me)',
# 'Carrie Underwood - Before He Cheats',
# 'Florida Georgia Line - Cruise',
# 'Tim McGraw - Humble and Kind',
# 'Johnny Cash - Ring of Fire',
# 'Miranda Lambert - The House That Built Me',
# 'Keith Urban - Blue Ain\'t Your Color',
# # Dance/Electronic
# 'Calvin Harris - Summer',
# 'David Guetta ft. Sia - Titanium',
# 'Avicii - Wake Me Up',
# 'The Chainsmokers - Closer',
# 'Zedd ft. Alessia Cara - Stay',
# 'Marshmello ft. Bastille - Happier',
# 'Dua Lipa - Physical',
# 'Martin Garrix - Animals',
# 'Major Lazer & DJ Snake ft. MØ - Lean On',
# 'Kygo ft. Conrad Sewell - Firestone',
# # Indie/Alternative
# 'Imagine Dragons - Radioactive',
# 'Tame Impala - The Less I Know the Better',
# 'Vampire Weekend - A-Punk',
# 'The Killers - Mr. Brightside',
# 'Foster the People - Pumped Up Kicks',
# 'Florence + The Machine - Shake It Out',
# 'Lorde - Royals',
# 'Arctic Monkeys - Do I Wanna Know?',
# 'MGMT - Electric Feel',
# 'The Strokes - Last Nite',
# # Reggae
# 'Bob Marley & The Wailers - No Woman, No Cry',
# 'Shaggy - It Wasn\'t Me',
# 'Sean Paul - Get Busy',
# 'UB40 - Red Red Wine',
# 'Inner Circle - Bad Boys',
# 'Damian Marley - Welcome to Jamrock',
# 'Peter Tosh - Legalize It',
# 'Tarrus Riley - She\'s Royal',
# 'Beres Hammond - I Feel Good',
# 'Steel Pulse - Your House',
# # Jazz/Blues
# 'Frank Sinatra - Fly Me to the Moon',
# 'Billie Holiday - Strange Fruit',
# 'Nina Simone - Feeling Good',
# 'Ella Fitzgerald - Summertime',
# 'Louis Armstrong - What a Wonderful World',
# 'Etta James - At Last',
# 'Ray Charles - Georgia on My Mind',
# 'John Coltrane - Giant Steps',
# 'B.B. King - The Thrill Is Gone',
# 'Miles Davis - So What',
# # Folk
# 'Bob Dylan - Blowin\' in the Wind',
# 'Simon & Garfunkel - The Sound of Silence',
# 'Fleet Foxes - White Winter Hymnal',
# 'Mumford & Sons - Little Lion Man',
# 'The Lumineers - Ho Hey',
# 'Iron & Wine - Flightless Bird, American Mouth',
# 'Johnny Cash - Folsom Prison Blues',
# 'Ben Howard - Keep Your Head Up',
# 'The Avett Brothers - I and Love and You',
# 'First Aid Kit - Fireworks'
# ]
# download_album_cover(songs_list)
# import os
# import requests
# from requests.auth import HTTPBasicAuth
# def get_access_token(client_id, client_secret):
# auth_url = 'https://accounts.spotify.com/api/token'
# auth_response = requests.post(auth_url, {
# 'grant_type': 'client_credentials'
# }, auth=HTTPBasicAuth(client_id, client_secret))
# auth_response_data = auth_response.json()
# return auth_response_data['access_token']
# def sanitize_filename(filename):
# return filename.replace('/', '_').replace(':', '-')
# def download_album_cover(album_names, save_dir='album_covers'):
# if not os.path.exists(save_dir):
# os.makedirs(save_dir)
# # Replace these with your actual client ID and secret
# client_id = '9a7cf55f463a473797efe87578dd08b2'
# client_secret = 'f0a5eb0dc489476abe7539474b1ca59c'
# access_token = get_access_token(client_id, client_secret)
# headers = {
# 'Authorization': f'Bearer {access_token}',
# }
# for album_name in album_names:
# try:
# search_url = 'https://api.spotify.com/v1/search'
# params = {
# 'q': album_name,
# 'type': 'album',
# 'limit': 1
# }
# response = requests.get(search_url, headers=headers, params=params)
# response.raise_for_status()
# data = response.json()
# if data['albums']['items']:
# album = data['albums']['items'][0]
# album_name = album['name']
# album_cover_url = album['images'][0]['url']
# sanitized_album_name = sanitize_filename(album_name)
# cover_filename = os.path.join(save_dir, f"{sanitized_album_name}.jpg")
# cover_response = requests.get(album_cover_url)
# cover_response.raise_for_status()
# with open(cover_filename, 'wb') as file:
# file.write(cover_response.content)
# print(f"Downloaded album cover for '{album_name}'")
# else:
# print(f"No album found with name '{album_name}'")
# except requests.exceptions.RequestException as e:
# print(f"An error occurred: {e}")
# # Example usage
# songs_list = [
# # Pop
# 'Ariana Grande - Thank U, Next',
# 'Dua Lipa - Levitating',
# 'Ed Sheeran - Shape of You',
# 'Billie Eilish - Bad Guy',
# 'Taylor Swift - Shake It Off',
# 'Katy Perry - Firework',
# 'Justin Bieber - Sorry',
# 'The Weeknd - Blinding Lights',
# 'Shawn Mendes - Stitches',
# 'Olivia Rodrigo - drivers license',
# # Rock
# 'Queen - Bohemian Rhapsody',
# 'The Beatles - Hey Jude',
# 'Nirvana - Smells Like Teen Spirit',
# 'Led Zeppelin - Stairway to Heaven',
# 'The Rolling Stones - Paint It, Black',
# 'Coldplay - Fix You',
# 'U2 - With or Without You',
# 'Linkin Park - In the End',
# 'Foo Fighters - Everlong',
# 'Green Day - Boulevard of Broken Dreams',
# # R&B/Soul
# 'Alicia Keys - If I Ain\'t Got You',
# 'Beyoncé - Halo',
# 'Marvin Gaye - Sexual Healing',
# 'SZA - Good Days',
# 'John Legend - All of Me',
# 'Whitney Houston - I Will Always Love You',
# 'Frank Ocean - Thinkin Bout You',
# 'Usher - Yeah!',
# 'Rihanna - Umbrella',
# 'Bruno Mars - Uptown Funk',
# # Hip-Hop/Rap
# 'Drake - God\'s Plan',
# 'Kendrick Lamar - HUMBLE.',
# 'Kanye West - Stronger',
# 'Cardi B - I Like It',
# 'Post Malone - Circles',
# 'Travis Scott - SICKO MODE',
# 'Eminem - Lose Yourself',
# 'Megan Thee Stallion - Savage',
# 'Nicki Minaj - Super Bass',
# 'J. Cole - Middle Child',
# # Country
# 'Taylor Swift - Love Story',
# 'Blake Shelton - God\'s Country',
# 'Kenny Chesney - American Kids',
# 'Luke Bryan - Country Girl (Shake It for Me)',
# 'Carrie Underwood - Before He Cheats',
# 'Florida Georgia Line - Cruise',
# 'Tim McGraw - Humble and Kind',
# 'Johnny Cash - Ring of Fire',
# 'Miranda Lambert - The House That Built Me',
# 'Keith Urban - Blue Ain\'t Your Color',
# # Dance/Electronic
# 'Calvin Harris - Summer',
# 'David Guetta ft. Sia - Titanium',
# 'Avicii - Wake Me Up',
# 'The Chainsmokers - Closer',
# 'Zedd ft. Alessia Cara - Stay',
# 'Marshmello ft. Bastille - Happier',
# 'Dua Lipa - Physical',
# 'Martin Garrix - Animals',
# 'Major Lazer & DJ Snake ft. MØ - Lean On',
# 'Kygo ft. Conrad Sewell - Firestone',
# # Indie/Alternative
# 'Imagine Dragons - Radioactive',
# 'Tame Impala - The Less I Know the Better',
# 'Vampire Weekend - A-Punk',
# 'The Killers - Mr. Brightside',
# 'Foster the People - Pumped Up Kicks',
# 'Florence + The Machine - Shake It Out',
# 'Lorde - Royals',
# 'Arctic Monkeys - Do I Wanna Know?',
# 'MGMT - Electric Feel',
# 'The Strokes - Last Nite',
# # Reggae
# 'Bob Marley & The Wailers - No Woman, No Cry',
# 'Shaggy - It Wasn\'t Me',
# 'Sean Paul - Get Busy',
# 'UB40 - Red Red Wine',
# 'Inner Circle - Bad Boys',
# 'Damian Marley - Welcome to Jamrock',
# 'Peter Tosh - Legalize It',
# 'Tarrus Riley - She\'s Royal',
# 'Beres Hammond - I Feel Good',
# 'Steel Pulse - Your House',
# # Jazz/Blues
# 'Frank Sinatra - Fly Me to the Moon',
# 'Billie Holiday - Strange Fruit',
# 'Nina Simone - Feeling Good',
# 'Ella Fitzgerald - Summertime',
# 'Louis Armstrong - What a Wonderful World',
# 'Etta James - At Last',
# 'Ray Charles - Georgia on My Mind',
# 'John Coltrane - Giant Steps',
# 'B.B. King - The Thrill Is Gone',
# 'Miles Davis - So What',
# # Folk
# 'Bob Dylan - Blowin\' in the Wind',
# 'Simon & Garfunkel - The Sound of Silence',
# 'Fleet Foxes - White Winter Hymnal',
# 'Mumford & Sons - Little Lion Man',
# 'The Lumineers - Ho Hey',
# 'Iron & Wine - Flightless Bird, American Mouth',
# 'Johnny Cash - Folsom Prison Blues',
# 'Ben Howard - Keep Your Head Up',
# 'The Avett Brothers - I and Love and You',
# 'First Aid Kit - Fireworks'
# ]
# download_album_cover(songs_list)
import os
import requests
from requests.auth import HTTPBasicAuth
def get_access_token(client_id, client_secret):
auth_url = 'https://accounts.spotify.com/api/token'
auth_response = requests.post(auth_url, {
'grant_type': 'client_credentials'
}, auth=HTTPBasicAuth(client_id, client_secret))
auth_response_data = auth_response.json()
return auth_response_data['access_token']
def sanitize_filename(filename):
return filename.replace('/', '_').replace(':', '-')
def download_album_cover(album_names, save_dir='album_covers'):
if not os.path.exists(save_dir):
os.makedirs(save_dir)
# Replace these with your actual client ID and secret
client_id = '9a7cf55f463a473797efe87578dd08b2'
client_secret = 'f0a5eb0dc489476abe7539474b1ca59c'
access_token = get_access_token(client_id, client_secret)
headers = {
'Authorization': f'Bearer {access_token}',
}
for album_name in album_names:
try:
search_url = 'https://api.spotify.com/v1/search'
params = {
'q': album_name,
'type': 'album',
'limit': 1
}
response = requests.get(search_url, headers=headers, params=params)
response.raise_for_status() # Raises an HTTPError for bad responses
data = response.json()
if data['albums']['items']:
album = data['albums']['items'][0]
album_name = album['name']
album_cover_url = album['images'][0]['url']
sanitized_album_name = sanitize_filename(album_name)
cover_filename = os.path.join(save_dir, f"{sanitized_album_name}.jpg")
cover_response = requests.get(album_cover_url)
cover_response.raise_for_status()
with open(cover_filename, 'wb') as file:
file.write(cover_response.content)
print(f"Downloaded album cover for '{album_name}'")
else:
print(f"No album found with name '{album_name}'")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
# Example usage
songs_list = [
'Pehli Nazar Mein - Atif Aslam',
'Tum Hi Ho - Arijit Singh',
'Tum Jo Aaye - Rahat Fateh Ali Khan',
'Channa Mereya - Arijit Singh',
'Dil Diyan Gallan - Atif Aslam',
'Tum Mile - Neeraj Shridhar',
'Sun Saathiya - Priya Saraiya, Divya Kumar',
'Jeene Laga Hoon - Atif Aslam',
'Raabta - Arijit Singh',
'Ae Mere Humsafar - Udit Narayan, Alka Yagnik',
'Tum Tak - Arijit Singh',
'Pee Loon - Mohit Chauhan',
'Agar Tum Saath Ho - Alka Yagnik, Arijit Singh',
'Raaz Aankhein Teri - Kunal Ganjawala',
'Dilwale Dulhania Le Jayenge (title track) - Lata Mangeshkar, Udit Narayan',
'Tumse Hi - Mohit Chauhan',
'Tum Se Hi - Shreya Ghoshal, Sonu Nigam',
'Hasi - Ami Mishra',
'Janam Janam - Arijit Singh, Antara Mitra',
'Badtameez Dil - Benny Dayal',
'Kar Gayi Chull - Neha Kakkar, Badshah',
'Gallan Goodiyan - Various Artists',
'Dil Dhadakne Do - Priyanka Chopra, Farhan Akhtar',
'Tamma Tamma Again - Badshah, Neha Kakkar',
'Desi Girl - Shankar Mahadevan, Sunidhi Chauhan',
'Lungi Dance - Yo Yo Honey Singh',
'Kala Chashma - Amar Arshi, Neha Kakkar',
'Sheila Ki Jawani - Sunidhi Chauhan, Vishal-Shekhar',
'Chikni Chameli - Shreya Ghoshal',
'Zinda - Siddharth Mahadevan',
'Teri Yaad - Anirudh Bhola',
'Pichle Saat Dinon Mein - Kailasa',
'Bande Hain Hum Uske - Kailasa',
'Dhoom Again - Kunal Ganjawala, Sonu Nigam',
'Rock On!! - Jim, Arun, and Mohit',
'Phir Se Udd Chala - Mohit Chauhan',
'Chak De India - Sukhwinder Singh',
'Woh Lamhe - Jal',
'Saudagar Sauda Kar - Udit Narayan',
'Tajdar-e-Haram - Atif Aslam',
'Kun Faya Kun - A.R. Rahman, Javed Ali, Mohit Chauhan',
'Allah Ke Bande - Kailasa',
'Arziyan - Javed Ali, Kailasa',
'Piya Haji Ali - A. R. Rahman, Sadhana Sargam',
'Mast Kalandar - Kailasa',
'Tera Ban Jaunga - Akhil Sachdeva, Mansheel Gujral',
'Saanson Ko - Kunal Ganjawala',
'Mast Mast - Ustad Nusrat Fateh Ali Khan',
'Noori - Rabbi Shergill',
'Patakha Guddi - Nooran Sisters',
'Chaiyya Chaiyya - Sukhwinder Singh, Sapna Awasthi',
'Madhaniya - Neha Bhasin',
'Desi Girl - Sunidhi Chauhan',
'Chunar - Arijit Singh',
'Teri Deewani - Kailasa',
'Meri Jaan - Neeraj Shridhar',
'Kaun Tujhe - Palak Muchhal',
'Dil Dhadakne Do - Zindagi Na Milegi Dobara',
'Gallan Goodiyan - Various Artists',
'Mushkil Hai - A.R. Rahman, Arjun Chandy',
'Kailasa - Kailasa',
'Meri Kahani - Shankar Ehsaan Loy',
'Ankh Marey - Neha Kakkar',
'Yeh Dooriyan - Mohit Chauhan',
'Yaari Hai - Tony Kakkar, Neha Kakkar',
'Tera Yaar Hoon Mai - Arijit Singh',
'Suno Na Sangemarmar - Arijit Singh',
'Tu Hi Hai - Aditya Rao, Amaal Mallik',
'Dil Beparvah - Zayn',
'Alvida - Shafqat Amanat Ali',
'Sajda - Rahat Fateh Ali Khan, Shankar Mahadevan',
'Laaga Chunri Mein Daag - Shreya Ghoshal',
'Keh Do Ke Tum - Shaan',
'Pardesi Pardesi - Udit Narayan',
'Jai Jai Shivshankar - Vishal Dadlani, Benny Dayal',
'Bairagi - Arijit Singh',
'Koi Kahe Kehta Rahe - Shankar Mahadevan',
'Ishq Sufiyana - Kailasa',
'Madhurima - Kailasa',
'Tujhse Naraz Nahi Zindagi - Lata Mangeshkar',
'Zindagi Kuch Toh - Atif Aslam',
'Kabira - Arijit Singh',
'Ae Dil Hai Mushkil - Arijit Singh',
'Sun Raha Hai - Shreya Ghoshal, Ankit Tiwari',
'Dil Ke Paas - Kishore Kumar',
'Munni Badnam Hui - Mamta Sharma, Aishwarya',
'Dance Basanti - Asha Bhosle, Kunal Ganjawala',
'Pappu Can\'t Dance - Mika Singh',
'Chhote Chhote Peg - Neha Kakkar, Mika Singh',
'Tunak Tunak Tun - Daler Mehndi',
'Aap Jaisa Koi - Udit Narayan, Sadhana Sargam',
'Anarkali Disco Chali - Mamta Sharma',
'Dilliwali Girlfriend - Arijit Singh, Neeti Mohan',
'Bachna Ae Haseeno - Neeraj Shridhar, Kunal Ganjawala'
]
download_album_cover(songs_list)