diff --git a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs index 0ceea2f10..5807b0ac4 100644 --- a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs +++ b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs @@ -27,6 +27,8 @@ protected override void MainDbUpgrade() .WithColumn("Overview").AsString().Nullable() .WithColumn("AirTime").AsString().Nullable() .WithColumn("Images").AsString() + .WithColumn("RootFolderId").AsInt32() + .WithColumn("Folder").AsString().NotNullable() .WithColumn("Path").AsString().Unique() .WithColumn("Monitored").AsBoolean() .WithColumn("QualityProfileId").AsInt32() diff --git a/NzbDrone.Core/Datastore/TableMapping.cs b/NzbDrone.Core/Datastore/TableMapping.cs index 6406bbeea..dc6f5baf3 100644 --- a/NzbDrone.Core/Datastore/TableMapping.cs +++ b/NzbDrone.Core/Datastore/TableMapping.cs @@ -41,7 +41,8 @@ public static void Map() Mapper.Entity().RegisterModel("History") .HasOne(h => h.Episode, h => h.EpisodeId); - Mapper.Entity().RegisterModel("Series"); + Mapper.Entity().RegisterModel("Series") + .HasOne(s => s.RootFolder, s => s.RootFolderId); Mapper.Entity().RegisterModel("Seasons"); Mapper.Entity().RegisterModel("Episodes"); diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index c9b104617..d7b516eb5 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -83,7 +83,6 @@ public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = f parseResult.Quality = episodeFile.Quality; parseResult.Episodes = episodes; - if (newDownload) { _eventAggregator.Publish(new EpisodeDownloadedEvent(parseResult)); @@ -91,7 +90,5 @@ public EpisodeFile MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = f return episodeFile; } - - } } \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index 0c6b7ed19..1665c6301 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -28,7 +28,6 @@ public class MediaFileService : IMediaFileService, IHandleAsync GetFilesBySeason(int seriesId, int seasonNumber) return _mediaFileRepository.GetFilesBySeason(seriesId, seasonNumber); } - - public void HandleAsync(SeriesDeletedEvent message) { var files = GetFilesBySeries(message.Series.Id); diff --git a/NzbDrone.Core/Tv/Series.cs b/NzbDrone.Core/Tv/Series.cs index 732e7b6f4..fad14707a 100644 --- a/NzbDrone.Core/Tv/Series.cs +++ b/NzbDrone.Core/Tv/Series.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using Marr.Data; using NzbDrone.Core.Datastore; using NzbDrone.Core.MetadataSource.Trakt; using NzbDrone.Core.Model; using NzbDrone.Core.Qualities; +using NzbDrone.Core.RootFolders; namespace NzbDrone.Core.Tv @@ -25,13 +27,11 @@ public Series() public int TvDbId { get; set; } public int TvRageId { get; set; } public string ImdbId { get; set; } - public string Title { get; set; } public string CleanTitle { get; set; } public SeriesStatusType Status { get; set; } public string Overview { get; set; } public String AirTime { get; set; } - public string Path { get; set; } public bool Monitored { get; set; } public int QualityProfileId { get; set; } public bool SeasonFolder { get; set; } @@ -44,9 +44,15 @@ public Series() public string Network { get; set; } public DateTime? CustomStartDate { get; set; } public bool UseSceneNumbering { get; set; } - public string TitleSlug { get; set; } + public int RootFolderId { get; set; } + public string Folder { get; set; } + public LazyLoaded RootFolder { get; set; } + + //Todo: Store the root folder + folderName + public string Path { get; set; } + //Todo: This should be a double since there are timezones that aren't on a full hour offset public int UtcOffset { get; set; } diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 717d5a238..e0d10b523 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -1,12 +1,17 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using Marr.Data; using NLog; +using NzbDrone.Common; using NzbDrone.Common.EnsureThat; using NzbDrone.Common.Eventing; using NzbDrone.Core.Configuration; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Model; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.RootFolders; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv @@ -29,15 +34,18 @@ public class SeriesService : ISeriesService, IHandleAsync private readonly IConfigService _configService; private readonly IProvideSeriesInfo _seriesInfoProxy; private readonly IEventAggregator _eventAggregator; + private readonly DiskProvider _diskProvider; private readonly Logger _logger; - public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, IProvideSeriesInfo seriesInfoProxy, - IEventAggregator eventAggregator, Logger logger) + public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, + IProvideSeriesInfo seriesInfoProxy, IEventAggregator eventAggregator, + DiskProvider diskProvider, Logger logger) { _seriesRepository = seriesRepository; _configService = configServiceService; _seriesInfoProxy = seriesInfoProxy; _eventAggregator = eventAggregator; + _diskProvider = diskProvider; _logger = logger; } @@ -80,6 +88,13 @@ public void AddSeries(Series newSeries) { Ensure.That(() => newSeries).IsNotNull(); + //Todo: If Path is null we need to create the path + if(String.IsNullOrWhiteSpace(newSeries.Folder)) + { + newSeries.Folder = FileNameBuilder.CleanFilename(newSeries.Title); + _diskProvider.CreateDirectory(Path.Combine(newSeries.RootFolder.Value.Path, newSeries.Folder)); + } + _logger.Info("Adding Series [{0}] Path: [{1}]", newSeries.Title, newSeries.Path); newSeries.Monitored = true; diff --git a/UI/AddSeries/New/SearchResultView.js b/UI/AddSeries/New/SearchResultView.js index 100ea6bb2..48eaf2347 100644 --- a/UI/AddSeries/New/SearchResultView.js +++ b/UI/AddSeries/New/SearchResultView.js @@ -22,13 +22,10 @@ define(['app', 'Shared/NotificationCollection', 'Series/SeriesCollection'], func addSeries: function () { var quality = this.ui.qualityProfile.val(); - - //Todo: This will create an invalid path on linux... - var rootPath = this.ui.rootFolder.find(":selected").text(); - var path = rootPath + "\\" + this.model.get('title'); + var rootFolderId = this.ui.rootFolder.val(); this.model.set('qualityProfileId', quality); - this.model.set('path', path); + this.model.set('rootFolderId', rootFolderId); var self = this;