Skip to content

Commit 45ce50d

Browse files
committed
🧱 Update to .Net 8 GA
1 parent 5652b98 commit 45ce50d

14 files changed

+74
-113
lines changed

Nitefox.App/Ffmpeg/FfmpegService.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,8 @@
1616
using SharpCompress.Readers;
1717
namespace Nitefox.App.Ffmpeg;
1818

19-
public class FfmpegService
19+
public class FfmpegService(NitefoxConfig nitefoxConfig)
2020
{
21-
private readonly NitefoxConfig _nitefoxConfig;
22-
23-
public FfmpegService(NitefoxConfig nitefoxConfig)
24-
{
25-
_nitefoxConfig = nitefoxConfig;
26-
27-
}
28-
2921
public async Task<bool> StreamConvert(string url, string fileName)
3022
{
3123
return await FFMpegArguments
@@ -38,14 +30,14 @@ public void ConfigureFfmpeg()
3830
{
3931
GlobalFFOptions.Configure(new FFOptions
4032
{
41-
BinaryFolder = _nitefoxConfig.FfmpegLocation,
42-
TemporaryFilesFolder = _nitefoxConfig.TempFilesLocation
33+
BinaryFolder = nitefoxConfig.FfmpegLocation,
34+
TemporaryFilesFolder = nitefoxConfig.TempFilesLocation
4335
});
4436
}
4537

4638
public async Task<bool> DownloadFfmpeg()
4739
{
48-
if (new DirectoryInfo(_nitefoxConfig.FfmpegLocation).EnumerateFiles()
40+
if (new DirectoryInfo(nitefoxConfig.FfmpegLocation).EnumerateFiles()
4941
.Count() >= 3)
5042
{
5143
return true;
@@ -76,7 +68,7 @@ public async Task<bool> DownloadFfmpeg()
7668
releaseAsset = release.Assets.First(asset => asset.Name.EndsWith("osx-arm64.zip"));
7769
}
7870

79-
var downloadInfo = await AssetDownloader.Instance.DownloadAssetAsync(releaseAsset, _nitefoxConfig.FfmpegLocation);
71+
var downloadInfo = await AssetDownloader.Instance.DownloadAssetAsync(releaseAsset, nitefoxConfig.FfmpegLocation);
8072

8173
await Task.Run(async () =>
8274
{
@@ -87,7 +79,7 @@ await Task.Run(async () =>
8779
{
8880
if (!reader.Entry.IsDirectory)
8981
{
90-
reader.WriteEntryToDirectory(_nitefoxConfig.FfmpegLocation, new ExtractionOptions()
82+
reader.WriteEntryToDirectory(nitefoxConfig.FfmpegLocation, new ExtractionOptions()
9183
{
9284
ExtractFullPath = true,
9385
Overwrite = true

Nitefox.App/Media/MediaDownloader.cs

+20-32
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,16 @@
1717

1818
namespace Nitefox.App.Media;
1919

20-
public class MediaDownloader
20+
public class MediaDownloader(
21+
IFileService fileService,
22+
FfmpegService ffmpegService,
23+
NitefoxConfig nitefoxConfig,
24+
MetadataService metadataService)
2125
{
22-
private readonly IFileService _fileService;
23-
private readonly DataStore _mediaDataStore;
24-
private readonly FfmpegService _ffmpegService;
25-
private readonly NitefoxConfig _nitefoxConfig;
26-
private readonly MetadataService _metadataService;
27-
28-
public MediaDownloader(
29-
IFileService fileService,
30-
FfmpegService ffmpegService,
31-
NitefoxConfig nitefoxConfig,
32-
MetadataService metadataService)
33-
{
34-
_fileService = fileService;
35-
_ffmpegService = ffmpegService;
36-
_nitefoxConfig = nitefoxConfig;
37-
_metadataService = metadataService;
38-
_mediaDataStore = new DataStore($"{_nitefoxConfig.DownloadLocation}downloads.json",
39-
reloadBeforeGetCollection: true);
40-
}
4126

27+
private readonly DataStore _mediaDataStore = new ($"{nitefoxConfig.DownloadLocation}downloads.json",
28+
reloadBeforeGetCollection: true);
29+
4230
public async Task<TrackDownload> Download(string title, string url, string author, string? collection = null)
4331
{
4432
var trackDownload = new TrackDownload
@@ -51,12 +39,12 @@ public async Task<TrackDownload> Download(string title, string url, string autho
5139

5240
try
5341
{
54-
await _ffmpegService.DownloadFfmpeg();
42+
await ffmpegService.DownloadFfmpeg();
5543

56-
_ffmpegService.ConfigureFfmpeg();
57-
_fileService.SetupDirectories();
44+
ffmpegService.ConfigureFfmpeg();
45+
fileService.SetupDirectories();
5846

59-
var streamUrl = await _metadataService.GetYoutubeSongStream(url);
47+
var streamUrl = await metadataService.GetYoutubeSongStream(url);
6048

6149
if (string.IsNullOrWhiteSpace(streamUrl))
6250
{
@@ -65,12 +53,12 @@ public async Task<TrackDownload> Download(string title, string url, string autho
6553

6654
if (collection is not null)
6755
{
68-
var songAlbumPath = $"{_nitefoxConfig.DownloadLocation}{collection}\\";
56+
var songAlbumPath = $"{nitefoxConfig.DownloadLocation}{collection}\\";
6957

7058
trackDownload.Collection = collection;
7159
trackDownload.SavePath = $"{songAlbumPath}{songSaveName}";
7260
trackDownload.IsDownloaded =
73-
await _ffmpegService.StreamConvert(streamUrl, $"{songAlbumPath}{songSaveName}");
61+
await ffmpegService.StreamConvert(streamUrl, $"{songAlbumPath}{songSaveName}");
7462

7563
if (trackDownload.IsDownloaded)
7664
{
@@ -81,9 +69,9 @@ await _mediaDataStore.GetCollection<TrackDownload>()
8169
return trackDownload;
8270
}
8371

84-
trackDownload.SavePath = $"{_nitefoxConfig.DownloadLocation}{songSaveName}";
72+
trackDownload.SavePath = $"{nitefoxConfig.DownloadLocation}{songSaveName}";
8573
trackDownload.IsDownloaded =
86-
await _ffmpegService.StreamConvert(streamUrl, $"{_nitefoxConfig.DownloadLocation}{songSaveName}");
74+
await ffmpegService.StreamConvert(streamUrl, $"{nitefoxConfig.DownloadLocation}{songSaveName}");
8775

8876
if (trackDownload.IsDownloaded)
8977
{
@@ -102,9 +90,9 @@ await _mediaDataStore.GetCollection<TrackDownload>()
10290

10391
public async IAsyncEnumerable<TrackDownload> DownloadAlbum(string title, string id)
10492
{
105-
_fileService.CreateMediaDirectory(_nitefoxConfig.DownloadLocation, title.ToPathSafeString());
93+
fileService.CreateMediaDirectory(nitefoxConfig.DownloadLocation, title.ToPathSafeString());
10694

107-
foreach (var track in await _metadataService.GetAlbumTracksMetadata(id, title))
95+
foreach (var track in await metadataService.GetAlbumTracksMetadata(id, title))
10896
{
10997
var authors = track.Artists.Select(artist => artist.Name).Take(3).ToDelimitedString();
11098
yield return await Download(track.Title, track.Url, authors, title.ToPathSafeString());
@@ -113,9 +101,9 @@ public async IAsyncEnumerable<TrackDownload> DownloadAlbum(string title, string
113101

114102
public async IAsyncEnumerable<TrackDownload> DownloadPlaylist(string title, string id)
115103
{
116-
_fileService.CreateMediaDirectory(_nitefoxConfig.DownloadLocation, title.ToPathSafeString());
104+
fileService.CreateMediaDirectory(nitefoxConfig.DownloadLocation, title.ToPathSafeString());
117105

118-
foreach (var track in await _metadataService.GetPlaylistTracksMetadata(id, title))
106+
foreach (var track in await metadataService.GetPlaylistTracksMetadata(id, title))
119107
{
120108
var authors = track.Artists.Select(artist => artist.Name).Take(3).ToDelimitedString();
121109
yield return await Download(track.Title, track.Url, authors, title.ToPathSafeString());

Nitefox.App/Media/MediaSearch.cs

+4-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,8 @@
1414

1515
namespace Nitefox.App.Media;
1616

17-
public class MediaSearch
17+
public class MediaSearch(SpotifyClient spotifyClient)
1818
{
19-
private readonly SpotifyClient _spotifyClient;
20-
21-
public MediaSearch(SpotifyClient spotifyClient)
22-
{
23-
_spotifyClient = spotifyClient;
24-
}
25-
2619
public async Task<IEnumerable<ISearchResult>> SearchAsync(string query, int limit = Int32.MaxValue, int skip = 0)
2720
{
2821
try
@@ -31,15 +24,15 @@ public async Task<IEnumerable<ISearchResult>> SearchAsync(string query, int limi
3124

3225
if (query.Contains("album", StringComparison.InvariantCultureIgnoreCase))
3326
{
34-
return await _spotifyClient.Search.GetAlbumsAsync(cleanQuery, skip, limit);
27+
return await spotifyClient.Search.GetAlbumsAsync(cleanQuery, skip, limit);
3528
}
3629

3730
if (query.Contains("playlist", StringComparison.InvariantCultureIgnoreCase))
3831
{
39-
return await _spotifyClient.Search.GetPlaylistsAsync(cleanQuery, skip, limit);
32+
return await spotifyClient.Search.GetPlaylistsAsync(cleanQuery, skip, limit);
4033
}
4134

42-
return await _spotifyClient.Search.GetTracksAsync(cleanQuery, skip, limit);
35+
return await spotifyClient.Search.GetTracksAsync(cleanQuery, skip, limit);
4336
}
4437
catch (Exception e)
4538
{

Nitefox.App/Media/MetadataService.cs

+11-20
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,25 @@
1515

1616
namespace Nitefox.App.Media;
1717

18-
public class MetadataService
18+
public class MetadataService(SpotifyClient spotifyClient, YoutubeClient youtubeClient)
1919
{
20-
private readonly SpotifyClient _spotifyClient;
21-
private readonly YoutubeClient _youtubeClient;
22-
23-
public MetadataService(SpotifyClient spotifyClient, YoutubeClient youtubeClient)
24-
{
25-
_spotifyClient = spotifyClient;
26-
_youtubeClient = youtubeClient;
27-
}
28-
2920
public async Task<int> GetAlbumTrackCount(string id)
3021
{
31-
var album = await _spotifyClient.Albums.GetAsync(id);
22+
var album = await spotifyClient.Albums.GetAsync(id);
3223
return album.Tracks.Count;
3324
}
3425

3526
public async Task<int> GetPlaylistTrackCount(string id)
3627
{
37-
var playlists = await _spotifyClient.Playlists.GetAsync(id);
28+
var playlists = await spotifyClient.Playlists.GetAsync(id);
3829
return playlists.Tracks.Count;
3930
}
4031

4132
public async Task<string> GetAlbumImageUrl(string id)
4233
{
4334
try
4435
{
45-
var album = await _spotifyClient.Albums.GetAsync(id);
36+
var album = await spotifyClient.Albums.GetAsync(id);
4637
var image = album.Images.FirstOrDefault(image => !string.IsNullOrWhiteSpace(image.Url));
4738
if (image is null) return string.Empty;
4839
return image.Url;
@@ -61,7 +52,7 @@ public async Task<string> GetPlaylistImageUrl(string id)
6152
{
6253
try
6354
{
64-
var tracks = await _spotifyClient.Playlists.GetTracksAsync(id, limit: 5);
55+
var tracks = await spotifyClient.Playlists.GetTracksAsync(id, limit: 5);
6556
var playlistImages = tracks.SelectMany(track => track.Album.Images)
6657
.Where(image => !string.IsNullOrWhiteSpace(image.Url));
6758
var image = playlistImages.FirstOrDefault(image => !string.IsNullOrWhiteSpace(image.Url));
@@ -80,30 +71,30 @@ public async Task<string> GetPlaylistImageUrl(string id)
8071

8172
public async Task<string> GetYoutubeSongStream(string url)
8273
{
83-
var youtubeId = await _spotifyClient.Tracks.GetYoutubeIdAsync(url);
84-
var streamManifest = await _youtubeClient.Videos.Streams.GetManifestAsync($"https://youtube.com/watch?v={youtubeId}");
74+
var youtubeId = await spotifyClient.Tracks.GetYoutubeIdAsync(url);
75+
var streamManifest = await youtubeClient.Videos.Streams.GetManifestAsync($"https://youtube.com/watch?v={youtubeId}");
8576
return streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate().Url;
8677
}
8778

8879
public async Task<string> GetPreviewStream(string url)
8980
{
90-
var youtubeId = await _spotifyClient.Tracks.GetYoutubeIdAsync(url);
91-
var streamManifest = await _youtubeClient.Videos.Streams.GetManifestAsync($"https://youtube.com/watch?v={youtubeId}");
81+
var youtubeId = await spotifyClient.Tracks.GetYoutubeIdAsync(url);
82+
var streamManifest = await youtubeClient.Videos.Streams.GetManifestAsync($"https://youtube.com/watch?v={youtubeId}");
9283
return streamManifest.GetAudioOnlyStreams()
9384
.OrderByDescending(stream => stream.Size)
9485
.First().Url;
9586
}
9687

9788
public async Task<IEnumerable<Track>> GetAlbumTracksMetadata(string id, string title)
9889
{
99-
var tracks = await _spotifyClient.Albums.GetAllTracksAsync(id);
90+
var tracks = await spotifyClient.Albums.GetAllTracksAsync(id);
10091
return tracks.AsEnumerable();
10192
}
10293

10394

10495
public async Task<IEnumerable<Track>> GetPlaylistTracksMetadata(string id, string title)
10596
{
106-
var tracks = await _spotifyClient.Playlists.GetAllTracksAsync(id);
97+
var tracks = await spotifyClient.Playlists.GetAllTracksAsync(id);
10798
return tracks.AsEnumerable();
10899
}
109100

Nitefox.App/Nitefox.App.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<PublishAot>true</PublishAot>
8+
<LangVersion>12</LangVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -17,6 +18,7 @@
1718
<PackageReference Include="Russkyc.Configuration" Version="1.0.1" />
1819
<PackageReference Include="SharpCompress" Version="0.34.1" />
1920
<PackageReference Include="SpotifyExplode" Version="1.0.7" />
21+
<PackageReference Include="TagLibSharp" Version="2.3.0" />
2022
<PackageReference Include="YoutubeExplode" Version="6.3.6" />
2123
</ItemGroup>
2224

Nitefox.App/States/MediaPlayerState.cs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void Play(string track, string url)
2222
{
2323
Track = track;
2424
StreamUrl = url;
25-
Loaded = true;
2625
}
2726

2827
public void Stop()

Nitefox.Client.Photino/Nitefox.Client.Photino.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<ApplicationIcon>nitefox_icon.ico</ApplicationIcon>
7+
<LangVersion>12</LangVersion>
78
</PropertyGroup>
89

910
<ItemGroup>

Nitefox.Client.Photino/Services/PhotinoFileService.cs

+16-24
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,18 @@
1616

1717
namespace Nitefox.Client.Photino.Services;
1818

19-
public class PhotinoFileService : IFileService
19+
public class PhotinoFileService(NitefoxConfig nitefoxConfig) : IFileService
2020
{
21-
private readonly NitefoxConfig _nitefoxConfig;
22-
23-
public PhotinoFileService(NitefoxConfig nitefoxConfig)
24-
{
25-
_nitefoxConfig = nitefoxConfig;
26-
SetupDirectories();
27-
}
28-
29-
public async Task<string> OpenFolder()
21+
public Task<string> OpenFolder()
3022
{
3123
try
3224
{
3325
var path = Program.App.MainWindow.ShowOpenFolder();
34-
return path[0];
26+
return Task.FromResult(path[0]);
3527
}
3628
catch (Exception)
3729
{
38-
return "";
30+
return Task.FromResult("");
3931
}
4032
}
4133

@@ -54,34 +46,34 @@ public bool CreateMediaDirectory(string basePath, string directoryName)
5446

5547
public void SetupDirectories()
5648
{
57-
if (string.IsNullOrWhiteSpace(_nitefoxConfig.DownloadLocation))
49+
if (string.IsNullOrWhiteSpace(nitefoxConfig.DownloadLocation))
5850
{
59-
_nitefoxConfig.DownloadLocation = Environment.CurrentDirectory + "\\songs\\";
51+
nitefoxConfig.DownloadLocation = Environment.CurrentDirectory + "\\songs\\";
6052
}
6153

62-
if (!Directory.Exists(_nitefoxConfig.DownloadLocation))
54+
if (!Directory.Exists(nitefoxConfig.DownloadLocation))
6355
{
64-
Directory.CreateDirectory(_nitefoxConfig.DownloadLocation);
56+
Directory.CreateDirectory(nitefoxConfig.DownloadLocation);
6557
}
6658

67-
if (string.IsNullOrWhiteSpace(_nitefoxConfig.TempFilesLocation))
59+
if (string.IsNullOrWhiteSpace(nitefoxConfig.TempFilesLocation))
6860
{
69-
_nitefoxConfig.TempFilesLocation = Environment.CurrentDirectory + "\\temp\\";
61+
nitefoxConfig.TempFilesLocation = Environment.CurrentDirectory + "\\temp\\";
7062
}
7163

72-
if (!Directory.Exists(_nitefoxConfig.TempFilesLocation))
64+
if (!Directory.Exists(nitefoxConfig.TempFilesLocation))
7365
{
74-
Directory.CreateDirectory(_nitefoxConfig.TempFilesLocation);
66+
Directory.CreateDirectory(nitefoxConfig.TempFilesLocation);
7567
}
7668

77-
if (string.IsNullOrWhiteSpace(_nitefoxConfig.FfmpegLocation))
69+
if (string.IsNullOrWhiteSpace(nitefoxConfig.FfmpegLocation))
7870
{
79-
_nitefoxConfig.FfmpegLocation = Environment.CurrentDirectory + "\\ffmpeg\\";
71+
nitefoxConfig.FfmpegLocation = Environment.CurrentDirectory + "\\ffmpeg\\";
8072
}
8173

82-
if (!Directory.Exists(_nitefoxConfig.FfmpegLocation))
74+
if (!Directory.Exists(nitefoxConfig.FfmpegLocation))
8375
{
84-
Directory.CreateDirectory(_nitefoxConfig.FfmpegLocation);
76+
Directory.CreateDirectory(nitefoxConfig.FfmpegLocation);
8577
}
8678
}
8779
}

0 commit comments

Comments
 (0)