Skip to content

Commit f9c4b1c

Browse files
committedOct 26, 2024
Added web search temporarily
1 parent ba1c4d1 commit f9c4b1c

File tree

6 files changed

+138
-3
lines changed

6 files changed

+138
-3
lines changed
 

‎app.js

+50-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const pages = {
7171
video: 'video.html',
7272
downloads: 'downloads.html',
7373
settings: 'settings.html',
74-
help: 'help.html'
74+
help: 'help.html',
75+
search: 'web_search.html'
7576
};
7677

7778

@@ -129,6 +130,50 @@ async function clearDownloadsDatabase() {
129130
}
130131
}
131132

133+
// URL mappings for each service's search
134+
const searchUrls = {
135+
youtube: "https://music.youtube.com/search?q=",
136+
spotify: "https://open.spotify.com/search/",
137+
qobuz: "https://www.qobuz.com/gb-en/search?q=",
138+
tidal: "https://listen.tidal.com/search?q=",
139+
deezer: "https://www.deezer.com/us/search/",
140+
appleMusic: "https://music.apple.com/search?term="
141+
};
142+
143+
// Set default tab
144+
let activeTab = "youtube";
145+
146+
// Function to update the active tab
147+
function updateActiveTab(tab) {
148+
document.querySelector('.tab-button.active').classList.remove('active');
149+
document.querySelector(`button[data-tab="${tab}"]`).classList.add('active');
150+
activeTab = tab;
151+
}
152+
153+
// Add event listeners to each tab button
154+
function initializeSearchPage() {
155+
document.querySelectorAll('.tab-button').forEach(button => {
156+
button.addEventListener('click', () => {
157+
updateActiveTab(button.getAttribute('data-tab'));
158+
});
159+
});
160+
}
161+
162+
// Function to perform the search
163+
function performSearch() {
164+
const query = document.getElementById('searchInput').value;
165+
console.log('Renderer: Attempting search with:', { query, activeTab });
166+
if (query) {
167+
try {
168+
window.electronAPI.performSearch({ query, activeTab });
169+
console.log('Renderer: Search request sent to main process');
170+
} catch (error) {
171+
console.error('Renderer: Error sending search:', error);
172+
}
173+
}
174+
}
175+
176+
132177
async function loadPage(pageName) {
133178
const contentDiv = document.getElementById('content');
134179
try {
@@ -152,6 +197,9 @@ async function loadPage(pageName) {
152197
else if (pageName === 'downloads') {
153198
await initializeDownloadStatusPage();
154199
}
200+
else if (pageName === 'search') {
201+
await initializeSearchPage()
202+
}
155203
} catch (error) {
156204
contentDiv.innerHTML = '<p>Error loading the page: ' + error.message + '</p>';
157205
}
@@ -1313,6 +1361,7 @@ window.electronAPI.receive('download-complete', (data) => {
13131361
document.getElementById('musicBtn').addEventListener('click', () => loadPage('music'));
13141362
document.getElementById('videoBtn').addEventListener('click', () => loadPage('video'));
13151363
document.getElementById('downloadsBtn').addEventListener('click', () => loadPage('downloads'));
1364+
document.getElementById('searchBtn').addEventListener('click', () => loadPage('search'));
13161365
document.getElementById('settingsBtn').addEventListener('click', () => loadPage('settings'));
13171366
document.getElementById('helpBtn').addEventListener('click', () => loadPage('help'));
13181367

‎help.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h3>Streamrip downloads (Qobuz, Deezer, Tidal) get stuck, what to do?</h3>
3737
<h2 class="helph2"><i class="fas fa-search"></i> Search FAQ</h2>
3838
<div class="faq-content">
3939
<h3>What is this?</h3>
40-
<p>A search function using API requests is in progress. Meanwhile, use your service’s search page.</p>
40+
<p>A search function using API requests is in progress. Meanwhile, use your service’s search page on our app.</p>
4141
</div>
4242
</section>
4343
<section id="sponsor-help">

‎index.html

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ <h1>MediaHarbor</h1>
1616
<a href="#" id="musicBtn" class="active"><i class="fas fa-music"></i>Music</a>
1717
<a href="#" id="videoBtn"><i class="fas fa-film"></i>Video</a>
1818
<a href="#" id="downloadsBtn"><i class="fas fa-download"></i>Downloads</a>
19+
<a href="#" id="searchBtn"><i class="fa-solid fa-magnifying-glass"></i>Search</a>
1920
</div>
2021
<div class="secondary-nav">
2122
<a href="#" id="settingsBtn"><i class="fas fa-cogs"></i>Settings</a>

‎main.js

+36-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const GamRip = require('./funcs/gamRip');
1010
const CustomRip = require('./funcs/customRip');
1111
const { setupSettingsHandlers } = require('./funcs/settings');
1212

13+
const searchUrls = {
14+
youtube: "https://music.youtube.com/search?q=",
15+
spotify: "https://open.spotify.com/search/",
16+
qobuz: "https://www.qobuz.com/gb-en/search?q=",
17+
tidal: "https://listen.tidal.com/search?q=",
18+
deezer: "https://www.deezer.com/us/search/",
19+
appleMusic: "https://music.apple.com/search?term="
20+
};
21+
1322
ipcMain.handle('load-downloads', (event) => {
1423
return new Promise((resolve, reject) => {
1524
loadDownloadsFromDatabase((rows) => {
@@ -204,6 +213,31 @@ function createWindow() {
204213
ipcMain.on('start-deezer-batch-download', (event, data) => {
205214
customRip.handleDeezerBatchDownload(event, data);
206215
});
216+
ipcMain.on('search-on-browser', (event, searchData) => {
217+
console.log('Main: Received search data:', searchData);
218+
const { query, activeTab } = searchData;
219+
220+
if (!query) {
221+
console.error('Main: No query provided');
222+
return;
223+
}
224+
225+
if (!searchUrls[activeTab]) {
226+
console.error('Main: Invalid activeTab:', activeTab);
227+
return;
228+
}
229+
230+
const searchUrl = searchUrls[activeTab] + encodeURIComponent(query);
231+
console.log('Main: Opening URL:', searchUrl);
232+
233+
shell.openExternal(searchUrl)
234+
.then(() => {
235+
console.log('Main: Browser opened successfully');
236+
})
237+
.catch(err => {
238+
console.error('Main: Failed to open external browser:', err);
239+
});
240+
});
207241
}
208242

209243
app.whenReady().then(createWindow);
@@ -218,4 +252,5 @@ app.on('activate', () => {
218252
if (BrowserWindow.getAllWindows().length === 0) {
219253
createWindow();
220254
}
221-
});
255+
});
256+

‎preload.js

+4
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
4848
folderLocation: () => ipcRenderer.invoke('dialog:openFolder'),
4949
fileSelectLocation: () => ipcRenderer.invoke('dialog:openFile'),
5050
openWvdLocation: () => ipcRenderer.invoke('dialog:openwvdFile'),
51+
performSearch: (searchData) => {
52+
console.log('Preload: Sending search data:', searchData);
53+
return ipcRenderer.send('search-on-browser', searchData);
54+
}
5155
});

‎web_search.html

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Web Search</title>
7+
<style>
8+
#searchInputContainer {
9+
display: flex;
10+
padding: 10px;
11+
background-color: #f4f4f4;
12+
}
13+
#searchInput {
14+
flex: 1;
15+
padding: 8px;
16+
font-size: 1em;
17+
}
18+
iframe {
19+
flex-grow: 1;
20+
width: 100%;
21+
border: none;
22+
}
23+
</style>
24+
</head>
25+
<body>
26+
<!-- Tab Bar -->
27+
<div class="tab-bar">
28+
<button class="tab-button active" data-tab="youtube">YouTube</button>
29+
<button class="tab-button" data-tab="spotify">Spotify</button>
30+
<button class="tab-button" data-tab="qobuz">Qobuz</button>
31+
<button class="tab-button" data-tab="tidal">Tidal</button>
32+
<button class="tab-button" data-tab="deezer">Deezer</button>
33+
<button class="tab-button" data-tab="appleMusic">Apple Music</button>
34+
</div>
35+
36+
<!-- Search Input -->
37+
<div id="searchInputContainer">
38+
<input type="text" id="searchInput" placeholder="Enter search query...">
39+
<button onclick="performSearch()">Search</button>
40+
</div>
41+
42+
<!-- Iframe for displaying search results -->
43+
<iframe id="searchFrame"></iframe>
44+
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)
Failed to load comments.