Skip to content

Commit 985e332

Browse files
committed
set source to None if client searches for a URL
1 parent 05493ad commit 985e332

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

swish/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import aiohttp
2929
import aiohttp.web
30+
import yarl
3031
import yt_dlp
3132

3233
from .config import CONFIG
@@ -231,11 +232,14 @@ async def search_tracks(self, request: aiohttp.web.Request) -> aiohttp.web.Respo
231232
if not query:
232233
return aiohttp.web.json_response({'error': 'Missing "query" query parameter.'}, status=400)
233234

234-
source: str = request.query.get('source', 'none')
235+
source = request.query.get('source', 'youtube')
236+
if (url := yarl.URL(query)) and url.host and url.scheme:
237+
source = 'none'
235238

236239
prefix = self._SOURCE_MAPPING.get(source)
237240
if prefix is None:
238241
return aiohttp.web.json_response({'error': 'Invalid "source" query parameter.'}, status=400)
239242

240243
tracks = await self._get_tracks(f'{prefix}{query}')
244+
241245
return aiohttp.web.json_response(tracks)

0 commit comments

Comments
 (0)