<commit_before>﻿using System;
using System.IO;
using NMaier.sdlna.FileMediaServer.Folders;
using NMaier.sdlna.Server;
using NMaier.sdlna.Server.Metadata;
using NMaier.sdlna.Util;

namespace NMaier.sdlna.FileMediaServer.Files
{
  internal class BaseFile : Logging, IMediaResource, IFileServerMediaItem, IMediaCover, IMetaInfo
  {

    private WeakReference _cover = new WeakReference(null);
    private static readonly LRUCache<string, Cover> coverCache = new LRUCache<string, Cover>(500);
    private DateTime? lastModified = null;
    private long? length = null;
    private readonly string title;



    protected BaseFile(BaseFolder aParent, FileInfo aFile, DlnaTypes aType, MediaTypes aMediaType)
    {
      Parent = aParent;
      Item = aFile;

      length = Item.Length;
      lastModified = Item.LastWriteTimeUtc;

      Type = aType;
      MediaType = aMediaType;

      title = System.IO.Path.GetFileNameWithoutExtension(Item.Name);
      if (string.IsNullOrEmpty(title)) {
        title = Item.Name;
      }
    }



    public Stream Content
    {
      get
      {
        return new FileStream(
          Item.FullName,
          FileMode.Open,
          FileAccess.Read,
          FileShare.ReadWrite | FileShare.Delete
          );
      }
    }
<commit_msg>Normalize title<commit_after>﻿using System;
using System.IO;
using NMaier.sdlna.FileMediaServer.Folders;
using NMaier.sdlna.Server;
using NMaier.sdlna.Server.Metadata;
using NMaier.sdlna.Util;

namespace NMaier.sdlna.FileMediaServer.Files
{
  internal class BaseFile : Logging, IMediaResource, IFileServerMediaItem, IMediaCover, IMetaInfo
  {

    private WeakReference _cover = new WeakReference(null);
    private static readonly LRUCache<string, Cover> coverCache = new LRUCache<string, Cover>(500);
    private DateTime? lastModified = null;
    private long? length = null;
    private readonly string title;



    protected BaseFile(BaseFolder aParent, FileInfo aFile, DlnaTypes aType, MediaTypes aMediaType)
    {
      Parent = aParent;
      Item = aFile;

      length = Item.Length;
      lastModified = Item.LastWriteTimeUtc;

      Type = aType;
      MediaType = aMediaType;

      title = System.IO.Path.GetFileNameWithoutExtension(Item.Name);
      if (string.IsNullOrEmpty(title)) {
        title = Item.Name;
      }
      try {
        title = Uri.UnescapeDataString(title);
      }
      catch (Exception) { }
      if (!title.Contains(" ")) {
        foreach (var c in new char[] { '_', '+', '.' }) {
          title = title.Replace(c, ' ');
        }
      }
    }



    public Stream Content
    {
      get
      {
        return new FileStream(
          Item.FullName,
          FileMode.Open,
          FileAccess.Read,
          FileShare.ReadWrite | FileShare.Delete
          );
      }
    }

{'fraction_non_alphanumeric': 0.09314775160599571, 'fraction_numerical': 0.0021413276231263384, 'mean_word_length': 2.616774193548387, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4792626', 'n_tokens_mistral': 880, 'n_tokens_neox': 835, 'n_words': 190}