Skip to content

Commit

Permalink
Rss sketchset
Browse files Browse the repository at this point in the history
  • Loading branch information
TimAidley committed Feb 27, 2023
1 parent 618c4ab commit 551da10
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private async Task InitAsync()

public bool IsSketchIndexValid(int index)
{
return index < NumSketches;
return index < NumSketches && index >= 0;
}

public void RequestOnlyLoadedMetadata(List<int> requests)
Expand Down
73 changes: 73 additions & 0 deletions Assets/Scripts/ResourceSystem/RssSketchCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml;
using System.ServiceModel.Syndication;
using UnityEngine;

namespace TiltBrush
{
public class RssSketchCollection : IResourceCollection
{
private Uri m_Uri;
private HttpClient m_HttpClient;

public RssSketchCollection(HttpClient httpClient, Uri uri)
{
m_Uri = uri;
m_HttpClient = httpClient;
}

public string Name => "RSS Feed";
public Uri Uri { get; }
public Uri PreviewUri { get; }
public string Description { get; }
public Author[] Authors { get; }
public ResourceLicense License { get; }
public async Task InitAsync()
{
// might as well do all the work when getting the page
return;
}
public async Task<Texture2D> LoadPreviewAsync()
{
throw new NotImplementedException();
}
public async Task<Stream> GetStreamAsync()
{
throw new NotImplementedException();
}
public async IAsyncEnumerable<IResource> ContentsAsync()
{
SyndicationFeed feed;
try
{
Debug.Log($"Fetching rss stream {m_Uri.AbsoluteUri}");
var stream = await m_HttpClient.GetStreamAsync(m_Uri);
Debug.Log("Got stream");
using var xmlReader = XmlReader.Create(stream);
Debug.Log("Loading feed");
feed = SyndicationFeed.Load(xmlReader);
}
catch (Exception e)
{
Debug.LogException(e);
yield break;
}
foreach (var item in feed.Items)
{
var remoteSketch = new RemoteSketchResource(
name: item.Title.Text,
uri: item.Links[0].Uri,
previewUri: null,
description: item.Summary.Text,
authors: item.Authors.Select(x => new TiltBrush.Author { Name = x.Name, Url = x.Uri, Email = x.Email }).ToArray()
);
yield return remoteSketch;
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/ResourceSystem/RssSketchCollection.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Assets/Scripts/Save/SketchCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ void Awake()

InitFeaturedSketchesPath();

var icosaCollection = new IcosaSketchCollection(App.HttpClient);
//var icosaCollection = new IcosaSketchCollection(App.HttpClient);
var rssCollection = new RssSketchCollection(App.HttpClient, new Uri("https://timaidley.github.io/open-brush-feed/sketches.rss"));

m_Sets = new SketchSet[]
{
new FileSketchSet(),
//new FileSketchSet(App.FeaturedSketchesPath()),
//new AsyncWrapperSketchSet(new RssSketchSetAsync(new Uri("https://heavenly-upbeat-scorpion.glitch.me/sketches.rss"))),
new ResourceCollectionSketchSet(icosaCollection),
//new ResourceCollectionSketchSet(icosaCollection),
new ResourceCollectionSketchSet(rssCollection),
new PolySketchSet(this, SketchSetType.Liked, maxTriangles, needsLogin: true),
new GoogleDriveSketchSet(),
};
Expand Down

0 comments on commit 551da10

Please sign in to comment.