AudioBookFileInfo.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. namespace Emby.Naming.AudioBook
  3. {
  4. /// <summary>
  5. /// Represents a single video file.
  6. /// </summary>
  7. public class AudioBookFileInfo : IComparable<AudioBookFileInfo>
  8. {
  9. /// <summary>
  10. /// Initializes a new instance of the <see cref="AudioBookFileInfo"/> class.
  11. /// </summary>
  12. /// <param name="path">Path to audiobook file.</param>
  13. /// <param name="container">File type.</param>
  14. /// <param name="partNumber">Number of part this file represents.</param>
  15. /// <param name="chapterNumber">Number of chapter this file represents.</param>
  16. public AudioBookFileInfo(string path, string container, int? partNumber = default, int? chapterNumber = default)
  17. {
  18. Path = path;
  19. Container = container;
  20. PartNumber = partNumber;
  21. ChapterNumber = chapterNumber;
  22. }
  23. /// <summary>
  24. /// Gets or sets the path.
  25. /// </summary>
  26. /// <value>The path.</value>
  27. public string Path { get; set; }
  28. /// <summary>
  29. /// Gets or sets the container.
  30. /// </summary>
  31. /// <value>The container.</value>
  32. public string Container { get; set; }
  33. /// <summary>
  34. /// Gets or sets the part number.
  35. /// </summary>
  36. /// <value>The part number.</value>
  37. public int? PartNumber { get; set; }
  38. /// <summary>
  39. /// Gets or sets the chapter number.
  40. /// </summary>
  41. /// <value>The chapter number.</value>
  42. public int? ChapterNumber { get; set; }
  43. /// <inheritdoc />
  44. public int CompareTo(AudioBookFileInfo? other)
  45. {
  46. if (ReferenceEquals(this, other))
  47. {
  48. return 0;
  49. }
  50. if (ReferenceEquals(null, other))
  51. {
  52. return 1;
  53. }
  54. var chapterNumberComparison = Nullable.Compare(ChapterNumber, other.ChapterNumber);
  55. if (chapterNumberComparison != 0)
  56. {
  57. return chapterNumberComparison;
  58. }
  59. var partNumberComparison = Nullable.Compare(PartNumber, other.PartNumber);
  60. if (partNumberComparison != 0)
  61. {
  62. return partNumberComparison;
  63. }
  64. return string.Compare(Path, other.Path, StringComparison.Ordinal);
  65. }
  66. }
  67. }