private async Task ProcessFilesInternal(IEnumerable <IStorageItem> filesToOpen) { StorageApplicationPermissions.FutureAccessList.Clear(); var tracks = new List <PlayerTrack>(filesToOpen.Count()); foreach (StorageFile item in filesToOpen) { var cachedData = new VKSaverAudioFile(item); var info = await cachedData.GetMetadataAsync(); var track = new PlayerTrack { Title = info.Track.Title, Artist = info.Track.Artist, VKInfo = info.VK }; string token = StorageApplicationPermissions.FutureAccessList.Add(item); track.Source = $"vks-token:{token}"; tracks.Add(track); } await _playerService.PlayNewTracks(tracks, 0); }
private async Task ProcessFileAsync(StorageFile file, StorageFolder folder) { if (file.FileType == TEMP_FILES_EXTENSION) { try { await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch (Exception ex) { _logService.LogException(ex); } return; } else if (file.FileType != MusicCacheService.FILES_EXTENSION) { return; } StorageFile newFile = null; try { VKSaverAudio metadata = null; using (var audioFile = new VKSaverAudioFile(file)) { metadata = await audioFile.GetMetadataAsync(); using (var sourceStream = await audioFile.GetContentStreamAsync()) { newFile = await folder.CreateFileAsync( Path.GetFileNameWithoutExtension(file.Name) + TEMP_FILES_EXTENSION, CreationCollisionOption.ReplaceExisting); using (var fileStream = await newFile.OpenStreamForWriteAsync()) { await CopyStreamAsync(sourceStream, fileStream); } } } await newFile.RenameAsync(GetSafeFileName(metadata.Track.Title) + MP3_FILES_EXTENSION, NameCollisionOption.GenerateUniqueName); await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch (Exception ex) { _logService.LogException(ex); await newFile?.DeleteAsync(StorageDeleteOption.PermanentDelete); } }
private async Task <VKSaverTrack> ProcessVKSaverAudioFile(StorageFile file) { using (var audioFile = new VKSaverAudioFile(file)) { var metadata = await audioFile.GetMetadataAsync(); var track = new VKSaverTrack { Title = metadata.Track.Title.Trim() }; ProcessArtist(track, metadata.Track.Artist.Trim()); ProcessAlbum(track, UNKNOWN_ALBUM_NAME); ProcessGenre(track, metadata.VK.Genre == (AudioGenres)0 ? UNKNOWN_GENRE_NAME : metadata.VK.Genre.ToString()); ProcessVKInfo(track, metadata.VK); track.Duration = TimeSpan.FromTicks(metadata.Track.Duration); return(track); } }