Skip to content

Commit

Permalink
Merge pull request #2 from nocturneop15/master
Browse files Browse the repository at this point in the history
added support for command line argumetns & small fixes
  • Loading branch information
Preclikos authored Jan 1, 2024
2 parents 19bc42c + 9062195 commit f4ae1aa
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
68 changes: 58 additions & 10 deletions SCCDownloader/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SCCDownloader;
using Microsoft.Extensions.Configuration;
// using Microsoft.VisualBasic; //not used
using SCCDownloader;
using SCCDownloader.Models;
using System.Diagnostics;
using System.Net;
//using System.Net; //not used
using System.Text;
using System.Text.Json;
using XAct;
Expand All @@ -11,21 +13,66 @@ namespace SCCDownoader // Note: actual namespace depends on the project name.
internal class Program
{
static bool enableMediaInfoExtensions = true;
//static string DownloadFolder = "Downloads";

//static string DownloadFolder = "Downloads"; //replaced by making folders by year

static void Main(string[] args)
{
MainAsync().Wait();



MainAsync(args).Wait(); //runs MainAsync()

}

static async Task MainAsync()

static async Task MainAsync(string[] args)
{
Console.Write("Zadej pozadovany rok: ");

var yearText = Console.ReadLine();
// create "Config" variable containing command line arguments

var Configuration = new ConfigurationBuilder();
Configuration.AddCommandLine(args);
var Config = Configuration.Build();




// create "year" from console parameter, read direct input if console input is null
var yearText = Config["year"];

if (yearText == null)
{
Console.Write("Zadej pozadovany rok: ");
yearText = Console.ReadLine();
}

// create number from yearText
var year = Int32.Parse(yearText);

// username from command line
var userName = Config["username"];

if (userName == null)
{
Console.Write("Zadej uzivatelske jmeno: ");
userName = Console.ReadLine();
}


// password from command line
var password = Config["password"];

if (password == null)
{
Console.Write("Zadej heslo: ");
password = Console.ReadLine();
}

//test
// var genre = String.Format("Western"); //used for search testing
//konec testu

var DownloadFolder = yearText;


Expand All @@ -42,11 +89,12 @@ static async Task MainAsync()
var movies = await sc.GetMovieList(year);
if (movies.Any())
{

/*
Console.Write("Zadej jmeno: ");
var userName = Console.ReadLine();
Console.Write("Zadej heslo: ");
var password = Console.ReadLine();
*/ //passed from command line, not needed anymore

if (!String.IsNullOrEmpty(userName) || !String.IsNullOrEmpty(password))
{
Expand Down Expand Up @@ -164,7 +212,7 @@ static String GetFileName(Movie movie, VideoStream stream)
static VideoStream GetIdentForParameters(VideoStream[] streams, String language = "cs", Boolean canBeWithSubtitles = true, Boolean canBeFilterSkiped = false)
{

var streamsWithSelectedAudio = streams.Where(w => w.Audio.Any(a => a.Language.ToLower() == language));
var streamsWithSelectedAudio = streams.Where(w => w.Audio.Any(a => (a.Language != null) && (a.Language.ToLower() == language))) ; // null returned sometimes and was throwing exception
if (streamsWithSelectedAudio.Any())
{
if (streamsWithSelectedAudio.Count() == 1)
Expand Down Expand Up @@ -219,7 +267,7 @@ static string StartMediaInfoProcess(String filePath)
// under System.Diagnostic Assembly Reference
ProcessStartInfo StartInfo = new ProcessStartInfo
{
FileName = "./MediaInfo_CLI_22.09_Windows_x64/MediaInfo.exe",
FileName = "./MediaInfo_CLI_23.11.1_Windows_x64/MediaInfo.exe",
Arguments = "./" + filePath + " --Output=JSON",
UseShellExecute = false,
RedirectStandardOutput = true,
Expand Down
8 changes: 8 additions & 0 deletions SCCDownloader/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"SCCDownloader": {
"commandName": "Project",
"commandLineArgs": "--year 1923 --username nocturne.op.15 --password OpsRPMPVF3Q4PDQd9nH0"
}
}
}
5 changes: 5 additions & 0 deletions SCCDownloader/SCCDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="XAct.Core.PCL" Version="0.0.5014" />
</ItemGroup>
Expand Down
15 changes: 10 additions & 5 deletions SCCDownloader/StreamCinema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ public class StreamCinema

static protected HttpClient httpClient;
static readonly String BaseUrl = "https://plugin.sc2.zone";
static String YearUrl = "/api/media/filter/v2/year?value={0}&order=desc&sort=year&type=movie&size=" + Limit + "&access_token=th2tdy0no8v1zoh1fs59";
static String YearFromUrl = "/api/media/filter/v2/year?value={0}&order=desc&sort=year&type=movie&size=" + Limit + "&access_token=th2tdy0no8v1zoh1fs59&from={1}";

static String YearUrl = "/api/media/filter/v2/year?value={0}&order=desc&sort=year&type=movie&size=" + Limit + "&access_token=F4fdEDXKgsw7z3TxzSjaDpp3O";
static String YearFromUrl = "/api/media/filter/v2/year?value={0}&order=desc&sort=year&type=movie&size=" + Limit + "&access_token=F4fdEDXKgsw7z3TxzSjaDpp3O&from={1}";

static String GenreURL = "/api/media/filter/v2/genre?value=Western&order=asc&sort=year&type=movie&size=" + Limit + "&access_token=F4fdEDXKgsw7z3TxzSjaDpp3O";
static String GenreFromUrl = "/api/media/filter/v2/genre?value=Western&order=asc&sort=year&type=movie&size=" + Limit + "&access_token=F4fdEDXKgsw7z3TxzSjaDpp3O&from={1}";

//static String SearchUrl = "/api/media/filter/v2/search?access_token=th2tdy0no8v1zoh1fs59&order=desc&sort=score&type=movie";
static String StreamUrl = "/api/media/{0}/streams?access_token=th2tdy0no8v1zoh1fs59";
static String StreamUrl = "/api/media/{0}/streams?access_token=F4fdEDXKgsw7z3TxzSjaDpp3O";

public StreamCinema()
{
Expand All @@ -24,7 +27,8 @@ public StreamCinema()

public async Task<IEnumerable<Movie>> GetMovieList(int year)
{
var pathFilter = String.Format(YearUrl, year);
var pathFilter = String.Format(YearUrl, year);
//var pathFilter = String.Format(GenreURL, year);
var response = await httpClient.GetAsync(pathFilter);
SearchResponse result = await response.Content.ReadFromJsonAsync<SearchResponse>();

Expand All @@ -40,6 +44,7 @@ public async Task<IEnumerable<Movie>> GetMovieList(int year)
for (int i = 1; i < totalPages; i++)
{
pathFilter = String.Format(YearFromUrl, year, i * Limit);
//pathFilter = String.Format(GenreFromUrl, year, i * Limit);
response = await httpClient.GetAsync(pathFilter);
result = await response.Content.ReadFromJsonAsync<SearchResponse>();
movieList.AddRange(GetMovieList(result));
Expand Down
2 changes: 1 addition & 1 deletion SCCDownloader/WebShare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<String> GetLink(string token, string ident)

if (saltResult.Status != "OK")
{
// throw new Exception("Link error");
// throw new Exception("Link error"); //replaced just by simple console output
Console.WriteLine("Link error");
}

Expand Down

0 comments on commit f4ae1aa

Please sign in to comment.