Skip to content

Commit

Permalink
New
Browse files Browse the repository at this point in the history
  • Loading branch information
EarzuChan committed Jun 5, 2022
1 parent 46c1ca4 commit e67daf7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 35 deletions.
26 changes: 15 additions & 11 deletions WebPhotoGetter/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
</Grid.ColumnDefinitions>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="80*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="76*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="8*"></RowDefinition>
</Grid.RowDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" x:Name="MyList" Background ="Transparent" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" SelectionMode="Multiple" ToolTip="Double Click to get view. " SelectionChanged="MyList_SelectionChanged">
<ListBox.ItemsPanel>
Expand All @@ -46,7 +46,7 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Row="1">
<Grid Grid.Row="1" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
Expand Down Expand Up @@ -74,10 +74,10 @@
</TextBox>
<Button Grid.Row="0" Grid.Column="2" x:Name="LoadButton" Content="Load" HorizontalAlignment="Stretch" Click="LoadButton_Click" Grid.ColumnSpan="1"/>
</Grid>
<Grid Grid.Row="2">
<Grid Grid.Row="2" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="65*"/>
<ColumnDefinition Width="15*"/>
<ColumnDefinition Width="70*"/>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="PathBox" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextChanged="PathBox_TextChanged">
Expand Down Expand Up @@ -106,13 +106,17 @@
<Button Grid.Row="0" Grid.Column="1" x:Name="PathButton" Content="..." HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="PathButton_Click" RenderTransformOrigin="0.392,0.563"/>
<Button Grid.Row="0" Grid.Column="2" Name="Getit" Content="Get" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="GetButton_Click"/>
</Grid>
<Grid Grid.Row="3">
<Grid Grid.Row="3" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<Button x:Name="DSB" Grid.Column="2" Content="Download" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="DSB_Click"/>

<Button x:Name="DSB" Grid.Column="3" Content="Download" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="DSB_Click"/>
<CheckBox x:Name="RenameBox" Grid.Column="1" Content="Rename Photo(s) to Id" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="RenameBox_Click"/>
<CheckBox x:Name="SDB" Grid.Column="0" Content="Show Details" HorizontalAlignment="Stretch" VerticalAlignment="Center" Click="SDB_Click"/>

</Grid>

Expand Down
115 changes: 91 additions & 24 deletions WebPhotoGetter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class LVData
Stopwatch stopwatch = new Stopwatch();

bool renamephotos = false;
bool showdetails = false;
string TheUriRightNow = "";
string NowPath = "";
int TheName = 0;
Expand All @@ -50,46 +51,62 @@ public MainWindow()

CtrlThePhotoViewer.Width = new GridLength(0);
dlg.IsFolderPicker = true;

PrintOut.Text += "\n\nDevelop By Earzu Chan 2022. All copyrights. \n\nHow To Use?\nFirst, type your uri that you wanna get photo into the Uri TextBox. \nSecond, Click the button Load, after the Page was loaded in the Browser under the interface, to scroll the Page to make sure all the photos you wanna get is loaded. \nThird, just click the button Get. After a while, all the photos that can be got was viewed in the ListBox up the interface. \nFouth, click the photos you wanna download, and click the button Download( If you wanna rename them all, click the Box Rename Photos), after a while, photos are downloaded. ";

renamephotos = true;//以后加入复选框
renamephotos = true;
RenameBox.IsChecked = renamephotos;
SDB.IsChecked = showdetails;

}

private void printMy(string str)
{
PrintOut.Text += str + "\n\n";

PrintOut.ScrollToEnd();
}

private void addPhoto(string url, int num)
{
var pic = new BitmapImage(new Uri(url));
string[] aArray = url.Split('/');
aArray = aArray[aArray.Length - 1].Split('.');
string type = "webp";
string nam = "Untitled";

if (aArray[aArray.Length - 1].Contains('?')) {
aArray[aArray.Length - 1] = aArray[aArray.Length - 1].Substring(0, aArray[aArray.Length - 1].IndexOf('?'));
//printMy($"搞这种扩展名修复太润,{aArray[aArray.Length - 1]}");
}
if (aArray[aArray.Length - 1].Length <= 4)
{
type = aArray[aArray.Length - 1];
nam = aArray[aArray.Length - 2];
}
else
{
nam = aArray[aArray.Length - 1] + ".As_A_Webp";
nam = aArray[aArray.Length - 1] + "(Load As A Webp)";
}
if (showdetails)
{
printMy($"File Type: {type}\nFile Name: {nam} <---");
}
else
{
printMy($"A {type} File. <---");
}

printMy($"--->File Type: {type}\nFile Name: {nam}<---");
LVDatas.Add(new LVData { Name = num.ToString(), Pic = pic, OriFileUri = url, OriFileName = nam, Type = type });
MyList.ItemsSource = LVDatas;
}

private void PathButton_Click(object sender, RoutedEventArgs e)
{
if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
{
PathBox.Text = dlg.FileName;
}
}

private void LoadButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(UrlBox.Text)) return;
Expand All @@ -99,21 +116,23 @@ private void LoadButton_Click(object sender, RoutedEventArgs e)

TheName = 100;

