Example #1
0
        public override IClip GetClip(ISecurityContext securityContext, IMediaFactory mediaFactory, IMetadataRepository mediaItemRepository, IArtist artist, IAlbum album)
        {
            var clip = mediaItemRepository.GetByTarget<IClip>(Location).FirstOrDefault();
            if (clip != null)
            {
                return clip;
            }

            var name = GetClipName();
            var summary = string.Empty;
            var number = GetClipNumber();
            var date = GetDate();
            var duration = file != null && file.Properties != null ? file.Properties.Duration : TimeSpan.FromMinutes(5);
            var height = file != null && file.Properties != null ? (uint)file.Properties.VideoHeight : 480;
            var width = file != null && file.Properties != null ? (uint)file.Properties.VideoWidth : 640;

            var builder = new MediaItemBuilder<IClip>(securityContext, mediaFactory)
                .Identity(name, summary, date, date, number)
                .Size(duration, height, width)
                .Target(Location, Type.Name);

            return builder.ToMediaItem();
        }
Example #2
0
        public virtual IAlbum GetAlbum(ISecurityContext securityContext, IMediaFactory mediaFactory, IMetadataRepository mediaItemRepository, IArtist artist)
        {
            IAlbum album = null;
            var clip = mediaItemRepository.GetByTarget<IClip>(Location).FirstOrDefault();
            if (clip != null)
            {
                album = mediaItemRepository.GetByLocation<IAlbum>(clip.Catalog);
                if (album != null)
                    return album;
            }

            var albumName = GetAlbumName();
            var summary = string.Empty;
            album = mediaItemRepository.GetByName<IAlbum>(albumName).FirstOrDefault();
            if (album != null)
            {
                return album;
            }

            var albumNumber = GetAlbumNumber();
            var date = GetDate();

            var builder = new MediaItemBuilder<IAlbum>(securityContext, mediaFactory)
                .Identity(albumName, summary, date, date, albumNumber)
                .Creator(artist.Location, artist.Name);

            return builder.ToMediaItem();
        }
        public IPlaylistItemViewModel ToPlaylistItem(ISecurityContext securityContext, IMediaFactory mediaFactory, uint number)
        {
            var builder = new MediaItemBuilder<IPlaylistItem>(securityContext, mediaFactory)
                .Identity(Name, Summary, item.FromDate, item.ToDate, number)
                .Size(item.Duration, item.Height, item.Width)
                .Creator(item.Creator, item.CreatorName)
                .Catalog(item.Catalog, item.CatalogName)
                .Target(item.Target, item.TargetType)
                .Thumbnail(item.Thumbnail, item.ThumbnailData);

            var playlistItem = builder.ToMediaItem();
            return new PlaylistItemViewModel(controller, playlistItem);
        }
        public IPlaylistViewModel ToPlaylist(ISecurityContext securityContext, IMediaFactory mediaFactory)
        {
            var date = DateTime.Now.ToUniversalTime();

            var builder = new MediaItemBuilder<IPlaylist>(securityContext, mediaFactory)
                .Identity(Name, Summary, date, date, 0, item.Location)
                .Thumbnail(item.Thumbnail, item.ThumbnailData);

            var playlist = builder.ToMediaItem();
            var playlistItems = new List<IPlaylistItemViewModel> { ToPlaylistItem(securityContext, mediaFactory, 1) };
            return new PlaylistViewModel(controller, playlist, playlistItems);
        }
Example #5
0
        public override ITrack GetTrack(ISecurityContext securityContext, IMediaFactory mediaFactory, IMetadataRepository mediaItemRepository, IAudioStreamFactory audioStreamFactory, IArtist artist, IAlbum album)
        {
            var track = mediaItemRepository.GetByTarget<ITrack>(Location).FirstOrDefault();
            //if (track != null)
                //return track;

            if (id3v2Tag == null)
            {
                if (track != null)
                    return track;

                var builder = new MediaItemBuilder<ITrack>(securityContext, mediaFactory)
                    .Identity("Unknown", string.Empty)
                    .Creator(artist.Location, artist.Name)
                    .Catalog(album.Location, album.Name)
                    .Target(Location, Type.Name);

                return builder.ToMediaItem();
            }

            var name = id3v2Tag.Title != null ? id3v2Tag.Title : "Unknown Track";
            var summary = id3v2Tag.Lyrics ?? string.Empty;
            
            var recordDate = DateTime.MinValue;
            if (id3v2Tag != null && id3v2Tag.RecordingDate > DateTime.MinValue)
                recordDate = id3v2Tag.RecordingDate;
            else if (id3v1Tag != null && id3v1Tag.Year >= DateTime.MinValue.Year && id3v1Tag.Year <= DateTime.MaxValue.Year)
                recordDate = new DateTime((int)id3v1Tag.Year, 1, 1);

            var releaseDate = DateTime.MinValue;
            if (id3v2Tag != null && id3v2Tag.ReleaseDate > DateTime.MinValue)
                releaseDate = id3v2Tag.ReleaseDate;
            else if (id3v1Tag != null && id3v1Tag.Year >= DateTime.MinValue.Year && id3v1Tag.Year <= DateTime.MaxValue.Year)
                releaseDate = new DateTime((int)id3v1Tag.Year, 1, 1);

            var number = id3v2Tag.Track;
            var duration = id3v2Tag.Duration;
            if (duration == TimeSpan.Zero)
            {
                using (var audioStream = audioStreamFactory.CreateAudioStream(Location))
                {
                    if (audioStream != null)
                    {
                        duration = audioStream.Duration;
                    }
                }
            }

            var thumbnail = Guid.Empty.ToUrn();
            var thumbnailData = id3v2Tag.Pictures != null && id3v2Tag.Pictures.Length > 0 ? id3v2Tag.Pictures[0].Data.ToArray() : new byte[0];

            var trackId = track != null ? track.Location : Guid.NewGuid().ToUrn();

            var fullBuilder = new MediaItemBuilder<ITrack>(securityContext, mediaFactory)
                .Identity(name, summary, recordDate, releaseDate, number, trackId)
                .Size(duration)
                .Creator(artist.Location, artist.Name)
                .Catalog(album.Location, album.Name)
                .Target(Location, Type.Name)
                .Thumbnail(thumbnail, thumbnailData);

            return fullBuilder.ToMediaItem();
        }
