-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Valyreon/develop
Logging and bugfixes
- Loading branch information
Showing
29 changed files
with
655 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace SubloaderAvalonia.Extensions; | ||
|
||
public static class DateTimeExtensions | ||
{ | ||
public static long ToUnixTimestamp(this DateTime dateTime) | ||
{ | ||
dateTime = dateTime.ToUniversalTime(); | ||
return (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OpenSubtitlesSharp; | ||
using SubloaderAvalonia.Extensions; | ||
|
||
namespace SubloaderAvalonia.Models; | ||
|
||
public class ApplicationSettings | ||
{ | ||
public static readonly IReadOnlyList<string> ValidFormats = new List<string> { "srt", "sub", "mpl", "webvtt", "dfxp", "txt" }; | ||
|
||
private User loggedInUser; | ||
private SearchParameters defaultSearchParameters; | ||
private string preferredFormat = "srt"; | ||
private IReadOnlyList<string> wantedLanguages; | ||
|
||
public bool AllowMultipleDownloads { get; set; } | ||
public SearchParameters DefaultSearchParameters { get; set; } = new(); | ||
public SearchParameters DefaultSearchParameters | ||
{ | ||
get => defaultSearchParameters ??= new(); | ||
set => defaultSearchParameters = value; | ||
} | ||
public bool DownloadToSubsFolder { get; set; } | ||
public bool KeepWindowOnTop { get; set; } = true; | ||
public User LoggedInUser { get; set; } | ||
public bool OverwriteSameLanguageSub { get; set; } | ||
public string PreferredFormat { get; set; } = "srt"; | ||
|
||
public IReadOnlyList<string> WantedLanguages { get; set; } | ||
|
||
public ApplicationSettings Initialize() | ||
public User LoggedInUser | ||
{ | ||
DefaultSearchParameters ??= new(); | ||
PreferredFormat ??= "srt"; | ||
WantedLanguages ??= new List<string>() { "en" }; | ||
get => loggedInUser == null || loggedInUser.TokenExpirationUnixTimestamp <= DateTime.UtcNow.ToUnixTimestamp() ? null : loggedInUser; | ||
set => loggedInUser = value; | ||
} | ||
|
||
public bool OverwriteSameLanguageSub { get; set; } | ||
|
||
if (LoggedInUser?.ResetTime.HasValue == true && LoggedInUser.ResetTime.Value <= DateTime.UtcNow) | ||
{ | ||
LoggedInUser.ResetTime = null; | ||
} | ||
public string PreferredFormat | ||
{ | ||
get => ValidFormats.Contains(preferredFormat) ? preferredFormat : "srt"; | ||
set => preferredFormat = value; | ||
} | ||
|
||
return this; | ||
public IReadOnlyList<string> WantedLanguages | ||
{ | ||
get => wantedLanguages == null || !wantedLanguages.Any() ? wantedLanguages = new List<string>() { "en" } : wantedLanguages; | ||
set => wantedLanguages = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
using System; | ||
using ReactiveUI; | ||
|
||
namespace SubloaderAvalonia.Models; | ||
|
||
public class User | ||
public class User : ReactiveObject | ||
{ | ||
public int AllowedDownloads { get; set; } | ||
public string BaseUrl { get; set; } | ||
public bool IsVIP { get; set; } | ||
public string Level { get; set; } | ||
public int RemainingDownloads { get; set; } | ||
public DateTime? ResetTime { get; set; } | ||
public string Token { get; set; } | ||
public int UserId { get; set; } | ||
public string Username { get; set; } | ||
public long TokenExpirationUnixTimestamp { get; set; } | ||
public string TokenExpirationTimestampString | ||
{ | ||
get | ||
{ | ||
var dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(TokenExpirationUnixTimestamp); | ||
var dateTime = dateTimeOffset.LocalDateTime; | ||
return dateTime.ToString("u")[..^1]; | ||
} | ||
set => _ = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.