17
17
18
18
namespace Nitefox . App . Media ;
19
19
20
- public class MediaDownloader
20
+ public class MediaDownloader (
21
+ IFileService fileService ,
22
+ FfmpegService ffmpegService ,
23
+ NitefoxConfig nitefoxConfig ,
24
+ MetadataService metadataService )
21
25
{
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
- }
41
26
27
+ private readonly DataStore _mediaDataStore = new ( $ "{ nitefoxConfig . DownloadLocation } downloads.json",
28
+ reloadBeforeGetCollection : true ) ;
29
+
42
30
public async Task < TrackDownload > Download ( string title , string url , string author , string ? collection = null )
43
31
{
44
32
var trackDownload = new TrackDownload
@@ -51,12 +39,12 @@ public async Task<TrackDownload> Download(string title, string url, string autho
51
39
52
40
try
53
41
{
54
- await _ffmpegService . DownloadFfmpeg ( ) ;
42
+ await ffmpegService . DownloadFfmpeg ( ) ;
55
43
56
- _ffmpegService . ConfigureFfmpeg ( ) ;
57
- _fileService . SetupDirectories ( ) ;
44
+ ffmpegService . ConfigureFfmpeg ( ) ;
45
+ fileService . SetupDirectories ( ) ;
58
46
59
- var streamUrl = await _metadataService . GetYoutubeSongStream ( url ) ;
47
+ var streamUrl = await metadataService . GetYoutubeSongStream ( url ) ;
60
48
61
49
if ( string . IsNullOrWhiteSpace ( streamUrl ) )
62
50
{
@@ -65,12 +53,12 @@ public async Task<TrackDownload> Download(string title, string url, string autho
65
53
66
54
if ( collection is not null )
67
55
{
68
- var songAlbumPath = $ "{ _nitefoxConfig . DownloadLocation } { collection } \\ ";
56
+ var songAlbumPath = $ "{ nitefoxConfig . DownloadLocation } { collection } \\ ";
69
57
70
58
trackDownload . Collection = collection ;
71
59
trackDownload . SavePath = $ "{ songAlbumPath } { songSaveName } ";
72
60
trackDownload . IsDownloaded =
73
- await _ffmpegService . StreamConvert ( streamUrl , $ "{ songAlbumPath } { songSaveName } ") ;
61
+ await ffmpegService . StreamConvert ( streamUrl , $ "{ songAlbumPath } { songSaveName } ") ;
74
62
75
63
if ( trackDownload . IsDownloaded )
76
64
{
@@ -81,9 +69,9 @@ await _mediaDataStore.GetCollection<TrackDownload>()
81
69
return trackDownload ;
82
70
}
83
71
84
- trackDownload . SavePath = $ "{ _nitefoxConfig . DownloadLocation } { songSaveName } ";
72
+ trackDownload . SavePath = $ "{ nitefoxConfig . DownloadLocation } { songSaveName } ";
85
73
trackDownload . IsDownloaded =
86
- await _ffmpegService . StreamConvert ( streamUrl , $ "{ _nitefoxConfig . DownloadLocation } { songSaveName } ") ;
74
+ await ffmpegService . StreamConvert ( streamUrl , $ "{ nitefoxConfig . DownloadLocation } { songSaveName } ") ;
87
75
88
76
if ( trackDownload . IsDownloaded )
89
77
{
@@ -102,9 +90,9 @@ await _mediaDataStore.GetCollection<TrackDownload>()
102
90
103
91
public async IAsyncEnumerable < TrackDownload > DownloadAlbum ( string title , string id )
104
92
{
105
- _fileService . CreateMediaDirectory ( _nitefoxConfig . DownloadLocation , title . ToPathSafeString ( ) ) ;
93
+ fileService . CreateMediaDirectory ( nitefoxConfig . DownloadLocation , title . ToPathSafeString ( ) ) ;
106
94
107
- foreach ( var track in await _metadataService . GetAlbumTracksMetadata ( id , title ) )
95
+ foreach ( var track in await metadataService . GetAlbumTracksMetadata ( id , title ) )
108
96
{
109
97
var authors = track . Artists . Select ( artist => artist . Name ) . Take ( 3 ) . ToDelimitedString ( ) ;
110
98
yield return await Download ( track . Title , track . Url , authors , title . ToPathSafeString ( ) ) ;
@@ -113,9 +101,9 @@ public async IAsyncEnumerable<TrackDownload> DownloadAlbum(string title, string
113
101
114
102
public async IAsyncEnumerable < TrackDownload > DownloadPlaylist ( string title , string id )
115
103
{
116
- _fileService . CreateMediaDirectory ( _nitefoxConfig . DownloadLocation , title . ToPathSafeString ( ) ) ;
104
+ fileService . CreateMediaDirectory ( nitefoxConfig . DownloadLocation , title . ToPathSafeString ( ) ) ;
117
105
118
- foreach ( var track in await _metadataService . GetPlaylistTracksMetadata ( id , title ) )
106
+ foreach ( var track in await metadataService . GetPlaylistTracksMetadata ( id , title ) )
119
107
{
120
108
var authors = track . Artists . Select ( artist => artist . Name ) . Take ( 3 ) . ToDelimitedString ( ) ;
121
109
yield return await Download ( track . Title , track . Url , authors , title . ToPathSafeString ( ) ) ;
0 commit comments