replace fchan

pull/1/head
BuildTools 5 years ago
parent 613f33ea7d
commit 3b5e2c918d
  1. 28
      Imageboard.cs
  2. 14
      Program.cs
  3. 4
      chandl.csproj

@ -0,0 +1,28 @@
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json;
namespace imageboard
{
public class Post
{
public long no;
public long tim;
public string ext;
}
public class Thread
{
public List<Post> Posts;
}
public class ImageboardController
{
public static Thread GetThread(string board, int postNumber)
{
string threadURL = "https://a.4cdn.org/" + board + "/thread/" + postNumber + ".json";
var webclient = new WebClient();
string response = webclient.DownloadString(threadURL);
Thread threadObject = JsonConvert.DeserializeObject<Thread>(response);
return threadObject;
}
}
}

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Net;
using FChan.Library;
using System.IO;
using Newtonsoft.Json;
using imageboard;
namespace chandl
{
@ -16,19 +16,19 @@ namespace chandl
List<string> imgList = new List<string>();
try
{
var a = Chan.GetThread(board, threadNumber);
var a = ImageboardController.GetThread(board, threadNumber);
}
catch (NullReferenceException)
{
Console.WriteLine("Invalid thread");
throw new NullReferenceException();
}
Thread threadObject = Chan.GetThread(board, threadNumber);
Thread threadObject = ImageboardController.GetThread(board, threadNumber);
foreach (Post postObject in threadObject.Posts)
{
if (postObject.FileName != 0)
if (postObject.tim != 0)
{
imgList.Add(postObject.FileName + postObject.FileExtension);
imgList.Add(postObject.tim + postObject.ext);
}
}
return Tuple.Create(imgList, threadNumber, board);
@ -68,6 +68,10 @@ namespace chandl
static void Main(string[] args)
{
Console.WriteLine("Running from " + localDirectory);
if (args.Length < 1)
{
Console.WriteLine("Missing arguments.");
}
Console.WriteLine("Downloading images from thread " + args[0] + " on board " + Int32.Parse(args[1]));
var images = GetThreadImages(args[0], Int32.Parse(args[1]));
DownloadImages(images.Item1, images.Item2, images.Item3);

@ -48,9 +48,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FChan.Library, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\FChan.Library.2.0.1\lib\netstandard2.0\FChan.Library.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
@ -66,6 +63,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Imageboard.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

Loading…
Cancel
Save