Skip to content

Commit

Permalink
+ auto open txt file
Browse files Browse the repository at this point in the history
  • Loading branch information
aleqsanbr committed Jul 8, 2023
1 parent 145d594 commit e7c84b0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions YandexMusicExport/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Text.Json;

internal class Program
namespace YandexMusicExport;

internal static class Program
{
private static void Main(string[] args)
private static void Main()
{
try
{
Expand Down Expand Up @@ -60,11 +63,11 @@ private static void Main(string[] args)
var response = JsonSerializer.Deserialize<PlaylistResponse>(responseRaw, options);

// Извлечение названия плейлиста и списка треков из полученного ответа
var playlistTitle = response.Playlist.Title;
var tracks = response.Playlist.Tracks;
var playlistTitle = response?.Playlist.Title;
var tracks = response?.Playlist.Tracks;

// Итерация по каждому треку в списке треков
foreach (var track in tracks)
foreach (var track in tracks!)
{
var artistsNames = "";

Expand All @@ -87,13 +90,15 @@ private static void Main(string[] args)
Console.ResetColor();

Console.WriteLine($"Название плейлиста: {playlistTitle}\n" +
$"Список треков распечатан ниже и сохранен рядом с файлом программы.");
$"Список треков распечатан ниже и сохранен рядом с файлом программы (файл {playlistTitle}.txt).\n");

using (var fs = new StreamWriter($"{playlistTitle}.txt"))
{
fs.Write(allFile);
}
Console.WriteLine(allFile);

Process.Start(new ProcessStartInfo($"{playlistTitle}.txt") { UseShellExecute = true });

}
catch (JsonException e)
Expand Down

0 comments on commit e7c84b0

Please sign in to comment.