Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Added Beat Saber Searching
Browse files Browse the repository at this point in the history
  • Loading branch information
Suprnova committed Sep 9, 2020
1 parent 88ebe90 commit 8e5f22e
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 1 deletion.
5 changes: 5 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<TextBlock Name="osusearch" FontSize="14">osu!</TextBlock>
</StackPanel>
</ComboBoxItem>
<ComboBoxItem>
<StackPanel>
<TextBlock Name="beatsearch" FontSize="14">Beat Saber</TextBlock>
</StackPanel>
</ComboBoxItem>
</ComboBox>
<Label Content="Songs directory:" HorizontalAlignment="Left" Margin="163,10,0,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="29" Width="109"/>
<TextBox Grid.Column="1" HorizontalAlignment="Left" Height="25" Margin="296,10,0,0" Text="" TextWrapping="NoWrap" VerticalAlignment="Top" Width="236" FontSize="14" Name="dir"/>
Expand Down
183 changes: 182 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public class CloneSong
public string Link { get; set; }
public string Charter { get; set; }
}
public class BeatSong
{
public string Key { get; set; }
public MetadataList Metadata { get; set; }
public class MetadataList
{
public string SongName { get; set; }
public string SongAuthorName { get; set; }
public string LevelAuthorName { get; set; }
}
}
[DllImport("Kernel32")]
public static extern void AllocConsole();

Expand Down Expand Up @@ -112,6 +123,10 @@ private void SearchChanged(object sender, SelectionChangedEventArgs e)
{
provider.Text = "osusearch";
}
else if (search.SelectedIndex == 6)
{
provider.Text = "Beat Saver";
}
}

private void Browse_Click(object sender, RoutedEventArgs e)
Expand All @@ -138,7 +153,7 @@ private void Download_Click(object sender, RoutedEventArgs e)
}
private void Search_Click(object sender, RoutedEventArgs e)
{
if ((source.SelectedIndex == 1 && search.SelectedIndex == 1) || (source.SelectedIndex == 0 && search.SelectedIndex == 5))
if ((source.SelectedIndex == 1 && search.SelectedIndex == 1) || (source.SelectedIndex == 0 && search.SelectedIndex == 5) || (source.SelectedIndex == 3 && search.SelectedIndex == 6))
{
MessageBox.Show("You cannot use the same game as the source and the search.", "Error");
return;
Expand Down Expand Up @@ -252,6 +267,35 @@ private void SourceClone()
}
}
}
else if (search.SelectedIndex == 6)
{
{
searchBtn.IsEnabled = false;
source.IsEnabled = false;
search.IsEnabled = false;
dir.IsEnabled = false;
browse.IsEnabled = false;
prov.IsEnabled = false;

Globals.links = BeatSaberMatching(titles, artists);
int i = 0;
using (StringReader reader = new StringReader(Globals.links))
{
string line = string.Empty;
do
{
line = reader.ReadLine();
if (line != null)
{
Globals.linksFinal[i] = line;
i++;
}
}
while (line != null);
download.IsEnabled = true;
}
}
}
}
private void SourceOsu()
{
Expand Down Expand Up @@ -331,6 +375,35 @@ private void SourceOsu()
prov.IsEnabled = false;
results.Text = GrooveCoasterMatching(titles, titlesUni);
}
else if (search.SelectedIndex == 6)
{
{
searchBtn.IsEnabled = false;
source.IsEnabled = false;
search.IsEnabled = false;
dir.IsEnabled = false;
browse.IsEnabled = false;
prov.IsEnabled = false;

Globals.links = BeatSaberMatching(titles, artists);
int i = 0;
using (StringReader reader = new StringReader(Globals.links))
{
string line = string.Empty;
do
{
line = reader.ReadLine();
if (line != null)
{
Globals.linksFinal[i] = line;
i++;
}
}
while (line != null);
download.IsEnabled = true;
}
}
}
}
private void SourceStep()
{
Expand Down Expand Up @@ -439,6 +512,35 @@ private void SourceStep()
}
}
}
else if (search.SelectedIndex == 6)
{
{
searchBtn.IsEnabled = false;
source.IsEnabled = false;
search.IsEnabled = false;
dir.IsEnabled = false;
browse.IsEnabled = false;
prov.IsEnabled = false;

Globals.links = BeatSaberMatching(titles, artists);
int i = 0;
using (StringReader reader = new StringReader(Globals.links))
{
string line = string.Empty;
do
{
line = reader.ReadLine();
if (line != null)
{
Globals.linksFinal[i] = line;
i++;
}
}
while (line != null);
download.IsEnabled = true;
}
}
}
}
private void SourceBeatSaber()
{
Expand Down Expand Up @@ -1442,5 +1544,84 @@ public string OsuMatching(List<string> titles, List<string> artists)
osuLinks.ForEach(s => sb.AppendLine(s));
return sb.ToString();
}
public string BeatSaberMatching(List<string> titles, List<string> artists)
{
var json = string.Empty;
var beatMatches = new List<string>();
var beatLinks = new List<string>();
Console.Clear();
Console.WriteLine("Searching Beat Saber songs... ");
for (var i = 0; i < titles.Count; i++)
{
var title = titles[i];
var titleURL = title.Replace(" ", "%20");
var artist = string.Empty;
bool containsArtist = false;
if (artists != null)
{
containsArtist = true;
artist = artists[i];
}
else
{
}

try
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add("User-Agent: Other"); // done to avoid 403 errors
json = wc.DownloadString("https://beatsaver.com/api/search/text/:page?q=" + titleURL);
}
}
catch
{
continue;
}
if (json.Length < 100)
{
Console.Clear();
Console.WriteLine("Searching Beat Saber songs... " + i + "/" + titles.Count);
continue;
}
JObject songSearch = JObject.Parse(json);
IList<JToken> results = songSearch["docs"].Children().ToList();
IList<BeatSong> songs = new List<BeatSong>();
foreach (JToken result in results)
{
BeatSong song = result.ToObject<BeatSong>();
if (song.Metadata.SongName.ToUpper() == title.ToUpper())
{
if (containsArtist == true)
{
if (song.Metadata.SongAuthorName.ToUpper() == artist.ToUpper())
{
beatMatches.Add(song.Metadata.SongName + " - Created by " + song.Metadata.LevelAuthorName);
beatLinks.Add("https://beatsaver.com/beatmap/" + song.Key);
}
else { }
}
else
{
beatMatches.Add(song.Metadata.SongName + " - Created by " + song.Metadata.LevelAuthorName);
beatLinks.Add("https://beatsaver.com/beatmap/" + song.Key);
}
}
}
Console.Clear();
Console.WriteLine("Searching Beat Saber songs... " + i + "/" + titles.Count);
}
var sb = new StringBuilder(4096);
beatMatches.ForEach(s => resultsList.Items.Add(s));
try
{
resultsList.SelectedIndex = 0;
}
catch { };
App.Current.MainWindow.Show();
FreeConsole();
beatLinks.ForEach(s => sb.AppendLine(s));
return sb.ToString();
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For example, you can search for BEMANI songs that are also in your osu! songs fo
* DJMAX RESPECT (via [Cypher Gate](https://cyphergate.net/))
* GROOVE COASTER (via [groovecoaster.jp](https://groovecoaster.jp/))
* osu! (via [osusearch](https://osusearch.com/))
* Beat Saber (via [Beat Saver](https://beatsaver.com/))

# Usage:
![Tutorial Image](https://cdn.discordapp.com/attachments/603730493074046978/750395544127668344/unknown.png)
Expand Down

0 comments on commit 8e5f22e

Please sign in to comment.