Example #6
0
        public override IAlbum GetAlbum(ISecurityContext securityContext, IMediaFactory mediaFactory, IMetadataRepository mediaItemRepository, IArtist artist)
        {
            IAlbum album = null;
            var track = mediaItemRepository.GetByTarget<ITrack>(Location).FirstOrDefault();
            if (track != null)
            {
                album = mediaItemRepository.GetByLocation<IAlbum>(track.Catalog);
                if (album != null)
                    return album;
            }

            var albumTitle = "Unknown Album";
            var summary = string.Empty;
            //var albumTag = GetTags().Where(x => x.Type == Id3v2TagType.Album).FirstOrDefault();
            if (id3v2Tag != null && id3v2Tag.Album != null)
            {
                albumTitle = id3v2Tag.Album; //albumTag.Tuple.ToString();
                album = mediaItemRepository.GetByCreatorAndName<IAlbum>(artist.Location, albumTitle);
                if (album != null)
                    return album;
            }

            var builder = new MediaItemBuilder<IAlbum>(securityContext, mediaFactory)
                .Identity(albumTitle, summary)
                .Creator(artist.Location, artist.Name);

            return builder.ToMediaItem();
        }
Example #7
0
        public override IArtist GetArtist(ISecurityContext securityContext, IMediaFactory mediaFactory, IMetadataRepository mediaItemRepository)
        {
            IArtist artist = null;
            var track = mediaItemRepository.GetByTarget<ITrack>(Location).FirstOrDefault();
            if (track != null)
            {
                artist = mediaItemRepository.GetByLocation<IArtist>(track.Creator);
                if (artist != null)
                    return artist;
            }

            if (id3v2Tag == null || id3v2Tag.JoinedPerformers == null)
                return new MediaItemBuilder<IArtist>(securityContext, mediaFactory).GetDefault();

            var artistName = id3v2Tag.JoinedPerformers;
            var summary = string.Empty;
            artist = mediaItemRepository.GetByName<IArtist>(artistName).FirstOrDefault();
            if (artist != null)
                return artist;

            var builder = new MediaItemBuilder<IArtist>(securityContext, mediaFactory)
                .Identity(artistName, summary);

            return builder.ToMediaItem();
        }
        private void clipListBoxItem_DoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                var element = e.OriginalSource as UIElement;
                if (element == null)
                    return;

                var listBoxItem = element.FindContainingItem<ListBoxItem>();
                if (listBoxItem == null)
                    return;

                var clipViewModel = listBoxItem.DataContext as IClipViewModel;
                if (clipViewModel == null)
                    return;

                var summary = string.Empty;
                var thumbnail = Guid.Empty.ToUrn();
                var thumbnailData = new byte[0];

                var album = mediaItemController.GetAlbum(clipViewModel.Id);
                if (album != null)
                {
                    summary = "Based on: " + album.Name;
                    thumbnail = album.Thumbnail;
                    thumbnailData = album.ThumbnailData;
                }

                var date = DateTime.Now.ToUniversalTime();

                var builder = new MediaItemBuilder<IPlaylist>(securityContext, mediaFactory)
                    .Identity(clipViewModel.Name, summary, date, date, 1)
                    .Size(clipViewModel.Duration)
                    .Thumbnail(thumbnail, thumbnailData);

                var playlist = builder.ToMediaItem();
                var playlistItem = clipViewModel.ToPlaylistItem(securityContext, mediaFactory, 1);
                var playlistViewModel = new PlaylistViewModel(mediaItemController, playlist, new List<IPlaylistItemViewModel> { playlistItem });

                var taskViewModel = taskController.GetPlaylistViewModel(playlistViewModel);
                taskResultView.Playlist(taskViewModel, playlistViewModel);
            }
            catch (Exception ex)
            {
                logger.Error("  SearchResultView.clipListBoxItem_DoubleClick", ex);
            }
        }