190 lines
5.6 KiB
C#
190 lines
5.6 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace Simpsons_generator;
|
|
|
|
class Program
|
|
{
|
|
/* public static void openit(string x) {
|
|
System.Diagnostics.Process.Start("cmd", "/C start" + " " + x);
|
|
}*/
|
|
|
|
public static readonly string folder_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Simpsons_generator");
|
|
public static readonly string filePath = Path.Combine(folder_path, "episodes-watched.csv");
|
|
public static readonly string overrideBrowser = Path.Combine(folder_path, "overrideBrowser.xml");
|
|
|
|
private static void openit(string url)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(url);
|
|
}
|
|
catch
|
|
{
|
|
// hack because of this: https://github.com/dotnet/corefx/issues/10361
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
{
|
|
url = url.Replace("&", "^&");
|
|
if (File.Exists(overrideBrowser))
|
|
{
|
|
string browser_path = File.ReadAllText(overrideBrowser);
|
|
Console.WriteLine("browser: "+browser_path);
|
|
Process.Start(new ProcessStartInfo(browser_path, url) { CreateNoWindow = true });
|
|
}
|
|
else {
|
|
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
|
|
}
|
|
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
{
|
|
Process.Start("xdg-open", url);
|
|
}
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
{
|
|
Process.Start("open", url);
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
//Process.Start(new ProcessStartInfo("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", url_generated) { CreateNoWindow = true });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private static bool CheckEpisodeAlreadyRun(string url)
|
|
{
|
|
if (File.Exists(filePath))
|
|
{
|
|
|
|
|
|
var linesRead = File.ReadLines(filePath);
|
|
|
|
// iterate through each element within the array and
|
|
// print it out
|
|
//
|
|
foreach (var lineRead in linesRead)
|
|
{
|
|
if (lineRead == url)
|
|
{
|
|
Console.WriteLine("already watched");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
private static void saveIntoFile(string data_input)
|
|
{
|
|
|
|
//first check if folder and file exist
|
|
|
|
if (!Directory.Exists(folder_path))
|
|
Directory.CreateDirectory(folder_path);
|
|
|
|
using (StreamWriter w = new StreamWriter(filePath, true))
|
|
{
|
|
w.WriteLine(data_input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
|
|
string url_generated;
|
|
|
|
bool restart = false;
|
|
do
|
|
{
|
|
restart = false;
|
|
|
|
|
|
int maximum_number_seasons = 35;
|
|
string root_url = "https://www1.kisscartoon.online/episode/the-simpsons-season-";
|
|
|
|
//random for the season
|
|
Random rnd = new Random();
|
|
int random_season = rnd.Next(1, maximum_number_seasons);
|
|
|
|
Console.WriteLine("random season:"+random_season);
|
|
|
|
|
|
//dictionary for the maximum number of episodes
|
|
Dictionary<int, int> Season_nbr_Episodes = new Dictionary<int, int>();
|
|
Season_nbr_Episodes.Add(1,13);
|
|
Season_nbr_Episodes.Add(2,22);
|
|
Season_nbr_Episodes.Add(3,24);
|
|
Season_nbr_Episodes.Add(4,22);
|
|
Season_nbr_Episodes.Add(5,22);
|
|
Season_nbr_Episodes.Add(6,25);
|
|
Season_nbr_Episodes.Add(7,25);
|
|
Season_nbr_Episodes.Add(8,25);
|
|
Season_nbr_Episodes.Add(9,25);
|
|
Season_nbr_Episodes.Add(10,23);
|
|
Season_nbr_Episodes.Add(11,22);
|
|
Season_nbr_Episodes.Add(12,21);
|
|
Season_nbr_Episodes.Add(13,22);
|
|
Season_nbr_Episodes.Add(14,22);
|
|
Season_nbr_Episodes.Add(15,22);
|
|
Season_nbr_Episodes.Add(16,21);
|
|
Season_nbr_Episodes.Add(17,22);
|
|
Season_nbr_Episodes.Add(18,22);
|
|
Season_nbr_Episodes.Add(19,20);
|
|
Season_nbr_Episodes.Add(20,21);
|
|
Season_nbr_Episodes.Add(21,23);
|
|
Season_nbr_Episodes.Add(22,22);
|
|
Season_nbr_Episodes.Add(23,22);
|
|
Season_nbr_Episodes.Add(24,22);
|
|
Season_nbr_Episodes.Add(25,22);
|
|
Season_nbr_Episodes.Add(26,22);
|
|
Season_nbr_Episodes.Add(27,22);
|
|
Season_nbr_Episodes.Add(28,22);
|
|
Season_nbr_Episodes.Add(29,21);
|
|
Season_nbr_Episodes.Add(30,23);
|
|
Season_nbr_Episodes.Add(31,22);
|
|
Season_nbr_Episodes.Add(32,22);
|
|
Season_nbr_Episodes.Add(33,22);
|
|
Season_nbr_Episodes.Add(34,22);
|
|
Season_nbr_Episodes.Add(35,18);
|
|
|
|
int random_episode = rnd.Next(1,Season_nbr_Episodes[random_season]);
|
|
|
|
Console.WriteLine("random episode:"+random_episode);
|
|
|
|
//url generated
|
|
url_generated = root_url + random_season + "-episode-"+random_episode;
|
|
|
|
Console.WriteLine(url_generated);
|
|
|
|
if (CheckEpisodeAlreadyRun(url_generated))
|
|
{
|
|
//return;
|
|
restart = true;
|
|
Console.WriteLine("already watched");
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (restart);
|
|
openit(url_generated);
|
|
|
|
saveIntoFile(url_generated);
|
|
|
|
|
|
|
|
}
|
|
} |