summaryrefslogtreecommitdiff
path: root/Services/SourceService.cs
blob: 8953fdad72122a2cfedf4aa4b67129c0436444e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Text.RegularExpressions;

namespace HyperBooru.Client.Services;

public interface ISourceService {
    public string? GetUrlFromFilename(string filename);
}

public class SourceService : ISourceService {
    private Regex PixivRegex =
        new(@"^([0-9]+)_p[0-9]+(_master1200)?\.[^.]+$", RegexOptions.Compiled);

    public string? GetUrlFromFilename(string filename) {
        var pixivMatch = PixivRegex.Match(filename);
        if(pixivMatch.Success)
            return $"https://pixiv.net/en/artworks/{pixivMatch.Groups[1].Value}";

        return null;
    }
}