Ejemplo n.º 1
0
        private async Task TryUploadMp3(SongUpload song, AlbumUpload album, int songNumber, string songId)
        {
            var mp3Uri = default(Uri);

            try
            {
                var uri = await cdnManagerService.UploadMp3Async(song.Address, album.Artist, album.Name, songNumber, song.FileName);

                mp3Uri = uri;
            }
            catch (Exception error)
            {
                logger.LogError(error, "Unable to upload song MP3. {songId}, {songAddress}, {fileName}, {album}, {artist}", songId, song.Address, song.FileName, album.Name, album.Artist);
                await TryDeleteSong(songId);
            }

            if (mp3Uri != null)
            {
                await TryUpdateSongUri(songId, mp3Uri);
            }
        }
Ejemplo n.º 2
0
        public async Task <string> Upload([FromBody] AlbumUpload album)
        {
            // Put the album art on the CDN.
            var albumArtUriCdn = await cdnManagerService.UploadAlbumArtAsync(album.AlbumArtUri, album.Artist, album.Name, ".jpg");

            // Store the new album if it doesn't exist already.
            var existingAlbum = await DbSession.Query <Album>()
                                .FirstOrNoneAsync(a => a.Name == album.Name && a.Artist == album.Artist);

            if (existingAlbum == null)
            {
                existingAlbum = new Album();
            }

            // Store the Artist as well.
            var existingArtist = await DbSession.Query <Artist>()
                                 .FirstOrDefaultAsync(a => a.Name == album.Artist);

            if (existingArtist == null)
            {
                existingArtist = new Artist
                {
                    Bio  = "",
                    Name = album.Artist
                };
                await DbSession.StoreAsync(existingArtist);
            }

            existingAlbum.AlbumArtUri     = albumArtUriCdn;
            existingAlbum.Artist          = album.Artist;
            existingAlbum.BackgroundColor = album.BackColor;
            existingAlbum.ForegroundColor = album.ForeColor;
            existingAlbum.MutedColor      = album.MutedColor;
            existingAlbum.Name            = album.Name;
            existingAlbum.TextShadowColor = album.TextShadowColor;
            existingAlbum.SongCount       = album.Songs.Count + existingAlbum.SongCount;

            if (string.IsNullOrEmpty(existingAlbum.Id))
            {
                await DbSession.StoreAsync(existingAlbum);
            }

            // Store the songs in the DB.
            var songNumber   = 1;
            var mp3sToUpload = new List <(SongUpload upload, Song song)>(album.Songs.Count);

            foreach (var albumSong in album.Songs)
            {
                var(english, hebrew) = albumSong.FileName.GetEnglishAndHebrew();
                var song = new Song
                {
                    Album                 = album.Name,
                    Artist                = album.Artist,
                    AlbumArtUri           = albumArtUriCdn,
                    CommunityRankStanding = CommunityRankStanding.Normal,
                    Genres                = album.Genres.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
                    Name        = english,
                    HebrewName  = hebrew,
                    Number      = songNumber,
                    PurchaseUri = album.PurchaseUrl,
                    UploadDate  = DateTime.UtcNow,
                    AlbumId     = existingAlbum.Id,
                    ArtistId    = existingArtist.Id,
                    AlbumColors = new AlbumColors
                    {
                        Background = existingAlbum.BackgroundColor,
                        Foreground = existingAlbum.ForegroundColor,
                        Muted      = existingAlbum.MutedColor,
                        TextShadow = existingAlbum.TextShadowColor
                    }
                };
                await DbSession.StoreAsync(song);

                mp3sToUpload.Add((albumSong, song));
                songNumber++;
            }

            await DbSession.SaveChangesAsync();

            // Queue up the MP3s to upload to the CDN now that the songs are saved in the database.
            mp3sToUpload.ForEach(mp3 => songUploadService.QueueMp3Upload(mp3.upload, album, mp3.song.Number, mp3.song.Id !));

            return(existingAlbum.Id !);
        }
Ejemplo n.º 3
0
 public void QueueMp3Upload(SongUpload song, AlbumUpload album, int songNumber, string songId)
 {
     backgroundQueue.Enqueue(_ => TryUploadMp3(song, album, songNumber, songId));
 }