mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
search game by id added
This commit is contained in:
@@ -123,7 +123,7 @@ class IGDBHandler():
|
||||
for rom in matched_roms:
|
||||
try:
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
|
||||
data=f"fields url; where game={rom['id']};").json()[0]
|
||||
data=f"fields url; where game={rom['id']};").json()[0]
|
||||
rom['url_cover'] = f"https:{res_details['url']}".replace('t_thumb', f't_cover_big')
|
||||
except IndexError:
|
||||
rom['url_cover'] = DEFAULT_URL_COVER_L
|
||||
@@ -132,6 +132,21 @@ class IGDBHandler():
|
||||
else:
|
||||
log.warning(f"{p_slug} is not supported!")
|
||||
return matched_roms
|
||||
|
||||
def get_matched_roms_by_id(self, igdb_id: str) -> list:
|
||||
matched_roms: list[dict] = []
|
||||
matched_roms: list = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"fields name, id, slug, summary; where id={igdb_id};").json()
|
||||
for rom in matched_roms:
|
||||
try:
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
|
||||
data=f"fields url; where game={rom['id']};").json()[0]
|
||||
rom['url_cover'] = f"https:{res_details['url']}".replace('t_thumb', f't_cover_big')
|
||||
except IndexError:
|
||||
rom['url_cover'] = DEFAULT_URL_COVER_L
|
||||
rom['r_igdb_id'] = rom.pop('id')
|
||||
rom['r_slug'] = rom.pop('slug')
|
||||
return matched_roms
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -112,13 +112,17 @@ def remove_rom(p_slug: str, file_name: str, filesystem: bool=False) -> dict:
|
||||
|
||||
|
||||
@app.put("/search/roms/igdb")
|
||||
async def search_rom_igdb(req: Request) -> dict:
|
||||
async def search_rom_igdb(req: Request, igdb_id: str=None) -> dict:
|
||||
"""Get all the roms matched from igdb."""
|
||||
|
||||
data: dict = await req.json()
|
||||
log.info(emoji.emojize(":magnifying_glass_tilted_right: IGDB Searching"))
|
||||
log.info(emoji.emojize(f":video_game: {data['rom']['p_slug']}: {COLORS['orange']}{data['rom']['file_name']}{COLORS['reset']}"))
|
||||
matched_roms = igdbh.get_matched_roms(data['rom']['file_name'], data['rom']['p_igdb_id'], data['rom']['p_slug'])
|
||||
if igdb_id:
|
||||
log.info(f"Searching by id: {igdb_id}")
|
||||
matched_roms = igdbh.get_matched_roms_by_id(igdb_id)
|
||||
else:
|
||||
log.info(emoji.emojize(f":video_game: {data['rom']['p_slug']}: {COLORS['orange']}{data['rom']['file_name']}{COLORS['reset']}"))
|
||||
matched_roms = igdbh.get_matched_roms(data['rom']['file_name'], data['rom']['p_igdb_id'], data['rom']['p_slug'])
|
||||
log.info("Results:")
|
||||
[log.info(f"\t - {COLORS['blue']}{rom['name']}{COLORS['reset']}") for rom in matched_roms]
|
||||
return {'data': matched_roms}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { downloadRom, downloadSave } from '@/utils/utils.js'
|
||||
const rom = ref(JSON.parse(localStorage.getItem('currentRom')) || '')
|
||||
const saveFiles = ref(false)
|
||||
const searching = ref(false)
|
||||
const igdb_id = ref('')
|
||||
const matchedRoms = ref([])
|
||||
const updating = ref(false)
|
||||
const editedRomName = ref(rom.value.file_name)
|
||||
@@ -27,7 +28,7 @@ emitter.on('currentRom', (currentRom) => { rom.value = currentRom })
|
||||
async function searchRomIGDB() {
|
||||
searching.value = true
|
||||
dialogSearchRom.value = true
|
||||
await axios.put('/api/search/roms/igdb', {
|
||||
await axios.put('/api/search/roms/igdb?igdb_id='+igdb_id.value, {
|
||||
rom: rom.value
|
||||
}).then((response) => {
|
||||
matchedRoms.value = response.data.data
|
||||
@@ -155,14 +156,30 @@ async function deleteRom() {
|
||||
|
||||
<v-dialog v-model="dialogSearchRom" scroll-strategy="none" width="auto" :scrim="false">
|
||||
<v-card max-width="600">
|
||||
|
||||
<v-toolbar v-show="searching">
|
||||
<v-toolbar-title>Searching...</v-toolbar-title>
|
||||
<v-btn icon @click="dialogSearchRom=false" class="ml-1" rounded="0"><v-icon>mdi-close</v-icon></v-btn>
|
||||
</v-toolbar>
|
||||
|
||||
<v-toolbar v-show="!searching">
|
||||
<v-toolbar-title>Results found</v-toolbar-title>
|
||||
<v-btn icon @click="dialogSearchRom=false" class="ml-1" rounded="0"><v-icon>mdi-close</v-icon></v-btn>
|
||||
</v-toolbar>
|
||||
|
||||
<v-text-field
|
||||
@keyup.enter="searchRomIGDB()"
|
||||
@click:clear="igdb_id=''"
|
||||
v-show="!searching"
|
||||
v-model="igdb_id"
|
||||
label="search by id"
|
||||
prepend-inner-icon="mdi-search-web"
|
||||
class="ml-5 mt-5 mr-5 mb-5 shrink"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
hide-details
|
||||
clearable/>
|
||||
|
||||
<v-card-text rounded="0" class="pa-3 scroll">
|
||||
<div class="d-flex justify-center">
|
||||
<v-progress-circular v-show="searching" :width="2" :size="40" class="pa-3 ma-3" indeterminate/>
|
||||
|
||||
Reference in New Issue
Block a user