예제 #1
0
 public ImportedAlbumOptions(InspectedAlbum inspectedAlbum)
 {
     ImportedDbAlbumId = inspectedAlbum.ImportedAlbum.Id;
     MergedAlbumId     = inspectedAlbum.MergedAlbumId;
     MergeTracks       = inspectedAlbum.MergeTracks;
     SelectedLanguage  = inspectedAlbum.SelectedLanguage;
 }
예제 #2
0
 public ImportedAlbumOptions(InspectedAlbum inspectedAlbum)
 {
     ImportedDbAlbumId = inspectedAlbum.ImportedAlbum.Id;
     MergedAlbumId = inspectedAlbum.MergedAlbumId;
     MergeTracks = inspectedAlbum.MergeTracks;
     SelectedLanguage = inspectedAlbum.SelectedLanguage;
 }
예제 #3
0
        public ActionResult AcceptImported(InspectedAlbum album, string commit)
        {
            if (commit != "Accept") {

                //var options = albums.Select(a => new ImportedAlbumOptions(a)).ToArray();
                var options = new ImportedAlbumOptions(album);
                var inspectResult = Service.Inspect(options);

                return View("PrepareForImport", inspectResult);

            }

            var ids = new ImportedAlbumOptions(album);
            var selectedSongIds = (album.Tracks != null ? album.Tracks.Where(t => t.Selected).Select(t => t.ExistingSong.Id).ToArray() : new int[] { });

            Service.AcceptImportedAlbum(ids, selectedSongIds);

            TempData.SetSuccessMessage("Imported album approved successfully.");

            return RedirectToAction("Index");
        }
예제 #4
0
		private AlbumContract AcceptImportedAlbum(ISession session, ContentLanguageSelection languageSelection, 
			InspectedAlbum acceptedAlbum, int[] selectedSongIds) {
			
			Album album;
			var diff = new AlbumDiff(false);

			if (acceptedAlbum.MergedAlbum == null) {

				album = new Album(new LocalizedString(acceptedAlbum.ImportedAlbum.Title, languageSelection));

				if (languageSelection != ContentLanguageSelection.Unspecified)
					album.Names.SortNames.DefaultLanguage = languageSelection;

				album.DiscType = DiscType.Unknown;
				diff.Names = true;
				session.Save(album);

			} else {

				album = session.Load<Album>(acceptedAlbum.MergedAlbum.Id);

				if (!album.Names.HasName(acceptedAlbum.ImportedAlbum.Title)) {
					album.CreateName(acceptedAlbum.ImportedAlbum.Title, languageSelection);
					diff.Names = true;
				}

			}

			foreach (var inspectedArtist in acceptedAlbum.Artists) {

				if (inspectedArtist.ExistingArtist != null) {

					var artist = session.Load<Artist>(inspectedArtist.ExistingArtist.Id);

					if (!artist.HasAlbum(album)) {
						session.Save(artist.AddAlbum(album));
						diff.Artists = true;
					}

				} else {
					album.AddArtist(inspectedArtist.Name, false, ArtistRoles.Default);
					diff.Artists = true;
				}

			}

			if (acceptedAlbum.MergedAlbum == null || acceptedAlbum.MergeTracks) {

				foreach (var inspectedTrack in acceptedAlbum.Tracks) {
					if (AcceptImportedSong(session, album, inspectedTrack, languageSelection, selectedSongIds))
						diff.Tracks = true;
				}

			}

			var importedAlbum = session.Load<MikuDbAlbum>(acceptedAlbum.ImportedAlbum.Id);
			importedAlbum.Status = AlbumStatus.Approved;

			if (importedAlbum.CoverPicture != null && album.CoverPictureData == null) {

				album.CoverPictureData = importedAlbum.CoverPicture;

				using (var stream = new MemoryStream(album.CoverPictureData.Bytes)) {
					var thumbs = ImageHelper.GenerateThumbs(stream, new[] { 250 });
					if (thumbs.Any()) {
						album.CoverPictureData.Thumb250 = new PictureThumb250(thumbs.First().Bytes);
					}
				}

				diff.Cover = true;
			}

			if (acceptedAlbum.ImportedAlbum.Data.ReleaseYear != null && album.OriginalReleaseDate.Year == null) {
				album.OriginalReleaseDate.Year = acceptedAlbum.ImportedAlbum.Data.ReleaseYear;
				diff.OriginalRelease = true;
			}

			if (!album.WebLinks.Any(w => w.Url.Contains("mikudb.com"))) {
				album.CreateWebLink("MikuDB", acceptedAlbum.ImportedAlbum.SourceUrl, WebLinkCategory.Reference);
				diff.WebLinks = true;
			}

			album.UpdateArtistString();

			AuditLog(string.Format("accepted imported album '{0}'", acceptedAlbum.ImportedAlbum.Title), session);
			AddEntryEditedEntry(session, album, EntryEditEvent.Created);

			Services.Albums.Archive(session, album, diff, AlbumArchiveReason.AutoImportedFromMikuDb);

			session.Update(album);
			session.Update(importedAlbum);

			return new AlbumContract(album, PermissionContext.LanguagePreference);

		}
예제 #5
0
		private InspectedAlbum Inspect(ISession session, MikuDbAlbum imported, ImportedAlbumOptions options) {

			Album albumMatch;
			var foundAlbums = FindAlbums(session, imported);
			switch (options.MergedAlbumId) {
				case null:
					albumMatch = foundAlbums.FirstOrDefault();
					break;
				case 0:
					albumMatch = null;
					break;
				default:
					albumMatch = session.Load<Album>(options.MergedAlbumId);
					if (!foundAlbums.Contains(albumMatch))
						foundAlbums.Add(albumMatch);
					break;
			}

			var importedContract = new MikuDbAlbumContract(imported);
			var data = importedContract.Data;

			var artists = data.ArtistNames.Concat(data.VocalistNames).Concat(!string.IsNullOrEmpty(data.CircleName) ? new[] { data.CircleName } : new string[] {})
				.Select(a => InspectArtist(session, a))
				.ToArray();

			var matchedArtists = artists.Where(a => a.ExistingArtist != null).Select(a => a.ExistingArtist).ToArray();

			var tracks = data.Tracks.Select(t => InspectTrack(session, t, matchedArtists, albumMatch)).ToArray();

			var result = new InspectedAlbum(importedContract);
			result.MergeTracks = options.MergeTracks ?? true;

			if (albumMatch != null) {
				result.MergedAlbum = new AlbumContract(albumMatch, PermissionContext.LanguagePreference);
				result.MergedAlbumId = albumMatch.Id;
			}

			result.ExistingAlbums = foundAlbums.Select(a => new AlbumContract(a, PermissionContext.LanguagePreference))
				.Concat(new[] { new AlbumContract { Name = "Nothing" } }).ToArray();

			result.Artists = artists.Select(a => a.InspectedArtist).ToArray();
			result.Tracks = tracks;

			return result;

		}
예제 #6
0
 public PrepareAlbumsForImport(InspectedAlbum album)
 {
     Album = album;
 }