Ejemplo n.º 1
0
        private bool EnableOrganization(FileSystemMetadata fileInfo, TvFileOrganizationOptions options)
        {
            var minFileBytes = options.MinFileSizeMb * 1024 * 1024;

            try
            {
                return _libraryManager.IsVideoFile(fileInfo.FullName) && fileInfo.Length >= minFileBytes;
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error organizing file {0}", ex, fileInfo.Name);
            }

            return false;
        }
Ejemplo n.º 2
0
        private void DeleteFile(FileSystemMetadata file, int retryCount)
        {
            if (retryCount >= 5)
            {
                return;
            }

            try
            {
                FileSystem.DeleteFile(file.FullName);
            }
            catch (IOException ex)
            {
                Logger.ErrorException("Error deleting partial stream file(s) {0}", ex, file.FullName);

                Thread.Sleep(100);
                DeleteFile(file, retryCount + 1);
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error deleting partial stream file(s) {0}", ex, file.FullName);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the image path.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="imageType">Type of the image.</param>
 /// <param name="file">The file.</param>
 public static void SetImagePath(this IHasImages item, ImageType imageType, FileSystemMetadata file)
 {
     item.SetImagePath(imageType, 0, file);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Ensures the name.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="fileInfo">The file information.</param>
 private static void EnsureName(BaseItem item, FileSystemMetadata fileInfo)
 {
     // If the subclass didn't supply a name, add it here
     if (string.IsNullOrEmpty(item.Name) && !string.IsNullOrEmpty(item.Path))
     {
         item.Name = GetDisplayName(fileInfo.Name, fileInfo.IsDirectory);
     }
 }
Ejemplo n.º 5
0
        private static void SetDateCreated(BaseItem item, IFileSystem fileSystem, FileSystemMetadata info)
        {
            var config = BaseItem.ConfigurationManager.GetMetadataConfiguration();

            if (config.UseFileCreationTimeForDateAdded)
            {
                item.DateCreated = fileSystem.GetCreationTimeUtc(info);
            }
            else
            {
                item.DateCreated = DateTime.UtcNow;
            }
        }
Ejemplo n.º 6
0
 private FileMetadata GetFile(FileSystemMetadata file)
 {
     return new FileMetadata
     {
         Id = file.FullName,
         Name = Path.GetFileName(file.FullName),
         MimeType = MimeTypes.GetMimeType(file.FullName)
     };
 }
Ejemplo n.º 7
0
        private RemoteImageInfo GetImageInfo(FileSystemMetadata xmlFile, CancellationToken cancellationToken)
        {
            var height = 225;
            var width = 400;
            var url = string.Empty;

            using (var streamReader = new StreamReader(xmlFile.FullName, Encoding.UTF8))
            {
                // Use XmlReader for best performance
                using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings
                {
                    CheckCharacters = false,
                    IgnoreProcessingInstructions = true,
                    IgnoreComments = true,
                    ValidationType = ValidationType.None
                }))
                {
                    reader.MoveToContent();

                    // Loop through each element
                    while (reader.Read())
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                            {
                                case "thumb_width":
                                    {
                                        var val = reader.ReadElementContentAsString();

                                        if (!string.IsNullOrWhiteSpace(val))
                                        {
                                            int rval;

                                            // int.TryParse is local aware, so it can be probamatic, force us culture
                                            if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
                                            {
                                                width = rval;
                                            }
                                        }
                                        break;
                                    }

                                case "thumb_height":
                                    {
                                        var val = reader.ReadElementContentAsString();

                                        if (!string.IsNullOrWhiteSpace(val))
                                        {
                                            int rval;

                                            // int.TryParse is local aware, so it can be probamatic, force us culture
                                            if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
                                            {
                                                height = rval;
                                            }
                                        }
                                        break;
                                    }

                                case "filename":
                                    {
                                        var val = reader.ReadElementContentAsString();
                                        if (!string.IsNullOrWhiteSpace(val))
                                        {
                                            url = TVUtils.BannerUrl + val;
                                        }
                                        break;
                                    }

                                default:
                                    reader.Skip();
                                    break;
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                return null;
            }

            return new RemoteImageInfo
            {
                Width = width,
                Height = height,
                ProviderName = Name,
                Url = url,
                Type = ImageType.Primary
            };
        }
Ejemplo n.º 8
0
        private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type)
        {
            return new InternalProfileInfo
            {
                Path = file.FullName,

                Info = new DeviceProfileInfo
                {
                    Id = file.FullName.ToLower().GetMD5().ToString("N"),
                    Name = _fileSystem.GetFileNameWithoutExtension(file),
                    Type = type
                }
            };
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Shoulds the ignore.
        /// </summary>
        /// <param name="fileInfo">The file information.</param>
        /// <param name="parent">The parent.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem parent)
        {
            var filename = fileInfo.Name;
            var isHidden = (fileInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
            var path = fileInfo.FullName;

            // Handle mac .DS_Store
            // https://github.com/MediaBrowser/MediaBrowser/issues/427
            if (filename.IndexOf("._", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return true;
            }

            // Ignore hidden files and folders
            if (isHidden)
            {
                if (parent == null)
                {
                    var parentFolderName = Path.GetFileName(Path.GetDirectoryName(path));

                    if (string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
                    {
                        return false;
                    }
                    if (string.Equals(parentFolderName, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
                    {
                        return false;
                    }
                }

                // Sometimes these are marked hidden
                if (_fileSystem.IsRootPath(path))
                {
                    return false;
                }

                return true;
            }

            if (fileInfo.IsDirectory)
            {
                // Ignore any folders in our list
                if (IgnoreFolders.Contains(filename, StringComparer.OrdinalIgnoreCase))
                {
                    return true;
                }

                if (parent != null)
                {
                    // Ignore trailer folders but allow it at the collection level
                    if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) &&
                        !(parent is AggregateFolder) && !(parent is UserRootFolder))
                    {
                        return true;
                    }

                    if (string.Equals(filename, BaseItem.ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }

                    if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
                    {
                        return true;
                    }
                }
            }
            else
            {
                if (parent != null)
                {
                    // Don't resolve these into audio files
                    if (string.Equals(_fileSystem.GetFileNameWithoutExtension(filename), BaseItem.ThemeSongFilename) && _libraryManager.IsAudioFile(filename))
                    {
                        return true;
                    }
                }
                
                // Ignore samples
                var sampleFilename = " " + filename.Replace(".", " ", StringComparison.OrdinalIgnoreCase)
                    .Replace("-", " ", StringComparison.OrdinalIgnoreCase)
                    .Replace("_", " ", StringComparison.OrdinalIgnoreCase)
                    .Replace("!", " ", StringComparison.OrdinalIgnoreCase);

                if (sampleFilename.IndexOf(" sample ", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 10
0
        private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info)
        {
            var result = new FileSystemMetadata();

            result.Exists = info.Exists;
            result.FullName = info.FullName;
            result.Extension = info.Extension;
            result.Name = info.Name;

            if (result.Exists)
            {
                result.Attributes = info.Attributes;
                result.IsDirectory = info is DirectoryInfo || (result.Attributes & FileAttributes.Directory) == FileAttributes.Directory;

                var fileInfo = info as FileInfo;
                if (fileInfo != null)
                {
                    result.Length = fileInfo.Length;
                    result.DirectoryName = fileInfo.DirectoryName;
                }

                result.CreationTimeUtc = GetCreationTimeUtc(info);
                result.LastWriteTimeUtc = GetLastWriteTimeUtc(info);
            }
            else
            {
                result.IsDirectory = info is DirectoryInfo;
            }

            return result;
        }
Ejemplo n.º 11
0
 public DateTime GetLastWriteTimeUtc(FileSystemMetadata info)
 {
     return info.LastWriteTimeUtc;
 }
Ejemplo n.º 12
0
        public string GetFileNameWithoutExtension(FileSystemMetadata info)
        {
            if (info.IsDirectory)
            {
                return info.Name;
            }

            return Path.GetFileNameWithoutExtension(info.FullName);
        }
Ejemplo n.º 13
0
 public DateTime GetCreationTimeUtc(FileSystemMetadata info)
 {
     return info.CreationTimeUtc;
 }