mckabue commited on
Commit
2f4074b
·
1 Parent(s): 8d9ee35

Add CSV parsing utility and test route; update UI for loading test playlist

Browse files
Files changed (3) hide show
  1. app.py +20 -4
  2. index.html +45 -21
  3. shazamlibrary.test.csv +223 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  """Shazam Playlist to Youtube Playlist"""
2
 
 
3
  from typing import Optional
4
  import logging
5
  import pandas as pd
@@ -37,13 +38,28 @@ def parse_csv():
37
  try:
38
  file = request.files['file']
39
  # Process the uploaded file
40
- shazamlibrary_df = pd.read_csv(file, header=1)
41
- shazamlibrary_df = shazamlibrary_df.drop_duplicates(subset=['TrackKey'])[['Title', 'Artist']]
42
- return shazamlibrary_df.to_json(orient="records")
 
 
 
 
 
 
 
 
43
  except Exception as e:
44
  return str(e)
45
 
46
  def get_youtube_song(title: str, artist: str) -> Optional[YouTube]:
47
  """Searches for a YouTube video based on the given title and artist"""
48
  search_result = Search(f'{title} by {artist}')
49
- return search_result.results[0] if search_result.results else None
 
 
 
 
 
 
 
 
1
  """Shazam Playlist to Youtube Playlist"""
2
 
3
+ from pathlib import Path
4
  from typing import Optional
5
  import logging
6
  import pandas as pd
 
38
  try:
39
  file = request.files['file']
40
  # Process the uploaded file
41
+ return parse_csv_util(pd.read_csv(file, header=1))
42
+ except Exception as e:
43
+ return str(e)
44
+
45
+ @app.route('/parse_csv_test', methods=['GET'])
46
+ def parse_csv_test():
47
+ """Route handler for parsing the test CSV file"""
48
+ try:
49
+ # Construct the path to the CSV file
50
+ csv_path = Path(__file__).parent / 'shazamlibrary.test.csv'
51
+ return parse_csv_util(pd.read_csv(csv_path, header=1))
52
  except Exception as e:
53
  return str(e)
54
 
55
  def get_youtube_song(title: str, artist: str) -> Optional[YouTube]:
56
  """Searches for a YouTube video based on the given title and artist"""
57
  search_result = Search(f'{title} by {artist}')
58
+ return search_result.results[0] if search_result.results else None
59
+
60
+ def parse_csv_util(shazamlibrary_df):
61
+ try:
62
+ shazamlibrary_df = shazamlibrary_df.drop_duplicates(subset=['TrackKey'])[['Title', 'Artist']]
63
+ return shazamlibrary_df.to_json(orient="records")
64
+ except Exception as e:
65
+ return str(e)
index.html CHANGED
@@ -46,7 +46,13 @@
46
  </div>
47
  </div>
48
 
49
- <div class="row mt-5 justify-content-center">
 
 
 
 
 
 
50
  <div class="col-md-8">
51
  <div class="object-fit-contain border rounded ratio ratio-16x9">
52
  <div class="youtube-player"></div>
@@ -67,6 +73,17 @@
67
  let videoIndex = -1;
68
  let youtubePlayer;
