public bool AddMediaMetadata(IMediaMetadata metadata) { var json = JsonConvert.SerializeObject(metadata); return(_twitterAccessor.TryPOSTJsonContent("https://upload.twitter.com/1.1/media/metadata/create.json", json)); }
/// <summary> /// Add metadata to a media that has been uploaded. /// </summary> public static bool AddMediaMetadata(IMediaMetadata metadata) { return(UploadQueryExecutor.AddMediaMetadata(metadata)); }
protected void CreateMediaWithRelationships(IMediaMetadata meta, Guid mediaId, Guid userId, string imageSavePath, bool saveChanges) { Guid artistCoverMediaId = Guid.Parse("00000000-0000-0000-0000-000000000001"); Guid albumCoverMediaId = Guid.Parse("00000000-0000-0000-0000-000000000002"); // Create/Update Genre. string genreName = meta.Genre; if (string.IsNullOrEmpty(genreName)) { genreName = "Unknown"; } var genre = _mediaDataContext.Get <Genre>().Where(x => x.Name == genreName).FirstOrDefault(); if (genre == null) { genre = new Genre { Id = Guid.NewGuid(), Name = genreName }; _mediaDataContext.Add(genre); } // Create/Update Artist. string artistName = meta.Artist; if (string.IsNullOrEmpty(artistName)) { artistName = "Unknown Artist"; } var artist = _mediaDataContext.Get <Artist>().Where(x => x.Name == artistName).FirstOrDefault(); if (artist == null) { artist = new Artist { Id = Guid.NewGuid(), Name = artistName, GenreId = genre.Id, Genre = genre }; _mediaDataContext.Add(artist); } // Create/Update Album. string albumName = meta.Album; if (string.IsNullOrEmpty(albumName)) { albumName = "Unknown Album"; } var album = _mediaDataContext.Get <Album>().Where(x => x.Name == albumName).FirstOrDefault(); if (album == null) { int year = 0; int.TryParse(meta.Year, out year); album = new Album { Id = Guid.NewGuid(), Name = albumName, ArtistId = artist.Id, Year = year, }; // Album cover image. if (meta.AlbumImagesUrl != null && meta.AlbumImagesUrl.Any()) { string albumImageUrl = meta.AlbumImagesUrl.FirstOrDefault().Value; IEnumerable <MediaImage> images = null; using (var imageStream = _localStorage.Open(albumImageUrl)) { images = ResizeAndCopyImage(imageStream, imageSavePath, "album", MediaFormatExtension.GetMimeType(MediaFormatExtension.ImageJpeg)); } if (images != null && images.Any()) { var imageGroup = new MediaImageGroup { UserId = userId }; _mediaDataContext.Add(imageGroup); _mediaDataContext.Add(new AlbumAndMediaImage { AlbumId = album.Id, IsCoverImage = true, MediaImageGroupId = imageGroup.Id }); foreach (var m in images) { m.ImageGroupId = imageGroup.Id; _mediaDataContext.Add(m); } } } _mediaDataContext.Add(album); } // Create/Update Song. string songName = meta.Song; if (string.IsNullOrEmpty(songName)) { albumName = "Unknown Song"; } int trackNumber = 0; int.TryParse(meta.Track, out trackNumber); var song = new Song { Id = Guid.NewGuid(), Name = songName, AlbumId = album.Id, TrackNumber = trackNumber, DurationSec = meta.DurationSec, MediaId = mediaId }; _mediaDataContext.Add(song); if (saveChanges) { _mediaDataContext.SaveChanges(); } }
/// <summary> /// Add metadata to a media that has been uploaded. /// </summary> public static bool AddMediaMetadata(IMediaMetadata metadata) { return UploadQueryExecutor.AddMediaMetadata(metadata); }