mirror of
https://github.com/JuLi0n21/pwa-player.git
synced 2026-04-19 23:40:05 +00:00
search feature
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.Win32;
|
||||
using OsuParsers.Beatmaps;
|
||||
using OsuParsers.Database;
|
||||
using OsuParsers.Database.Objects;
|
||||
using shitweb;
|
||||
using System.Collections;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -13,7 +14,6 @@ public class Osudb
|
||||
private static Osudb instance = null;
|
||||
private static readonly object padlock = new object();
|
||||
public static string osufolder { get; private set; }
|
||||
public static OsuDatabase osuDatabase { get; private set; }
|
||||
public static CollectionDatabase CollectionDb { get; private set; }
|
||||
|
||||
static Osudb()
|
||||
@@ -37,6 +37,7 @@ public class Osudb
|
||||
|
||||
static void Parse(string filepath)
|
||||
{
|
||||
OsuDatabase osuDatabase = null;
|
||||
string file = "/osu!.db";
|
||||
if (File.Exists(filepath + file))
|
||||
{
|
||||
@@ -45,6 +46,8 @@ public class Osudb
|
||||
Console.WriteLine($"Parsing {file}");
|
||||
osuDatabase = OsuParsers.Decoders.DatabaseDecoder.DecodeOsu($"{filepath}{file}");
|
||||
Console.WriteLine($"Parsed {file}");
|
||||
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +61,10 @@ public class Osudb
|
||||
Console.WriteLine($"Parsed {file}");
|
||||
}
|
||||
}
|
||||
|
||||
SqliteDB.Instance().setup(osuDatabase);
|
||||
osuDatabase = null;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public static Osudb Instance
|
||||
@@ -75,15 +82,6 @@ public class Osudb
|
||||
}
|
||||
}
|
||||
|
||||
public DbBeatmap GetBeatmapbyHash(string Hash)
|
||||
{
|
||||
if (Hash == null || osuDatabase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return osuDatabase.Beatmaps.FirstOrDefault(beatmap => beatmap.MD5Hash == Hash);
|
||||
}
|
||||
|
||||
public static OsuParsers.Database.Objects.Collection GetCollectionbyName(string name) {
|
||||
|
||||
return CollectionDb.Collections.FirstOrDefault(collection => collection.Name == name);
|
||||
@@ -101,87 +99,37 @@ public class Osudb
|
||||
if (collection == null) { return null; }
|
||||
|
||||
List<Song> songs = new List<Song>();
|
||||
var activeId = 0;
|
||||
var activeId = "";
|
||||
|
||||
collection.MD5Hashes.ForEach(hash =>
|
||||
{
|
||||
var beatmap = GetBeatmapbyHash(hash);
|
||||
var beatmap = SqliteDB.GetSongByHash(hash);
|
||||
if (beatmap == null) { return; }
|
||||
|
||||
if (activeId == beatmap.BeatmapSetId) { return; }
|
||||
activeId = beatmap.BeatmapSetId;
|
||||
//todo
|
||||
string img = getBG(beatmap.FolderName, beatmap.FileName);
|
||||
|
||||
songs.Add(new Song(hash: beatmap.MD5Hash, name: beatmap.Title, artist: beatmap.Artist, length: beatmap.TotalTime, url: $"{beatmap.FolderName}/{beatmap.AudioFileName}" , previewimage: img, mapper: beatmap.Creator));
|
||||
songs.Add(beatmap);
|
||||
|
||||
});
|
||||
|
||||
return new Collection(collection.Name, songs.Count, songs);
|
||||
}
|
||||
|
||||
public List<CollectionPreview> GetCollections()
|
||||
public List<CollectionPreview> GetCollections(int limit, int offset)
|
||||
{
|
||||
|
||||
List<CollectionPreview> collections = new List<CollectionPreview>();
|
||||
|
||||
for (int i = 0; i < CollectionDb.Collections.Count; i++) {
|
||||
for (int i = offset; i < CollectionDb.Collections.Count - 1 && i < offset + limit; i++) {
|
||||
var collection = CollectionDb.Collections[i];
|
||||
|
||||
var beatmap = GetBeatmapbyHash(collection.MD5Hashes.FirstOrDefault());
|
||||
var beatmap = SqliteDB.GetSongByHash(collection.MD5Hashes.FirstOrDefault());
|
||||
|
||||
//todo
|
||||
string img = getBG(beatmap.FolderName, beatmap.FileName);
|
||||
|
||||
collections.Add(new CollectionPreview(index: i, name: collection.Name, previewimage: img, length: collection.Count));
|
||||
collections.Add(new CollectionPreview(index: i, name: collection.Name, previewimage: beatmap.previewimage, length: collection.Count));
|
||||
};
|
||||
|
||||
return collections;
|
||||
}
|
||||
|
||||
public List<Song> GetRecent(int limit, int offset)
|
||||
{
|
||||
var recent = new List<Song>();
|
||||
if(limit > 100 && limit < 0) {
|
||||
limit = 100;
|
||||
}
|
||||
|
||||
var size = osuDatabase.Beatmaps.Count -1;
|
||||
for (int i = size - offset; i > size - offset - limit; i--)
|
||||
{
|
||||
var beatmap = osuDatabase.Beatmaps.ElementAt(i);
|
||||
if (beatmap == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string img = getBG(beatmap.FolderName, beatmap.FileName);
|
||||
|
||||
recent.Add(new Song(
|
||||
name: beatmap.FileName,
|
||||
hash: beatmap.MD5Hash,
|
||||
artist: beatmap.Artist,
|
||||
length: beatmap.TotalTime,
|
||||
url: $"{beatmap.FolderName}/{beatmap.AudioFileName}",
|
||||
previewimage: img,
|
||||
mapper: beatmap.Creator));
|
||||
}
|
||||
|
||||
return recent;
|
||||
}
|
||||
|
||||
public List<Song> GetFavorites()
|
||||
{
|
||||
var recent = new List<Song>();
|
||||
/*
|
||||
osuDatabase.Beatmaps.ForEach(beatmap =>
|
||||
{
|
||||
Console.WriteLine(beatmap.LastModifiedTime);
|
||||
});
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string getBG(string songfolder, string diff)
|
||||
public static string getBG(string songfolder, string diff)
|
||||
{
|
||||
string folderpath = Path.Combine(songfolder, diff);
|
||||
string filepath = Path.Combine(osufolder, "Songs", folderpath);
|
||||
|
||||
Reference in New Issue
Block a user