Skip to content

Commit

Permalink
Version 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
LordZero25 committed Jan 22, 2017
1 parent 6cb489c commit fb96d02
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 63 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Download chapters from Syosetsu ni Narou
- Option to specify a chapter range i.e. if you want to only download say chapters 3-10
- Download mutiple series
- Clicking the progress bar will cancel the download job
- Clicking the novel title will open it download folder
- Clicking the novel title will open its download folder
- Custom filename (see format.ini for details)
- Chapter list generation (nxxxxxx.htm)

**Notes:**
- If no chapter range is specified it will download everything
Expand All @@ -17,8 +18,6 @@ Download chapters from Syosetsu ni Narou
- No volume support
- "chapter 1" is "http://*.syosetu.com/xxxxxxx/1"
- Replaces illegal characters on filename with "□"

**ToDo:**
- Table of contents creation
- No chapter list generation for wayback machine

**[Releases Here](https://github.com/LordZero25/Syosetu-Downloader/releases/)**
9 changes: 8 additions & 1 deletion syosetuDownloader/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public enum FileType { Text, HTML };
string _link = String.Empty;
string _seriesCode = String.Empty;
private string _fileNameFormat = String.Empty;
private List<string> chapterTitle = new List<string>();

public CookieContainer SyousetsuCookie
{
Expand All @@ -46,7 +47,7 @@ public CookieContainer SyousetsuCookie
}
}

public string Title
public string SeriesTitle
{
get { return _title; }
set { _title = value; }
Expand Down Expand Up @@ -94,5 +95,11 @@ public string FilenameFormat
get { return _fileNameFormat; }
set { _fileNameFormat = value; }
}

public List<string> ChapterTitle
{
get { return chapterTitle; }
set { chapterTitle = value; }
}
}
}
9 changes: 5 additions & 4 deletions syosetuDownloader/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<Window x:Class="syosetuDownloader.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Narou Downloader" ResizeMode="CanMinimize" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="501" d:DesignWidth="317" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
Title="Narou Downloader" ResizeMode="CanMinimize" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="532" d:DesignWidth="317" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen">
<Grid>
<Label Content="Link:" Height="28" HorizontalAlignment="Left" Name="lblLink" VerticalAlignment="Top" Margin="26,5,0,0" />
<TextBox Height="23" HorizontalAlignment="Left" Name="txtLink" VerticalAlignment="Top" Width="197" Margin="66,5,0,0" />
<Label Content="From chapters" Height="28" HorizontalAlignment="Left" Margin="26,34,0,0" Name="label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="118,34,0,0" Name="txtFrom" VerticalAlignment="Top" Width="50" />
<Label Content="To" Height="28" HorizontalAlignment="Left" Margin="180,34,0,0" Name="label2" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="213,34,0,0" Name="txtTo" VerticalAlignment="Top" Width="50" />
<GroupBox Header="File Type" Height="61" HorizontalAlignment="Center" Name="groupBox1" VerticalAlignment="Top" Width="237" Margin="29,66,29,0">
<GroupBox Header="File Type" Height="56" HorizontalAlignment="Center" Name="groupBox1" VerticalAlignment="Top" Width="237" Margin="29,66,29,0">
<Grid>
<RadioButton Content="Text" Height="16" HorizontalAlignment="Center" Name="rbText" VerticalAlignment="Top" Margin="67,11,117,0" IsChecked="True" Checked="rbText_Checked" />
<RadioButton Content="HTML" Height="16" HorizontalAlignment="Center" Name="rbHtml" VerticalAlignment="Top" Margin="114,11,60,0" Checked="rbHtml_Checked" />
</Grid>
</GroupBox>
<Button Content="Download" Height="23" HorizontalAlignment="Center" Name="btnDownload" VerticalAlignment="Top" Width="107" Margin="94,138,94,0" Click="btnDownload_Click" />
<ScrollViewer Height="255" HorizontalAlignment="Left" Margin="0,167,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="295" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Button Content="Download" Height="23" HorizontalAlignment="Center" Name="btnDownload" VerticalAlignment="Top" Width="107" Margin="94,151,94,0" Click="btnDownload_Click" />
<ScrollViewer Height="255" HorizontalAlignment="Left" Margin="0,193,0,0" Name="scrollViewer1" VerticalAlignment="Top" Width="295" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<StackPanel Name="stackPanel1" />
</ScrollViewer>
<Button Content="Delete Completed" Height="23" HorizontalAlignment="Center" Name="btnDelete" VerticalAlignment="Bottom" Width="103" Margin="96,0,96,10" Click="btnDelete_Click" />
<CheckBox Content="Generate Chapter List" Height="16" HorizontalAlignment="Center" Name="chkList" VerticalAlignment="Top" Margin="80,128,80,0" />
</Grid>
</Window>
110 changes: 67 additions & 43 deletions syosetuDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,64 +48,88 @@ public MainWindow()