printMy($"--->\nGetting Load With: \n{TheUriRightNow}\n<---");
printMy($"---> Getting Load With: \n{TheUriRightNow} <---");
WebView.Source = new Uri(TheUriRightNow);
}

private void clearList()
{
PrintOut.Text = "";

LVDatas = new ObservableCollection<LVData>();
}

private async void GetButton_Click(object sender, RoutedEventArgs e)
{

clearList();

printMy("--->\nGot Started\n<---");
printMy("---> Got Started <---");
stopwatch.Start();

object obj = await WebView.CoreWebView2.ExecuteScriptAsync("document.documentElement.outerHTML;");//jquery获取页面内容
Expand All @@ -122,13 +141,14 @@ private async void GetButton_Click(object sender, RoutedEventArgs e)
HtmlText = Regex.Unescape(HtmlText);
HtmlText = HtmlText.AsSpan()[1..^1].ToString();

getPhotosNextStep(HtmlText, TheName);
getPhotosNextStep(HtmlText);
}
private void getPhotosNextStep(string str, int name)

private void getPhotosNextStep(string str)
{
if (string.IsNullOrEmpty(str.Trim()))
{
printMy("--->\nGot Failed: \nGot the WebPage file error. \n<---");
printMy("---> Got Failed: \nGot the WebPage file error. <---");
return;
}

Expand All @@ -146,20 +166,33 @@ private void getPhotosNextStep(string str, int name)

alltemp++;

if (src.StartsWith(@"//")) src = "http://" + src.Substring(2);
if (src.StartsWith(@"//")) src = string.Concat("http://", src.AsSpan(2));

if (src.StartsWith("http"))
{
temp++;
printMy("The Normal PhotoUrl: \n" + src);

if (showdetails)
{
printMy("---> No." + temp + " . The Normal Photo. \nUrl: " + src);
}
else
{
printMy($"---> A Normal Photo. No.{temp}");
}

addPhoto(src, temp);
name++;
printMy("It can be got normally. \n");
}
else
{
printMy("The Special Photo: \n" + src + "\n\nWhich can't be viewed right now, maybe is anthor's knowledge too few. ");
if (showdetails)
{
printMy("---> The Special Photo: \n" + src + "\n\nWhich can't be viewed right now, maybe is anthor's knowledge too few. <---");
}
else
{
printMy("---> A Special Photo <---");
}
}
}
}
Expand All @@ -172,28 +205,29 @@ private void getPhotosNextStep(string str, int name)
printMy("There's about " + alltemp + " Photo files, and got " + temp + " successfully.");
printMy("Time: " + stopwatch.ElapsedMilliseconds / 1000 + " Second(s). \n<---");
}

private void DSB_Click(object sender, RoutedEventArgs e)
{
if (MyList.SelectedItem != null)
{
if (string.IsNullOrEmpty(NowPath))
{
printMy("--->\nFile Written Path is Empty\n<---");
printMy("---> File Written Path is Empty <---");
return;
}
PathBox.IsReadOnly = true;
int seconds = 0;

printMy("--->\nStart Writting File(s). \n<---");
printMy("---> Start Writting File(s). <---");
WebClient client = new WebClient();
foreach (object obj in MyList.SelectedItems)
{
LVData item = (LVData)obj;
seconds++;

string filename = "";

if (renamephotos)
//printMy($"Rename? {renamephotos}");
if (renamephotos == true)
{
filename = seconds.ToString();
}
Expand All @@ -209,27 +243,36 @@ private void DSB_Click(object sender, RoutedEventArgs e)
filename = NowPath + "\\" + filename + "." + item.Type;

client.DownloadFile(item.OriFileUri, filename);

printMy("Writting the " + seconds + " file: \n" + item.OriFileName + "." + item.Type);
if (showdetails == true)
{
printMy("---> Writting the " + seconds + "\nFile:\nOrinName: " + item.OriFileName + "." + item.Type + "\nSave Name: " + filename + " <---");
}
else
{
printMy($"---> Writting the {seconds} File. <---");
}

}
printMy("--->\nFile(s) Written. \n<---");
printMy("---> File(s) Written. <---");
PathBox.IsReadOnly = false;
}
else
{
printMy("Nothing selected. ");
printMy("---> Nothing selected. <---");
}

}

private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
printMy("--->\nGot Loaded: \nNow you can scroll the WebPage until all the photos were got ready. \n\nNow you can select and download the Photo(s) you like, but remember to select the Photo(s) in order. \n<---");
printMy("---> Got Loaded: \nNow you can scroll the WebPage until all the photos were got ready. \n\nNow you can select and download the Photo(s) you like, but remember to select the Photo(s) in order. <---");
}

private void MyList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{

}

private void MyList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MyList.SelectedItem != null)
Expand All @@ -252,5 +295,29 @@ private void PathBox_TextChanged(object sender, TextChangedEventArgs e)
{
NowPath = PathBox.Text;
}

private void RenameBox_Click(object sender, RoutedEventArgs e)
{
if (RenameBox.IsChecked == true)
{
renamephotos = true;
}
else
{
renamephotos = false;
}
}

private void SDB_Click(object sender, RoutedEventArgs e)
{
if (SDB.IsChecked == true)
{
showdetails = true;
}
else
{
showdetails = false;
}
}
}
}

0 comments on commit e67daf7

Please sign in to comment.