Skip to content

Commit

Permalink
Merge pull request #3211 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
support wmc episode naming conventions
  • Loading branch information
LukePulverenti authored Mar 26, 2018
2 parents e0488f9 + bdc5963 commit 4095c06
Show file tree
Hide file tree
Showing 75 changed files with 287 additions and 405 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public IEnumerable<DisplayPreferences> GetAllDisplayPreferences(Guid userId)

private DisplayPreferences Get(IReadOnlyList<IResultSetValue> row)
{
using (var stream = _memoryStreamProvider.CreateNew(row[0].ToBlob()))
using (var stream = new MemoryStream(row[0].ToBlob()))
{
stream.Position = 0;
return _jsonSerializer.DeserializeFromStream<DisplayPreferences>(stream);
Expand Down
3 changes: 2 additions & 1 deletion Emby.Server.Implementations/Data/SqliteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using SQLitePCL.pretty;
using System.IO;

namespace Emby.Server.Implementations.Data
{
Expand Down Expand Up @@ -136,7 +137,7 @@ public static byte[] SerializeToBytes(this IJsonSerializer json, object obj, IMe
throw new ArgumentNullException("obj");
}

using (var stream = streamProvider.CreateNew())
using (var stream = new MemoryStream())
{
json.SerializeToStream(obj, stream);
return stream.ToArray();
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ private BaseItem GetItem(IReadOnlyList<IResultSetValue> reader, InternalItemsQue

if (TypeRequiresDeserialization(type))
{
using (var stream = _memoryStreamProvider.CreateNew(reader[1].ToBlob()))
using (var stream = new MemoryStream(reader[1].ToBlob()))
{
stream.Position = 0;

Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Data/SqliteUserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public IEnumerable<User> RetrieveAllUsers()
{
var id = row[0].ReadGuidFromBlob();

using (var stream = _memoryStreamProvider.CreateNew(row[1].ToBlob()))
using (var stream = new MemoryStream(row[1].ToBlob()))
{
stream.Position = 0;
var user = _jsonSerializer.DeserializeFromStream<User>(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
<Name>SocketHttpListener</Name>
</ProjectReference>
<Reference Include="Emby.Naming, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MediaBrowser.Naming.1.1.0\lib\netstandard1.3\Emby.Naming.dll</HintPath>
<HintPath>..\packages\MediaBrowser.Naming.1.1.1\lib\netstandard1.3\Emby.Naming.dll</HintPath>
</Reference>
<Reference Include="Emby.Server.MediaEncoding">
<HintPath>..\ThirdParty\emby\Emby.Server.MediaEncoding.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath,
{
using (var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true))
{
var memoryStream = _memoryStreamProvider.CreateNew();
var memoryStream = new MemoryStream();

await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
Expand Down Expand Up @@ -343,7 +343,7 @@ private async Task CacheResponse(HttpResponseInfo response, string responseCache

using (var responseStream = response.Content)
{
var memoryStream = _memoryStreamProvider.CreateNew();
var memoryStream = new MemoryStream();
await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;

Expand Down Expand Up @@ -458,7 +458,7 @@ private async Task<HttpResponseInfo> SendAsyncInternal(HttpRequestOptions option

using (var stream = httpResponse.GetResponseStream())
{
var memoryStream = _memoryStreamProvider.CreateNew();
var memoryStream = new MemoryStream();

await stream.CopyToAsync(memoryStream).ConfigureAwait(false);

Expand Down
82 changes: 29 additions & 53 deletions Emby.Server.Implementations/HttpServer/SocketSharp/RequestMono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ static internal string GetParameter(string header, string attr)
return header.Substring(ap + 1, end - ap - 1);
}

async Task LoadMultiPart()
async Task LoadMultiPart(WebROCollection form)
{
string boundary = GetParameter(ContentType, "; boundary=");
if (boundary == null)
return;

using (var requestStream = GetSubStream(InputStream, _memoryStreamProvider))
using (var requestStream = InputStream)
{
//DB: 30/01/11 - Hack to get around non-seekable stream and received HTTP request
//Not ending with \r\n?
var ms = _memoryStreamProvider.CreateNew(32 * 1024);
var ms = new MemoryStream(32 * 1024);
await requestStream.CopyToAsync(ms).ConfigureAwait(false);

var input = ms;
Expand Down Expand Up @@ -83,28 +83,21 @@ async Task LoadMultiPart()
}
}

public QueryParamCollection Form
public async Task<QueryParamCollection> GetFormData()
{
get
{
if (form == null)
{
form = new WebROCollection();
files = new Dictionary<string, HttpPostedFile>();
var form = new WebROCollection();
files = new Dictionary<string, HttpPostedFile>();

if (IsContentType("multipart/form-data", true))
{
var task = LoadMultiPart();
Task.WaitAll(task);
}
else if (IsContentType("application/x-www-form-urlencoded", true))
{
var task = LoadWwwForm();
Task.WaitAll(task);
}
if (IsContentType("multipart/form-data", true))
{
await LoadMultiPart(form).ConfigureAwait(false);
}
else if (IsContentType("application/x-www-form-urlencoded", true))
{
await LoadWwwForm(form).ConfigureAwait(false);
}

form.Protect();
}
form.Protect();

#if NET_4_0
if (validateRequestNewMode && !checked_form) {
Expand All @@ -114,14 +107,13 @@ public QueryParamCollection Form
ValidateNameValueCollection ("Form", query_string_nvc, RequestValidationSource.Form);
} else
#endif
if (validate_form && !checked_form)
{
checked_form = true;
ValidateNameValueCollection("Form", form);
}

return form;
if (validate_form && !checked_form)
{
checked_form = true;
ValidateNameValueCollection("Form", form);
}

return form;
}

public string Accept
Expand Down Expand Up @@ -228,11 +220,11 @@ bool IsContentType(string ct, bool starts_with)
return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase);
}

async Task LoadWwwForm()
async Task LoadWwwForm(WebROCollection form)
{
using (Stream input = GetSubStream(InputStream, _memoryStreamProvider))
using (Stream input = InputStream)
{
using (var ms = _memoryStreamProvider.CreateNew())
using (var ms = new MemoryStream())
{
await input.CopyToAsync(ms).ConfigureAwait(false);
ms.Position = 0;
Expand All @@ -252,31 +244,31 @@ async Task LoadWwwForm()
{
if (c == '&')
{
AddRawKeyValue(key, value);
AddRawKeyValue(form, key, value);
break;
}
else
value.Append((char)c);
}
if (c == -1)
{
AddRawKeyValue(key, value);
AddRawKeyValue(form, key, value);
return;
}
}
else if (c == '&')
AddRawKeyValue(key, value);
AddRawKeyValue(form, key, value);
else
key.Append((char)c);
}
if (c == -1)
AddRawKeyValue(key, value);
AddRawKeyValue(form, key, value);
}
}
}
}

void AddRawKeyValue(StringBuilder key, StringBuilder value)
void AddRawKeyValue(WebROCollection form, StringBuilder key, StringBuilder value)
{
string decodedKey = WebUtility.UrlDecode(key.ToString());
form.Add(decodedKey,
Expand All @@ -286,29 +278,13 @@ void AddRawKeyValue(StringBuilder key, StringBuilder value)
value.Length = 0;
}

WebROCollection form;

Dictionary<string, HttpPostedFile> files;

class WebROCollection : QueryParamCollection
{
bool got_id;
int id;

public bool GotID
{
get { return got_id; }
}

public int ID
{
get { return id; }
set
{
got_id = true;
id = value;
}
}
public void Protect()
{
//IsReadOnly = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
using IResponse = MediaBrowser.Model.Services.IResponse;
using System.Threading.Tasks;

namespace Emby.Server.Implementations.HttpServer.SocketSharp
{
Expand Down Expand Up @@ -384,8 +385,6 @@ private static string GetPathInfo(string fullPath, string mode, string appPath)
return fullPath;
}



private static string ResolvePathInfoFromMappedPath(string fullPath, string mappedPathRoot)
{
if (mappedPathRoot == null) return null;
Expand Down Expand Up @@ -456,12 +455,6 @@ public QueryParamCollection QueryString
get { return queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query)); }
}

private QueryParamCollection formData;
public QueryParamCollection FormData
{
get { return formData ?? (formData = this.Form); }
}

public bool IsLocal
{
get { return request.IsLocal; }
Expand Down Expand Up @@ -552,23 +545,6 @@ public IHttpFile[] Files
}
}

static Stream GetSubStream(Stream stream, IMemoryStreamFactory streamProvider)
{
if (stream is MemoryStream)
{
var other = (MemoryStream)stream;

byte[] buffer;
if (streamProvider.TryGetBuffer(other, out buffer))
{
return streamProvider.CreateNew(buffer);
}
return streamProvider.CreateNew(other.ToArray());
}

return stream;
}

public static string NormalizePathInfo(string pathInfo, string handlerPath)
{
if (handlerPath != null && pathInfo.TrimStart('/').StartsWith(
Expand Down
6 changes: 6 additions & 0 deletions Emby.Server.Implementations/IO/LibraryMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ private void StartWatchingPath(string path)
}
}

if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Android)
{
// causing crashing
return;
}

// Already being watched
if (_fileSystemWatchers.ContainsKey(path))
{
Expand Down
16 changes: 0 additions & 16 deletions Emby.Server.Implementations/IO/MemoryStreamProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,5 @@ public MemoryStream CreateNew()
{
return new MemoryStream();
}

public MemoryStream CreateNew(int capacity)
{
return new MemoryStream(capacity);
}

public MemoryStream CreateNew(byte[] buffer)
{
return new MemoryStream(buffer);
}

public bool TryGetBuffer(MemoryStream stream, out byte[] buffer)
{
buffer = stream.GetBuffer();
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ public override ResolverPriority Priority
/// <returns>MusicAlbum.</returns>
protected override MusicAlbum Resolve(ItemResolveArgs args)
{
if (!args.IsDirectory) return null;

// Avoid mis-identifying top folders
if (args.HasParent<MusicAlbum>()) return null;
if (args.Parent.IsRoot) return null;

var collectionType = args.GetCollectionType();

var isMusicMediaFolder = string.Equals(collectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase);

// If there's a collection type and it's not music, don't allow it.
Expand All @@ -68,6 +61,12 @@ protected override MusicAlbum Resolve(ItemResolveArgs args)
return null;
}

if (!args.IsDirectory) return null;

// Avoid mis-identifying top folders
if (args.HasParent<MusicAlbum>()) return null;
if (args.Parent.IsRoot) return null;

return IsMusicAlbum(args) ? new MusicAlbum() : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override Series Resolve(ItemResolveArgs args)
{
if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
{
if (args.Parent.IsRoot)
if (args.Parent != null && args.Parent.IsRoot)
{
// For now, return null, but if we want to allow this in the future then add some additional checks to guard against a misplaced tvshow.nfo
return null;
Expand All @@ -99,7 +99,7 @@ protected override Series Resolve(ItemResolveArgs args)
};
}

if (args.Parent.IsRoot)
if (args.Parent != null && args.Parent.IsRoot)
{
return null;
}
Expand Down
Loading

0 comments on commit 4095c06

Please sign in to comment.