aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Library
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-12-22 22:58:14 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-12-22 22:58:14 -0500
commit42b14166029d5251e952b72f5c16cd9ae96aa8cb (patch)
treea57be3f719586c722526c78f92481b86b691a3bd /MediaBrowser.Server.Implementations/Library
parentfef1d16cec5d3bf22f5efee21595480ca1aaa602 (diff)
begin work on daily episodes
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
-rw-r--r--MediaBrowser.Server.Implementations/Library/LibraryManager.cs88
-rw-r--r--MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs2
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserManager.cs68
3 files changed, 125 insertions, 33 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
index d52288f87..66125784c 100644
--- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs
@@ -1755,9 +1755,12 @@ namespace MediaBrowser.Server.Implementations.Library
var resolver = new EpisodeResolver(new ExtendedNamingOptions(),
new Naming.Logging.NullLogger());
+ var fileType = episode.VideoType == VideoType.BluRay || episode.VideoType == VideoType.Dvd || episode.VideoType == VideoType.HdDvd ?
+ FileInfoType.Directory :
+ FileInfoType.File;
+
var locationType = episode.LocationType;
- var fileType = /*args.IsDirectory ? FileInfoType.Directory :*/ FileInfoType.File;
var episodeInfo = locationType == LocationType.FileSystem || locationType == LocationType.Offline ?
resolver.Resolve(episode.Path, fileType) :
new Naming.TV.EpisodeInfo();
@@ -1769,29 +1772,42 @@ namespace MediaBrowser.Server.Implementations.Library
var changed = false;
- if (!episode.IndexNumber.HasValue)
+ if (episodeInfo.IsByDate)
{
- episode.IndexNumber = episodeInfo.EpisodeNumber;
-
if (episode.IndexNumber.HasValue)
{
+ episode.IndexNumber = null;
changed = true;
}
- }
-
- if (!episode.IndexNumberEnd.HasValue)
- {
- episode.IndexNumberEnd = episodeInfo.EndingEpsiodeNumber;
if (episode.IndexNumberEnd.HasValue)
{
+ episode.IndexNumberEnd = null;
changed = true;
}
- }
- if (!episode.ParentIndexNumber.HasValue)
- {
- episode.ParentIndexNumber = episodeInfo.SeasonNumber;
+ if (!episode.PremiereDate.HasValue)
+ {
+ if (episodeInfo.Year.HasValue && episodeInfo.Month.HasValue && episodeInfo.Day.HasValue)
+ {
+ episode.PremiereDate = new DateTime(episodeInfo.Year.Value, episodeInfo.Month.Value, episodeInfo.Day.Value).ToUniversalTime();
+ }
+
+ if (episode.PremiereDate.HasValue)
+ {
+ changed = true;
+ }
+ }
+
+ if (!episode.ProductionYear.HasValue)
+ {
+ episode.ProductionYear = episodeInfo.Year;
+
+ if (episode.ProductionYear.HasValue)
+ {
+ changed = true;
+ }
+ }
if (!episode.ParentIndexNumber.HasValue)
{
@@ -1801,11 +1817,53 @@ namespace MediaBrowser.Server.Implementations.Library
{
episode.ParentIndexNumber = season.IndexNumber;
}
+
+ if (episode.ParentIndexNumber.HasValue)
+ {
+ changed = true;
+ }
+ }
+ }
+ else
+ {
+ if (!episode.IndexNumber.HasValue)
+ {
+ episode.IndexNumber = episodeInfo.EpisodeNumber;
+
+ if (episode.IndexNumber.HasValue)
+ {
+ changed = true;
+ }
}
- if (episode.ParentIndexNumber.HasValue)
+ if (!episode.IndexNumberEnd.HasValue)
{
- changed = true;
+ episode.IndexNumberEnd = episodeInfo.EndingEpsiodeNumber;
+
+ if (episode.IndexNumberEnd.HasValue)
+ {
+ changed = true;
+ }
+ }
+
+ if (!episode.ParentIndexNumber.HasValue)
+ {
+ episode.ParentIndexNumber = episodeInfo.SeasonNumber;
+
+ if (!episode.ParentIndexNumber.HasValue)
+ {
+ var season = episode.Season;
+
+ if (season != null)
+ {
+ episode.ParentIndexNumber = season.IndexNumber;
+ }
+ }
+
+ if (episode.ParentIndexNumber.HasValue)
+ {
+ changed = true;
+ }
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
index 39b0a93cc..1a873f01e 100644
--- a/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
+++ b/MediaBrowser.Server.Implementations/Library/Resolvers/TV/EpisodeResolver.cs
@@ -1,7 +1,5 @@
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Naming.Common;
-using MediaBrowser.Naming.IO;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index 1d58ad074..02d7c1be1 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -171,6 +171,38 @@ namespace MediaBrowser.Server.Implementations.Library
return AuthenticateUser(username, passwordSha1, null, remoteEndPoint);
}
+ public bool IsValidUsername(string username)
+ {
+ // Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)
+ return username.All(IsValidCharacter);
+ }
+
+ private bool IsValidCharacter(char i)
+ {
+ return char.IsLetterOrDigit(i) || char.Equals(i, '-') || char.Equals(i, '_') || char.Equals(i, '\'') ||
+ char.Equals(i, '.');
+ }
+
+ public string MakeValidUsername(string username)
+ {
+ if (IsValidUsername(username))
+ {
+ return username;
+ }
+
+ // Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)
+ var builder = new StringBuilder();
+
+ foreach (var c in username)
+ {
+ if (IsValidCharacter(c))
+ {
+ builder.Append(c);
+ }
+ }
+ return builder.ToString();
+ }
+
public async Task<bool> AuthenticateUser(string username, string passwordSha1, string passwordMd5, string remoteEndPoint)
{
if (string.IsNullOrWhiteSpace(username))
@@ -178,7 +210,8 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException("username");
}
- var user = Users.FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase));
+ var user = Users
+ .FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase));
if (user == null)
{
@@ -203,20 +236,6 @@ namespace MediaBrowser.Server.Implementations.Library
}
}
- // Maybe user accidently entered connect credentials. let's be flexible
- if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5))
- {
- try
- {
- await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false);
- success = true;
- }
- catch
- {
-
- }
- }
-
// Update LastActivityDate and LastLoginDate, then save
if (success)
{
@@ -273,7 +292,7 @@ namespace MediaBrowser.Server.Implementations.Library
// There always has to be at least one user.
if (users.Count == 0)
{
- var name = Environment.UserName;
+ var name = MakeValidUsername(Environment.UserName);
var user = InstantiateNewUser(name, false);
@@ -477,6 +496,11 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentNullException("name");
}
+ if (!IsValidUsername(name))
+ {
+ throw new ArgumentException("Only alphanumeric characters are allowed.");
+ }
+
if (Users.Any(u => u.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
{
throw new ArgumentException(string.Format("A user with the name '{0}' already exists.", name));
@@ -803,6 +827,10 @@ namespace MediaBrowser.Server.Implementations.Library
return (UserPolicy)_xmlSerializer.DeserializeFromFile(typeof(UserPolicy), path);
}
}
+ catch (DirectoryNotFoundException)
+ {
+ return GetDefaultPolicy(user);
+ }
catch (FileNotFoundException)
{
return GetDefaultPolicy(user);
@@ -840,6 +868,8 @@ namespace MediaBrowser.Server.Implementations.Library
var path = GetPolifyFilePath(user);
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
+
lock (_policySyncLock)
{
_xmlSerializer.SerializeToFile(userPolicy, path);
@@ -900,6 +930,10 @@ namespace MediaBrowser.Server.Implementations.Library
return (UserConfiguration)_xmlSerializer.DeserializeFromFile(typeof(UserConfiguration), path);
}
}
+ catch (DirectoryNotFoundException)
+ {
+ return new UserConfiguration();
+ }
catch (FileNotFoundException)
{
return new UserConfiguration();
@@ -930,6 +964,8 @@ namespace MediaBrowser.Server.Implementations.Library
config = _jsonSerializer.DeserializeFromString<UserConfiguration>(json);
}
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
+
lock (_configSyncLock)
{
_xmlSerializer.SerializeToFile(config, path);