Inferencer nullability enabled

This commit is contained in:
Justin Swanson
2020-04-09 16:12:32 -05:00
parent 4e1a32caac
commit a30bba2c0b
3 changed files with 9 additions and 7 deletions

View File

@ -1,11 +1,12 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Wabbajack.Lib.Downloaders.UrlDownloaders namespace Wabbajack.Lib.Downloaders.UrlDownloaders
{ {
public class BethesdaNetInferencer : IUrlInferencer public class BethesdaNetInferencer : IUrlInferencer
{ {
public async Task<AbstractDownloadState> Infer(Uri uri) public async Task<AbstractDownloadState?> Infer(Uri uri)
{ {
return BethesdaNetDownloader.StateFromUrl(uri); return BethesdaNetDownloader.StateFromUrl(uri);
} }

View File

@ -1,10 +1,11 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
#nullable enable
namespace Wabbajack.Lib.Downloaders.UrlDownloaders namespace Wabbajack.Lib.Downloaders.UrlDownloaders
{ {
public interface IUrlInferencer public interface IUrlInferencer
{ {
Task<AbstractDownloadState> Infer(Uri uri); Task<AbstractDownloadState?> Infer(Uri uri);
} }
} }

View File

@ -3,15 +3,15 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Wabbajack.Common; using Wabbajack.Common;
using YoutubeExplode; using YoutubeExplode;
#nullable enable
namespace Wabbajack.Lib.Downloaders.UrlDownloaders namespace Wabbajack.Lib.Downloaders.UrlDownloaders
{ {
public class YoutubeInferencer : IUrlInferencer public class YoutubeInferencer : IUrlInferencer
{ {
public async Task<AbstractDownloadState?> Infer(Uri uri)
public async Task<AbstractDownloadState> Infer(Uri uri)
{ {
var state = (YouTubeDownloader.State)YouTubeDownloader.UriToState(uri); var state = YouTubeDownloader.UriToState(uri) as YouTubeDownloader.State;
if (state == null) return null; if (state == null) return null;
var client = new YoutubeClient(Common.Http.ClientFactory.Client); var client = new YoutubeClient(Common.Http.ClientFactory.Client);
@ -24,13 +24,13 @@ namespace Wabbajack.Lib.Downloaders.UrlDownloaders
.Select(line => .Select(line =>
{ {
var segments = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); var segments = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (segments.Length == 0) return (TimeSpan.Zero, null); if (segments.Length == 0) return (TimeSpan.Zero, string.Empty);
if (TryParseEx(segments.First(), out var s1)) if (TryParseEx(segments.First(), out var s1))
return (s1, string.Join(" ", segments.Skip(1))); return (s1, string.Join(" ", segments.Skip(1)));
if (TryParseEx(Enumerable.Last(segments), out var s2)) if (TryParseEx(Enumerable.Last(segments), out var s2))
return (s2, string.Join(" ", Utils.ButLast(segments))); return (s2, string.Join(" ", Utils.ButLast(segments)));
return (TimeSpan.Zero, null); return (TimeSpan.Zero, string.Empty);
}) })
.Where(t => t.Item2 != null) .Where(t => t.Item2 != null)
.ToList(); .ToList();