69
 
 
 
 
 
 
 
 
 
 
 
 
70
  uploaForm.addEventListener('input', e => {
71
  e.preventDefault();
72
  if (e.target.files.length == 0) {
@@ -116,30 +133,37 @@
116
  callback(video_id);
117
  resetCurrentPlayingBackground();
118
  }
119
- async function parseCsv(file, playlistTable) {
120
  try {
121
- const formData = new FormData();
122
- formData.append('file', file);
123
- songsPlaylist = await (await fetch('/parse_csv', { method: 'POST', body: formData })).json();
124
-
125
  tableBody = songsPlaylist.map((i, index) => `
126
- <tr data-index="${index}">
127
- <th>${index + 1}</th>
128
- <th>${i.Title}</th>
129
- <th>${i.Artist}</th>
130
- </tr>`
131
  ).join('')
132
  playlistTable.innerHTML = `
133
- <table class="table table-striped table-hover table-bordered rounded">
134
- <thead>
135
- <tr>
136
- <th>#</th>
137
- <th>Title</th>
138
- <th>Artist</th>
139
- </tr>
140
- </thead>
141
- <tbody>${tableBody}</tbody>
142
- </table>`
 
 
 
 
 
 
 
 
 
 
143
  } catch (error) {
144
  playlistTable.innerHTML = error;
145
  }
 
46
  </div>
47
  </div>
48
 
49
+ <div class="d-flex mt-2 justify-content-center">
50
+ <a id="load-test-playlist" class="btn btn-secondary btn-sm fst-italic">
51
+ click here to load test playlist
52
+ </a>
53
+ </div>
54
+
55
+ <div class="row mt-3 justify-content-center">
56
  <div class="col-md-8">
57
  <div class="object-fit-contain border rounded ratio ratio-16x9">
58
  <div class="youtube-player"></div>
 
73
  let videoIndex = -1;
74
  let youtubePlayer;
75
 
76
+ document.querySelector('#load-test-playlist').addEventListener('click', async e => {
77
+ try {
78
+ e.preventDefault();
79
+
80
+ const playlist = await(await fetch('/parse_csv_test')).json();
81
+ generateTable(playlist)
82
+ } catch (error) {
83
+ playlistTable.innerHTML = error;
84
+ }
85
+ });
86
+
87
  uploaForm.addEventListener('input', e => {
88
  e.preventDefault();
89
  if (e.target.files.length == 0) {
 
133
  callback(video_id);
134
  resetCurrentPlayingBackground();
135
  }
136
+ function generateTable(playlist) {
137
  try {
138
+ songsPlaylist = playlist
 
 
 
139
  tableBody = songsPlaylist.map((i, index) => `
140
+ <tr data-index="${index}">
141
+ <th>${index + 1}</th>
142
+ <th>${i.Title}</th>
143
+ <th>${i.Artist}</th>
144
+ </tr>`
145
  ).join('')
146
  playlistTable.innerHTML = `
147
+ <table class="table table-striped table-hover table-bordered rounded">
148
+ <thead>
149
+ <tr>
150
+ <th>#</th>
151
+ <th>Title</th>
152
+ <th>Artist</th>
153
+ </tr>
154
+ </thead>
155
+ <tbody>${tableBody}</tbody>
156
+ </table>`
157
+ } catch (error) {
158
+ playlistTable.innerHTML = error;
159
+ }
160
+ }
161
+ async function parseCsv(file, playlistTable) {
162
+ try {
163
+ const formData = new FormData();
164
+ formData.append('file', file);
165
+ const playlist = await (await fetch('/parse_csv', { method: 'POST', body: formData })).json();
166
+ generateTable(playlist)
167
  } catch (error) {
168
  playlistTable.innerHTML = error;
169
  }
shazamlibrary.test.csv ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Shazam Library,,
2
+ Title,Artist,TrackKey
3
+ Amor (feat. Jovial),Otile Brown,24052353291
4
+ Sisi Sote,Bony Mwaitege,18299634097
5
+ Forgive Our Trespasses (feat. Demola),Nandipha808 & Ceeka RSA,33631803576
6
+ The Zeitgeist,Mason Newell Comtois,41552479184
7
+ Bad Habits,Ed Sheeran,33344562233
8
+ 这不是你梦寐以求的长大吗,浪帝,30320612771
9
+ Capable God,Judikay,36066896554
10
+ Row Row Stream Song,CoComelon,35095842479
11
+ Ocean Depth,Veaceslav Draganov,11740399332
12
+ Until I Found You (Em Beihold Version),Stephen Sanchez & Em Beihold,17455286080
13
+ 愿你,黄静美,27003268416
14
+ Friendships,Pascal Letoublon,49979740786
15
+ You Have Done Me Well (Swahili),solomon lange,49626758377
16
+ Stay With Me,CHANYEOL & Punch,13877632448
17
+ Love Is Strong,Cospe,53072807771
18
+ One More I Love You,Alex Warren,27242917389
19
+ He Lives in You (Drill Remix),Odyssybeatz,23849169765
20
+ One of My Biggest Fears,Kevin Hart,42544325553
21
+ Star Wars (Epic Main Theme),Samuel Kim,14534555026
22
+ Dream It Possible,Delacey,27613435955
23
+ Around My Dream,Silver Pozzoli,32044104015
24
+ The End,Earl Grant,21127776250
25
+ Precious,AlutaHits,33252900788
26
+ Bring Me Back (feat. Claire Ridgely) [Sped Up],Miles Away,36823577498
27
+ Home (feat. Efe Oraka),"Dwin, The Stoic & Rhaffy",41153141125
28
+ Into Your Arms,MGX Nation,3322665247
29
+ Eastside,"benny blanco, Halsey & Khalid",11417031963
30
+ Oy U Luzi Chervona Kalyna (feat. BoomBox) [Army Remix],The Kiffness,16126862653
31
+ A Real Hero,College & Electric Youth,9435709337
32
+ Tunaanza Na Mungu,The Mafik,50448289874
33
+ Flames (Extended),David Guetta & Sia,47800316064
34
+ "If You Need to, Keep Time on Me",Fleet Foxes,31790591922
35
+ History of Time,Ender Güney,24177408037
36
+ 恋人心,Wei Xin Yu,22137123475
37
+ Ven Ven,Lotus Beatz,38030414237
38
+ Apollo (feat. Amba Shepherd),Hardwell,22765409664
39
+ With You In the Morning (8D Audio),Carl Storm,7532187359
40
+ Maine Royaan (Lofi Remix),Tanveer Evan,7820717653
41
+ When the Sunrise (feat. סיון טלמור),Yehezkel Raz,6297577351
42
+ Whenever,LiQWYD,53394978353
43
+ Vamos Contar Mentiras,Músicas Infantis,22543588743
44
+ Runaway,"R3HAB, Sigala & JP Cooper",45077634910
45
+ Best Choice,Md Moinul Hasan,14887201866
46
+ Another Love,Tom Odell,53011690604
47
+ Kesho,Bridget Blue,24062615006
48
+ Manike Mage Hithe,"Chamath Sangeeth, Yohani & Satheeshan",37712782583
49
+ "Don't Think Twice, It's All Right",Melanie,47701073881
50
+ Oil in my Head,Black Sherif,53595275163
51
+ Self Control,Yiquan,32220059160
52
+ Blue,Blood Harmony,11070370192
53
+ Mtafute,Janet Otieno,796449436
54
+ Hold Me (feat. Liam Thomas),Michael FK,51485772766
55
+ Thanks & Praise,Gappy Ranks,22709756101
56
+ A Hidden Life,"James Newton Howard, James Ehnes & Andrew Armstrong",52964476276
57
+ Prism Of Life,Enigma,5998869716
58
+ Sleepless,Crush Toast,12716623297
59
+ Omo Ope (feat. Olamide),Asake,33793869066
60
+ Cruise,Silas Davis,40364691100
61
+ This Land Is Your Land,Woody Guthrie,10570612980
62
+ Drogba (Joanna),Afro B,3721872719
63
+ Kitoko (feat. L Rice),Avril,31491672135
64
+ L'amour Toujours,Gigi D'Agostino,49507448750
65
+ Somewhere Only We Know (feat. rhianne),Gustixa,26472675082
66
+ The Night We Met,Lord Huron,1559791585
67
+ Synthesize to Escape,Stefanowitz,14900314102
68
+ Make Your Own Kind of Music,Cass Elliot,38165143930
69
+ Shining Tomorrow,Priyanka Panjiyar,13092995740
70
+ Give Me a Call,Mitch,45533091849
71
+ Nakupenda,Jay Melody,12439347463
72
+ Nifungue,Florence Andenyi,39425493141
73
+ Mortals,Warriyo,36893595740
74
+ The Nights,fenekot,16733365697
75
+ "Til You're Home (From A Man Called Otto"" Soundtrack)""",Rita Wilson & Sebastián Yatra,11929710927
76
+ Vaida,Harry Richie,8903544706
77
+ Music in Twelve Parts: Part 9,Philip Glass & The Philip Glass Ensemble,30520106080
78
+ One For One (feat. Mathew Gold),Household Funk & Chris Sen,9339786513
79
+ Capitals of Europe: Nordic Region,Katrina Holland,3737072244
80
+ Close To the Sun,TheFatRat & Anjulie,47624531087
81
+ Pizza,Oxydz,48663076631
82
+ Flames,David Guetta & Sia,28320071477
83
+ Morning After Dark (feat. Nelly Furtado & SoShy),Timbaland,52290209474
84
+ Where Are You,Otnicka,34249888400
85
+ Mary On A Cross (slowed + reverb),Ghost,18992396291
86
+ At Night,Ridney,38970254671
87
+ Psalm 24 (The King of Glory),Keith & Kristyn Getty,11262652232
88
+ Rush,Ayra Starr,10817892576
89
+ Ain't Nobody (Loves Me Better) [Acoustic],Jasmine Thompson,24716306208
90
+ Be Thou My Vision,Lifebreakthrough,21680143908
91
+ Levan Polkka Zeki Trap,Stefan Lichtberger,2753725443
92
+ Amarillo By Morning (Live),Enkh-Erdene,21952785395
93
+ Cheta,Ada Ehi,34776352786
94
+ Aurora,Vast Vision,10142182154
95
+ Дикая львица,ALEX&RUS,3862165381
96
+ What If (I Told You I Like You),Johnny Orlando & Mackenzie Ziegler,3790831465
97
+ كن فيكون (Acapella Cover),Othman Alibrahim,6649987832
98
+ Space for Two (feat. Viral Sound God) [Kompa Mix],Viral Sound Goddess,50791634299
99
+ I Left My Home (feat. Drill Sergeant DePalo),The Kiffness,7718979642
100
+ Heart of Courage,Two Steps From Hell,34485035875
101
+ Your Turn,Keegan DeWitt,22904494118
102
+ Panama,Matteo,26726258232
103
+ Bad Liar,Anna Hamilton,49926272607
104
+ Can't Buy Me Loving / La La La,Rauf & Faik,23549934979
105
+ Somewhere,Chronixx,23461102565
106
+ "Generation Opus Love (feat. Eric Prydz, Albert Neve & Robbie Wulfsohn)",AP MX,50056852797
107
+ Voilà,"André Rieu, Johann Strauss Orchestra & Emma Kok",50445067815
108
+ Daddy wey dey Pamper (feat. Lyrical HI),Moses Bliss,35835148475
109
+ Loving This Moment (feat. Mia Niles),Gamma Skies,53152072796
110
+ Pyramid (Flashback) [Abgt391] [Mixed],Jaytech,45270234119
111
+ Glassonanze,Rezyon,4035954908
112
+ DJ Old Lenka Trouble,DJ Riann Jatim,16569590533
113
+ Opus (Four Tet Remix),Eric Prydz,12466968641
114
+ Don't Go Yet,Camila Cabello,4976040408
115
+ "O Come, O Come, Emmanuel",Matt Maher,25357749491
116
+ Past Lives (Sapientdreams Remix),BØRNS,32203506376
117
+ Good Morning,Kanye West,41762448633
118
+ Phendula,Zahara,17223092203
119
+ We Found Love (feat. Calvin Harris),Rihanna,41476224177
120
+ Say It Right,Nelly Furtado,3633170164
121
+ Everything Cries Holy,Robin Mark,50820333416
122
+ Yet Not I but Through Christ in Me,CityAlight,30207055534
123
+ Bloody Mary,Lady Gaga,38959013617
124
+ "Loyal Brave True (From Mulan"")""",Christina Aguilera,44342698206
125
+ Heat Waves (Slowed),Glass Animals,42562743866
126
+ Bm (London View),OTP,7559590396
127
+ Tulia,Butera Knowless,10619293096
128
+ For a Girl,Laine Hardy,9591737298
129
+ Música Pop Africana Contemporánea,Ritmo Africano,24350628976
130
+ Ava,Famy,35497412691
131
+ Soweto,Victony & Tempoe,46992901617
132
+ Avant toi,Vitaa & Slimane,10075930799
133
+ Very Sad,Enchan,49770369659
134
+ Mary On A Cross,Ghost,39935709662
135
+ Phobia,Batawi,53778808716
136
+ Everybody,Ingrid Michaelson,44109462672
137
+ Power Rangers,Teni,25217016153
138
+ Lucid Dreams,Juice WRLD,42117414299
139
+ Grand Finale,Krzysztof A. Janczak,31825384523
140
+ I Love You (Music Theme) [Maithili],Ankita,17307363480
141
+ Pass On,Culture,24670591198
142
+ Fortish,Di Young,21936793113
143
+ Sympathy (Club Vocal),Black Rascals,7199426491
144
+ abc (The Wild Remix),GAYLE,23890431737
145
+ Take Care,Beach House,26680446899
146
+ Kwaku The Traveller,Black Sherif,44314676982
147
+ Headlights (feat. KIDDO),Alok & Alan Walker,3924374890
148
+ Caramelo,Ozuna,46998446090
149
+ Numb & Frozen (FILV Remix),Icy Narco,14348950687
150
+ Hero,Bryan Todd Feat. Ashley Argota,32284281159
151
+ If You Could Read My Mind,Gordon Lightfoot,13082264937
152
+ Lover Boy,Barnaba,10753864704
153
+ Alan Turing's Legacy,Alexandre Desplat & London Symphony Orchestra,49308481828
154
+ Hope (Club Mix),ARTY,4169931100
155
+ How Are You (My Friend),Johnny Drille,9457951834
156
+ Lose Yourself,Felax,16143176613
157
+ Dunia,Harmonize,31431087152
158
+ Lost Boy (Remix),Teewavey,53193089427
159
+ Before You Go,Lewis Capaldi,41493375275
160
+ Knowing You,Minister GUC,18922447765
161
+ Joy in Chaos,Holy Drill,100911899
162
+ Tigini,Kikimoteleba,37390821128
163
+ Memories,Maroon 5,31868483736
164
+ Break the Rules (End Credits),Ruen Brothers,44052056897
165
+ Nyar Migori,Prince Indah,14712796238
166
+ Road So Far,Tonyz,2332670060
167
+ Baby You (feat. Nadia Mukami),Bahati,18181189285
168
+ "Lento, Bailemo (Bachata Kizomba)",Alegria,31207829400
169
+ Into Your Arms (feat. Ava Max),Witt Lowry,18969074551
170
+ We're Dark Fey,Geoff Zanelli,47201833943
171
+ Kokoro (Karaoke) [Cover],Karaoke Sound,32295617875
172
+ Mimi Yesu,DEZ KURU,11278431947
173
+ Kill Em All (feat. Ill El),Tino Backwerdz,26920002882
174
+ Faded (feat. Stackboi999),Mortymp3,29683170625
175
+ Self Control,Laura Branigan,6357395252
176
+ Otaku,Robin Hagglund,16744933680
177
+ Bend,Ultrademon,8616661405
178
+ Trip to Heaven,Nico Anuch,4599249339
179
+ Think Twice,Céline Dion,17756664358
180
+ Young And Beautiful,Lana Del Rey,46060902353
181
+ Paris,Else,45546626019
182
+ ROCKSTAR (feat. Roddy Ricch),DaBaby,42428271604
183
+ Hislerim (feat. Zerrin),Serhat Durmus,21848615605
184
+ Off The Grid,HDMN Prime,7660629534
185
+ Nobody (feat. Cutty ( Eastside Cutty ) cutt),Giving Away Game Management Group,20144560914
186
+ Common Person,Burna Boy,36036938155
187
+ Someone To You,BANNERS,17363289198
188
+ Downtown Nostalgia / Moonlight Mystery,EmpeliusVanOptisey,32276695359
189
+ Without You (feat. Sandro Cavazza),Avicii,14287017095
190
+ это ли счастье?,Rauf & Faik,25398029559
191
+ Livia,Lightboy,20962197333
192
+ Iceembe (feat. Delpha),Kwame Rígíi,52283457510
193
+ Vessel,"Ship Wrek, Zookeepers & Trauzers",19041542643
194
+ Sitabaki Kama Nilivyo,Joel Lwaga,39005945199
195
+ Woh Din X Snap (Lofi),Sourav Verma,34007267410
196
+ Savior (feat. Quavo),Iggy Azalea,29808125780
197
+ I Like It (feat. Sho Madjozi),Darassa,41511469417
198
+ Ievan Polkka (feat. Bilal Göregen) [Club Remix],The Kiffness,10751488693
199
+ Come Tomorrow (2021 Remastered),Mighty Diamonds,49432334602
200
+ Roulette,Katy Perry,18032942515
201
+ Clandestina (Version acoustique),Emma Peters,9994551799
202
+ Sólo Tú (feat. Lupion),Iván Troyano,49771293283
203
+ Falling,Trevor Daniel,23894805345
204
+ Omemma,Judikay,28149058639
205
+ Annunciation,Michael Hix,3801737764
206
+ Bring Me Back,Odyssybeatz,16945985154
207
+ High et Monalisa,7th Sound,36989230672
208
+ Million Voices (feat. African Children's Choir),Wyclef Jean,38155554457
209
+ It's a Beautiful Day (Reprise),"The Kiffness, Rushawn & Jermaine Edwards",35364486369
210
+ Monody (feat. Laura Brehm),TheFatRat,30781388486
211
+ DETACH,Willaris. K,14314579743
212
+ In This Shirt,The Irrepressibles,37747842721
213
+ Mapenzi Run Dunia,Alikiba,9407644401
214
+ Ramenez la coupe à la maison,Vegedream,42019594799
215
+ Tia,RJ Kanierra,25613904979
216
+ Adulthood Anthem,Ladé,32639468409
217
+ Beautiful,Giulio Cercato,17995331630
218
+ Sun,Adrián Berenguer,2964463908
219
+ Man's Not Hot,Big Shaq,8570163349
220
+ Victory,solomon lange,40339890260
221
+ Can We Kiss Forever? (feat. Adriana Proenza),Kina,20900228170
222
+ This Is What It Feels Like (feat. Trevor Guthrie),Armin van Buuren,34070492820
223
+ Indica (Kraze),Kraze Enlighted_by_heart,13730744439