private void btnDownload_Click(object sender, RoutedEventArgs e)
{
_row += 1;

this._link = txtLink.Text;
this._start = txtFrom.Text;
this._end = txtTo.Text;

if (_link != String.Empty)
bool fromToValid = (System.Text.RegularExpressions.Regex.IsMatch(_start, @"^\d+$") || _start.Equals(String.Empty)) &&
(System.Text.RegularExpressions.Regex.IsMatch(_end, @"^\d+$") || _end.Equals(String.Empty));
if (_link != String.Empty && fromToValid)
{
if (!_link.StartsWith("http")) { _link = @"http://" + _link; }
if (!_link.EndsWith("/")) { _link = _link + "/"; }

Syousetsu.Constants sc = new Syousetsu.Constants();
HtmlDocument toc = Syousetsu.Methods.GetTableOfContents(_link, sc.SyousetsuCookie);
if (Syousetsu.Methods.IsValidLink(_link) &&
Syousetsu.Methods.IsValid(toc))
if (Syousetsu.Methods.IsValidLink(_link))
{
Label lb = new Label();
lb.Content = Syousetsu.Methods.GetTitle(toc);
lb.ToolTip = "Click to open folder";

ProgressBar pb = new ProgressBar();
pb.Maximum = (_end == String.Empty) ? Syousetsu.Methods.GetTotalChapters(toc) : Convert.ToDouble(_end);
pb.ToolTip = "Click to stop download";
pb.Height = 10;

Separator s = new Separator();
s.Height = 5;

sc.Title = lb.Content.ToString();
sc.Link = _link;
sc.Start = _start;
sc.End = _end;
sc.CurrentFileType = _fileType;
sc.SeriesCode = Syousetsu.Methods.GetSeriesCode(_link);
sc.FilenameFormat = _format;

System.Threading.CancellationTokenSource ct = Syousetsu.Methods.AddDownloadJob(sc, pb);
pb.MouseDown += (snt, evt) =>
{
ct.Cancel();
pb.ToolTip = "";
};
lb.MouseDown += (snt, evt) =>
Syousetsu.Constants sc = new Syousetsu.Constants();
sc.ChapterTitle.Add("");
HtmlDocument toc = Syousetsu.Methods.GetTableOfContents(_link, sc.SyousetsuCookie);

if (Syousetsu.Methods.IsValid(toc))
{
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), sc.Title);
if (System.IO.Directory.Exists(path))
_row += 1;

Label lb = new Label();
lb.Content = Syousetsu.Methods.GetTitle(toc);
lb.ToolTip = "Click to open folder";

ProgressBar pb = new ProgressBar();
pb.Maximum = (_end == String.Empty) ? Syousetsu.Methods.GetTotalChapters(toc) : Convert.ToDouble(_end);
pb.ToolTip = "Click to stop download";
pb.Height = 10;

Separator s = new Separator();
s.Height = 5;

sc.SeriesTitle = lb.Content.ToString();
sc.Link = _link;
sc.Start = _start;
sc.End = _end;
sc.CurrentFileType = _fileType;
sc.SeriesCode = Syousetsu.Methods.GetSeriesCode(_link);
sc.FilenameFormat = _format;
Syousetsu.Methods.GetAllChapterTitles(sc, toc);

if (chkList.IsChecked == true)
{
System.Diagnostics.Process.Start("explorer.exe", path);
Syousetsu.Create.GenerateTableOfContents(sc, toc);
}
};

stackPanel1.Children.Add(lb);
stackPanel1.Children.Add(pb);
stackPanel1.Children.Add(s);

_controls.Add(new Syousetsu.Controls { ID = _row, Label = lb, ProgressBar = pb, Separator = s });
System.Threading.CancellationTokenSource ct = Syousetsu.Methods.AddDownloadJob(sc, pb);
pb.MouseDown += (snt, evt) =>
{
ct.Cancel();
pb.ToolTip = null;
};
lb.MouseDown += (snt, evt) =>
{
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), sc.SeriesTitle);
if (System.IO.Directory.Exists(path))
{
System.Diagnostics.Process.Start("explorer.exe", path);
}
};

stackPanel1.Children.Add(lb);
stackPanel1.Children.Add(pb);
stackPanel1.Children.Add(s);

_controls.Add(new Syousetsu.Controls { ID = _row, Label = lb, ProgressBar = pb, Separator = s });
}
else
{
MessageBox.Show("Link not valid!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("Link not valid!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("Error parsing link and/or chapter range!", "", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

private void rbText_Checked(object sender, RoutedEventArgs e)
Expand Down
Loading

0 comments on commit fb96d02

Please sign in to comment.