返回提交历史
Modified
XFENewsApplication.Core/Models/NewsSource.cs
+2
-2
Modified
XFENewsApplication.Core/Utilities/Helpers/ClimbHelper.cs
+15
-2
Added
XFENewsApplication.Core/Utilities/Helpers/Helper.cs
+31
-0
Modified
XFENewsApplication.Test/Program.cs
+23
-2
Modified
XFENewsApplication/ViewModels/HotSearchViewPageViewModel.cs
+25
-2
Modified
XFENewsApplication/ViewModels/NewsViewPageViewModel.cs
+2
-6
Modified
XFENewsApplication/ViewModels/SettingPageViewModel.cs
+1
-1
Modified
XFENewsApplication/Views/AppShellPage.xaml
+3
-3
Modified
XFENewsApplication/Views/HotSearchViewPage.xaml
+3
-4
Modified
XFENewsApplication/Views/HotSearchViewPage.xaml.cs
+2
-7
XFEstudio/XFENewsApplication
初步完善央视新闻爬取机制
f20ed09
代码差异
10 个文件
+107
-29
@@ -9,8 +9,8 @@ public class NewsSource
9
9
public string? PublishTime { get; set; }
10
10
public string? Abstract { get; set; }
11
11
public string? ImageUrl { get; set; }
12
public int ImageWidth { get; set; }
13
public int ImageHeight { get; set; }
12
public double ImageWidth { get; set; }
13
public double ImageHeight { get; set; }
14
14
public int Index { get; set; }
15
15
public string Source { get; set; } = string.Empty;
16
16
}
@@ -49,7 +49,20 @@ public static class ClimbHelper
49
49
public static async Task<NewsResult> ClimbMSNNews(CancellationToken cancellationToken, int skip = 0, int lastCardCount = 0, int servedCardCount = 0)
50
50
{
51
51
if (MSNAPI.IsNullOrWhiteSpace())
52
MSNAPI = await GetMSNAPI(cancellationToken);
52
try
53
{
54
MSNAPI = await GetMSNAPI(cancellationToken);
55
}
56
catch (Exception ex)
57
{
58
return new()
59
{
60
NewsSourceList = [],
61
Message = ex.Message,
62
Count = 0,
63
Success = false
64
};
65
}
53
66
if (lastCardCount == 0 || skip == 0)
54
67
return await ClimbMSNNews($"https://assets.msn.com/service/news/feed/pages/weblayout?User=&activityId=&adoffsets=c1:-1,c2:-1&apikey={MSNAPI}&audienceMode=adult&cm=zh-cn&colstatus=c1:0,c2:0&column=c2&colwidth=300&contentType=article&it=edgeid&l3v=2&layout=c2&memory=8&newsSkip=0&newsTop=48&ocid=hponeservicefeed&pgc=11&private=1&scn=APP_ANON&timeOut=1000&vpSize=721x674&wposchema=byregion", cancellationToken);
55
68
else
@@ -184,7 +197,7 @@ public static class ClimbHelper
184
197
Title = node["keyword"].ToString(),
185
198
Abstract = node["heat_score"].ToString(),
186
199
Source = "B站热搜",
187
ImageWidth = 18,
200
ImageWidth = double.MaxValue,
188
201
ImageHeight = 18,
189
202
Index = index++,
190
203
ImageUrl = node.TryGetValue("icon", out var icon) ? Regex.Unescape(icon.ToString()) : string.Empty
@@ -0,0 +1,31 @@
1
using System.Diagnostics;
2
using XFENewsApplication.Core.Models;
3
4
namespace XFENewsApplication.Core.Utilities.Helpers;
5
6
public static class Helper
7
{
8
/// <summary>
9
/// 执行异步等待
10
/// </summary>
11
/// <param name="func">等待表达式</param>
12
/// <param name="delay">检测延迟</param>
13
/// <returns></returns>
14
public static async Task Wait(Func<bool> func, int delay = 100)
15
{
16
while (!func())
17
await Task.Delay(delay);
18
}
19
20
/// <summary>
21
/// 在浏览器中打开
22
/// </summary>
23
/// <param name="url">链接</param>
24
public static void OpenInBrowser(string url) => Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
25
26
/// <summary>
27
/// 在文件资源管理器中打开
28
/// </summary>
29
/// <param name="path">文件路径</param>
30
public static void OpenPath(string path) => Process.Start("explorer.exe", path);
31
}
@@ -1,9 +1,30 @@
1
using System.Text.RegularExpressions;
1
using System;
2
using System.Text.RegularExpressions;
2
3
using XFEExtension.NetCore.StringExtension;
3
4
using XFEExtension.NetCore.XFETransform.JsonConverter;
4
5
5
6
class Program
6
7
{
8
//[SMTest(1)]
9
public static async Task TestCCTVClimb(int index)
10
{
11
using var client = new HttpClient();
12
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0");
13
QueryableJsonNode jsonNode = await client.GetStringAsync($"https://news.cctv.com/2019/07/gaiban/cmsdatainterface/page/news_{index}.jsonp?cb=news");
14
foreach (var node in jsonNode["data"]["list"]["package:list", "brief", "title", "url"].PackageInListObject())
15
{
16
Console.WriteLine($"标题:{node["title"]}({node["url"]})\n{node["brief"]}\n");
17
}
18
}
19
20
[SMTest]
21
public static async Task TestM3u8()
22
{
23
using var client = new HttpClient();
24
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0");
25
Console.WriteLine(await client.GetStringAsync($"https://vdn.apps.cntv.cn/api/getHttpVideoInfo.do?pid=87b7efc3c7d84b45a288336e510e880e&client=flash&im=0&tsp=1744734329&vn=2049&vc=&uid=&wlan="));
26
}
27
7
28
//[SMTest]
8
29
public static async Task TestWeiboHotSearch()
9
30
{
@@ -17,7 +38,7 @@ class Program
17
38
}
18
39
}
19
40
20
[SMTest]
41
//[SMTest]
21
42
public static async Task TestBilibiliHotSearch()
22
43
{
23
44
using var client = new HttpClient();
@@ -1,4 +1,5 @@
1
using System.Collections.ObjectModel;
1
using CommunityToolkit.Mvvm.ComponentModel;
2
using System.Collections.ObjectModel;
2
3
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
3
4
using XFEExtension.NetCore.WinUIHelper.Utilities;
4
5
using XFENewsApplication.Core.Models;
@@ -8,17 +9,39 @@ namespace XFENewsApplication.ViewModels;
8
9
9
10
public partial class HotSearchViewPageViewModel : ViewModelBase
10
11
{
12
[ObservableProperty]
13
int selectedIndex = -1;
11
14
private List<NewsSource> hotSearchSource = [];
12
15
public ObservableCollection<NewsSource> HotSearchSource { get; } = [];
13
16
public CancellationTokenSource? TokenSource { get; set; }
14
17
public INavigationParameterService<string> NavigationParameterService { get; set; } = ServiceManager.GetService<INavigationParameterService<string>>();
18
public IListViewService ListViewService { get; set; } = ServiceManager.GetService<IListViewService>();
15
19
public IMessageService? MessageService { get; set; } = ServiceManager.GetGlobalService<IMessageService>();
16
20
public INavigationViewService? NavigationViewService { get; set; } = ServiceManager.GetGlobalService<INavigationViewService>();
17
21
18
public HotSearchViewPageViewModel() => NavigationParameterService.ParameterChange += NavigationParameterService_ParameterChange;
22
public HotSearchViewPageViewModel()
23
{
24
NavigationParameterService.ParameterChange += NavigationParameterService_ParameterChange;
25
}
26
27
private void ListView_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
28
{
29
switch (NavigationParameterService.Parameter)
30
{
31
case "Weibo":
32
Helper.OpenInBrowser($"https://m.weibo.cn/search?containerid=100103type%3D1%26t%3D10%26q%3D%23{HotSearchSource[SelectedIndex].Title}%23&stream_entry_id=31&isnewpage=1&extparam=seat%3D1%26cate%3D5001%26lcate%3D5001%26stream_entry_id%3D31%26q%3D%2523%25E6%2582%25AC%25E8%25B5%258F%25E9%2580%259A%25E7%25BC%25893%25E5%2590%258D%25E7%25BE%258E%25E5%259B%25BD%25E7%2589%25B9%25E5%25B7%25A5%2523%26dgr%3D0%26band_rank%3D1%26realpos%3D1%26pos%3D0%26c_type%3D31%26flag%3D0%26filter_type%3Drealtimehot%26display_time%3D1744725202%26pre_seqid%3D17447252029660411768217&luicode=10000011&lfid=106003type%3D25%26t%3D3%26disable_hot%3D1%26filter_type%3Drealtimehot");
33
break;
34
case "Bilibili":
35
Helper.OpenInBrowser($"https://search.bilibili.com/all?vt=24215469&keyword={HotSearchSource[SelectedIndex].Title}&from_source=webtop_search&spm_id_from=333.1007&search_source=4");
36
break;
37
default:
38
break;
39
}
40
}
19
41
20
42
private async void NavigationParameterService_ParameterChange(object? sender, string? e)
21
43
{
44
ListViewService.ListView.DoubleTapped += ListView_DoubleTapped;
22
45
var tokenSource = new CancellationTokenSource();
23
46
TokenSource = tokenSource;
24
47
var result = await GetSource(e, TokenSource.Token);
@@ -311,7 +311,7 @@ public partial class NewsViewPageViewModel : ViewModelBase
311
311
void OpenInBrowser()
312
312
{
313
313
if (NewsListViewService.ListView.SelectedItem is NewsSource newsSource)
314
Process.Start(new ProcessStartInfo(newsSource.Url) { UseShellExecute = true });
314
Helper.OpenInBrowser(newsSource.Url);
315
315
}
316
316
317
317
[RelayCommand]
@@ -437,10 +437,6 @@ public partial class NewsViewPageViewModel : ViewModelBase
437
437
if (imageUrl.IsNullOrEmpty())
438
438
return;
439
439
var uri = new Uri(imageUrl);
440
var processStartInfo = new ProcessStartInfo(uri.AbsoluteUri)
441
{
442
UseShellExecute = true
443
};
444
Process.Start(processStartInfo);
440
Helper.OpenInBrowser(uri.AbsoluteUri);
445
441
}
446
442
}
@@ -54,7 +54,7 @@ public partial class SettingPageViewModel : ViewModelBase
54
54
}
55
55
56
56
[RelayCommand]
57
static void OpenPath(string originalPath) => Process.Start("explorer.exe", originalPath);
57
static void OpenPath(string originalPath) => Helper.OpenPath(originalPath);
58
58
59
59
[RelayCommand]
60
60
async Task ClearCache()
@@ -36,17 +36,17 @@
36
36
<AutoSuggestBox QueryIcon="Find" PlaceholderText="搜索新闻源"/>
37
37
</NavigationView.AutoSuggestBox>
38
38
<NavigationView.MenuItems>
39
<NavigationViewItem Content="MSN新闻" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.NewsViewPage" add:NavigationAddition.NavigateParameter="MSN">
39
<NavigationViewItem Content="MSN 新闻" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.NewsViewPage" add:NavigationAddition.NavigateParameter="MSN">
40
40
<NavigationViewItem.Icon>
41
41
<ImageIcon Source="https://www.msn.com/favicon.ico" Width="16" Height="16"/>
42
42
</NavigationViewItem.Icon>
43
43
</NavigationViewItem>
44
<NavigationViewItem Content="微博热搜" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.HotSearchViewPage" add:NavigationAddition.NavigateParameter="Weibo">
44
<NavigationViewItem Content="微博 热搜" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.HotSearchViewPage" add:NavigationAddition.NavigateParameter="Weibo">
45
45
<NavigationViewItem.Icon>
46
46
<ImageIcon Source="https://m.weibo.cn/favicon.ico" Width="16" Height="16"/>
47
47
</NavigationViewItem.Icon>
48
48
</NavigationViewItem>
49
<NavigationViewItem Content="BiliBili热搜" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.HotSearchViewPage" add:NavigationAddition.NavigateParameter="Bilibili">
49
<NavigationViewItem Content="BiliBili 热搜" add:NavigationAddition.NavigateTo="XFENewsApplication.Views.HotSearchViewPage" add:NavigationAddition.NavigateParameter="Bilibili">
50
50
<NavigationViewItem.Icon>
51
51
<ImageIcon Source="https://www.bilibili.com/favicon.ico" Width="16" Height="16"/>
52
52
</NavigationViewItem.Icon>
@@ -14,19 +14,18 @@
14
14
</Page.Resources>
15
15
16
16
<Grid>
17
<ListView ItemsSource="{x:Bind ViewModel.HotSearchSource}" IsDoubleTapEnabled="True" DoubleTapped="ListView_DoubleTapped">
17
<ListView x:Name="hotSearchListView" ItemsSource="{x:Bind ViewModel.HotSearchSource}" SelectedIndex="{x:Bind ViewModel.SelectedIndex, Mode=TwoWay}" IsDoubleTapEnabled="True">
18
18
<ListView.ItemTemplate>
19
19
<DataTemplate x:DataType="coremodel:NewsSource">
20
20
<Grid>
21
21
<Grid.ColumnDefinitions>
22
<ColumnDefinition Width="30"/>
23
22
<ColumnDefinition Width="30"/>
24
23
<ColumnDefinition Width="*"/>
25
24
</Grid.ColumnDefinitions>
26
25
<TextBlock Text="{x:Bind Index}" VerticalAlignment="Center" FontSize="18"/>
27
<Image MaxWidth="{x:Bind ImageWidth}" Height="{x:Bind ImageHeight}" Grid.Column="1" Source="{x:Bind ImageUrl, Converter={StaticResource URLImageConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
28
<StackPanel Orientation="Horizontal" Grid.Column="2" Spacing="10" VerticalAlignment="Center">
26
<StackPanel Orientation="Horizontal" Grid.Column="1" Spacing="5" VerticalAlignment="Center">
29
27
<TextBlock Text="{x:Bind Title}" VerticalAlignment="Center" FontSize="15"/>
28
<Image Margin="0,0,5,0" Height="{x:Bind ImageHeight}" Source="{x:Bind ImageUrl, Converter={StaticResource URLImageConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
30
29
<TextBlock Text="{x:Bind Abstract}" VerticalAlignment="Center" Foreground="{ThemeResource TextFillColorDisabled}"/>
31
30
</StackPanel>
32
31
</Grid>
@@ -1,5 +1,4 @@
1
using Microsoft.UI.Xaml.Input;
2
using Microsoft.UI.Xaml.Navigation;
1
using Microsoft.UI.Xaml.Navigation;
3
2
4
3
namespace XFENewsApplication.Views;
5
4
@@ -16,6 +15,7 @@ public sealed partial class HotSearchViewPage : Page
16
15
Current = this;
17
16
this.InitializeComponent();
18
17
ViewModel.NavigationParameterService.Initialize(this);
18
ViewModel.ListViewService.Initialize(hotSearchListView);
19
19
}
20
20
21
21
protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -29,9 +29,4 @@ public sealed partial class HotSearchViewPage : Page
29
29
base.OnNavigatedFrom(e);
30
30
ViewModel.TokenSource?.Cancel();
31
31
}
32
33
private void ListView_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
34
{
35
36
}
37
32
}