diff --git a/Imageboard.cs b/Imageboard.cs new file mode 100644 index 0000000..07c9e45 --- /dev/null +++ b/Imageboard.cs @@ -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 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(response); + return threadObject; + } + } +} diff --git a/Program.cs b/Program.cs index ee5f9ab..9de3de9 100644 --- a/Program.cs +++ b/Program.cs @@ -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 imgList = new List(); 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); diff --git a/chandl.csproj b/chandl.csproj index e953a99..52214db 100644 --- a/chandl.csproj +++ b/chandl.csproj @@ -48,9 +48,6 @@ 4 - - packages\FChan.Library.2.0.1\lib\netstandard2.0\FChan.Library.dll - packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll @@ -66,6 +63,7 @@ +