Skip to content

Commit

Permalink
Merge pull request #10 from rithik-b/dev/downloader-remake
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
rithik-b authored Dec 24, 2021
2 parents 468d2ab + 516f687 commit 33f2f90
Show file tree
Hide file tree
Showing 47 changed files with 997 additions and 1,343 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: GetStrippedRefs
env:
FILES_URL: ${{ secrets.BSFILES_URL }}
run: wget --no-check-certificate "$FILES_URL" -q -O bsfiles.zip
- name: ExtractRefs
run: unzip -q -n bsfiles.zip -d ${{github.workspace}}/Refs
- name: Download SIRA References
uses: ProjectSIRA/[email protected]
with:
manifest: ${{github.workspace}}/MorePlaylists/manifest.json
sira-server-code: ${{ secrets.SIRA_SERVER_CODE }}
- name: Download Mod Dependencies
uses: Goobwabber/[email protected]
with:
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: GetStrippedRefs
env:
FILES_URL: ${{ secrets.BSFILES_URL }}
run: wget --no-check-certificate "$FILES_URL" -q -O bsfiles.zip
- name: ExtractRefs
run: unzip -q -n bsfiles.zip -d ${{github.workspace}}/Refs
- name: Download SIRA References
uses: ProjectSIRA/[email protected]
with:
manifest: ${{github.workspace}}/MorePlaylists/manifest.json
sira-server-code: ${{ secrets.SIRA_SERVER_CODE }}
- name: Download Mod Dependencies
uses: Goobwabber/[email protected]
with:
Expand Down
38 changes: 0 additions & 38 deletions MorePlaylists/Configuration/PluginConfig.cs

This file was deleted.

30 changes: 30 additions & 0 deletions MorePlaylists/Entries/AccSaberEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Threading.Tasks;
using SiraUtil.Web;

namespace MorePlaylists.Entries
{
internal class AccSaberEntry : SongDetailsEntry
{
public override string Title { get; protected set; }
public override string Author { get; protected set; }
public override string Description { get; protected set; }
public override string PlaylistURL { get; protected set; }
public override string SpriteString { get; protected set; }
public override SpriteType SpriteType => SpriteType.Playlist;

public static async Task<AccSaberEntry> GetAccSaberPlaylist(string playlistURL, IHttpService siraHttpService)
{
AccSaberEntry accSaberEntry = new AccSaberEntry();
accSaberEntry.PlaylistURL = playlistURL;
await accSaberEntry.DownloadPlaylist(siraHttpService);
if (accSaberEntry.RemotePlaylist != null)
{
accSaberEntry.Title = accSaberEntry.RemotePlaylist.Title;
accSaberEntry.Author = accSaberEntry.RemotePlaylist.Author;
accSaberEntry.Description = accSaberEntry.RemotePlaylist.Description;
return accSaberEntry;
}
return null;
}
}
}
41 changes: 0 additions & 41 deletions MorePlaylists/Entries/Base64Entry.cs

This file was deleted.

9 changes: 3 additions & 6 deletions MorePlaylists/Entries/BeastSaberEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MorePlaylists.Entries
{
public class BeastSaberEntry : Base64Entry
internal class BeastSaberEntry : SongDetailsEntry
{
[JsonProperty("playlistTitle")]
public override string Title { get; protected set; }
Expand All @@ -20,11 +20,8 @@ public class BeastSaberEntry : Base64Entry
public override string PlaylistURL { get; protected set; }

[JsonProperty("image")]
protected override string CoverString
{
get => base.CoverString;
set => base.CoverString = value;
}
public override string SpriteString { get; protected set; }
public override SpriteType SpriteType => SpriteType.Base64;

public override string Description
{
Expand Down
113 changes: 113 additions & 0 deletions MorePlaylists/Entries/BeatSaverEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BeatSaverSharp.Models;
using Newtonsoft.Json;
using SiraUtil.Web;

namespace MorePlaylists.Entries
{
internal class BeatSaverResponse
{
[JsonProperty("docs")]
public List<BeatSaverEntry> Entries { get; protected set; }
}

internal class BeatSaverEntry : GenericEntry
{
[JsonProperty("name")]
public override string Title { get; protected set; }

[JsonProperty("owner")]
public BeatSaverAuthor Owner { get; protected set; }

[JsonProperty("description")]
public override string Description { get; protected set; }

[JsonProperty("playlistId")]
public string PlaylistID { get; protected set; }

[JsonProperty("playlistImage")]
public override string SpriteString { get; protected set; }

public override SpriteType SpriteType => SpriteType.URL;

public override string Author
{
get => Owner.Name;
protected set { }
}

public override string PlaylistURL
{
get => $"https://api.beatsaver.com/playlists/id/{PlaylistID}/download";
protected set { }
}

private List<Song> songs;

public override async Task<List<Song>> GetSongs(IHttpService siraHttpService)
{
if (songs == null)
{
songs = new List<Song>();
int page = 0;
bool limitReached = false;
while (!limitReached)
{
try
{
IHttpResponse webResponse = await siraHttpService.GetAsync($"https://api.beatsaver.com/playlists/id/{PlaylistID}/{page}", cancellationToken: CancellationToken.None);
if (webResponse.Successful)
{
BeatSaverDetailEntry detailEntry = JsonConvert.DeserializeObject<BeatSaverDetailEntry>(await webResponse.ReadAsStringAsync());
if (detailEntry.maps.Count != 0)
{
foreach (BeatSaverMapDetailWithOrder map in detailEntry.maps)
{
songs.Add(new Song(map.map.Metadata.SongName, $"{map.map.Metadata.SongAuthorName} [{map.map.Metadata.LevelAuthorName}]", map.map.LatestVersion.CoverURL));
}
}
else
{
limitReached = true;
}
page++;
}
else
{
limitReached = true;
}
}
catch (Exception)
{
limitReached = true;
}
}
}
return songs;
}
}

internal class BeatSaverAuthor
{
[JsonProperty("name")]
public string Name { get; protected set; }
}

internal class BeatSaverDetailEntry
{
[JsonProperty("maps")]
public List<BeatSaverMapDetailWithOrder> maps { get; protected set; }
}

internal class BeatSaverMapDetailWithOrder
{
[JsonProperty("map")]
public Beatmap map { get; protected set; }

[JsonProperty("order")]
public float order { get; protected set; }
}
}
Loading

0 comments on commit 33f2f90

Please sign in to comment.