Skip to content

Commit

Permalink
根据分类加载分类列表数据
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjz authored and chenjz committed May 14, 2024
1 parent 8f05113 commit aeffdf1
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Peach.Application/Interfaces/IVodInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IVodInfoService
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<string> ClassifyAsync(string tid, string pg, string filter, string extend);
Task<VodListModel> ClassifyAsync(string tid, int pg, string filter, string extend);


/// <summary>
Expand Down
3 changes: 0 additions & 3 deletions Peach.Application/Services/SourceService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Newtonsoft.Json;
using Peach.Application.Interfaces;
using Peach.Model.Models;
using System;
using System.Net.Http;
using System.Xml.Linq;


namespace Peach.Application.Services
Expand Down
6 changes: 3 additions & 3 deletions Peach.Application/Services/VodInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public async Task<VodListModel> HomeVodAsync(string filter)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<string> ClassifyAsync(string tid, string pg, string filter, string extend)
public async Task<VodListModel> ClassifyAsync(string tid, int pg, string filter, string extend)
{
try
{
return await jsSpider.HomeVodAsync(filter);
// return clas.ToObjectByJson<VodListModel>();
var cate = await jsSpider.CategoryAsync(tid, pg.ToString(), filter, extend);
return cate.ToObjectByJson<VodListModel>();
}
catch (Exception e)
{
Expand Down
41 changes: 5 additions & 36 deletions Peach.Drpy/HtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Jint;
using Jint.Native;
using Jint.Runtime;
using NSoup;
using NSoup.Nodes;
using NSoup.Select;
Expand Down Expand Up @@ -47,41 +48,8 @@ public string GetHtml(string url)
/// <returns></returns>
public object request(string url, JsValue arguments)
{
//Uri uri = new Uri(url);
//string Host = uri.Host;

//if (arguments.IsObject())
//{
// var jsObject = arguments.AsObject();

// // 遍历对象的属性
// foreach (var property in jsObject.GetOwnProperties())
// {
// var propertyName = property.Key;
// var propertyValue = property.Value.Value;

// // 处理属性值
// }

// // 遍历对象的元素(如果是数组)
// if (jsObject.IsArray())
// {
// var array = jsObject.AsArray();

// for (var i = 0; i < array.Count(); i++)
// {
// var daaa = i.ToString();
// var elementValue = array.Get(i)?.ToString();

// // 处理元素值
// }
// }
//}
//else
//{
// // 处理其他类型的值
//}

Uri uri = new Uri(url);
string Host = uri.Host;

var method = arguments.Get("method")?.ToString();
var _headers = arguments.AsObject()["headers"].AsObject();
Expand Down Expand Up @@ -159,7 +127,8 @@ public object request(string url, JsValue arguments)
{
string[] cook = item.Split('=');
if (cook.Length == 2)
client.AddDefaultHeader("Cookie", Cookie);
request.AddCookie(cook[0].Trim(), cook[1].Trim(), "/", Host);
// client.AddDefaultHeader("Cookie", Cookie);
//client.AddCookie(cook[0].Trim(), cook[1].Trim(), "/", Host);
}
}
Expand Down
1 change: 1 addition & 0 deletions PeachPlayer/PeachPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.2.1" />
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.0.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.10" />
Expand Down
84 changes: 84 additions & 0 deletions PeachPlayer/ViewModels/ClassifyListViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Avalonia;
using Peach.Application.Interfaces;
using Peach.Model.Models;
using ReactiveUI;
using Splat;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;

namespace PeachPlayer.ViewModels
{
public class ClassifyListViewModel : ViewModelBase
{
private IVodInfoService vod;
private readonly ClassModel Class;
private readonly List<FilterModel> filters;
private int PgIndex = 1;

public string Type_Name => Class.Type_Name;

private VideoViewModel selectedVod;
public VideoViewModel SelectedVod
{
get { return selectedVod; }
set { this.RaiseAndSetIfChanged(ref selectedVod, value); }
}
public ObservableCollection<VideoViewModel> Videos { get; } = new();

private Vector offset;
public Vector Offset
{
get { return offset; }
set { this.RaiseAndSetIfChanged(ref offset, value); Debug.WriteLine($"offset:{offset}"); }
}

private Size viewport;
public Size Viewport
{
get { return viewport; }
set { this.RaiseAndSetIfChanged(ref viewport, value);Debug.WriteLine($"verticalViewport:{viewport}"); }
}


public ClassifyListViewModel(ClassModel _class, List<FilterModel> _filters = null)
{
vod = Locator.Current.GetService<IVodInfoService>();
Class = _class;
filters = _filters;
}

public async void LoadVodList()
{
Videos.Clear();
var data = await vod?.ClassifyAsync(Class.Type_Id, PgIndex, "", "");
if (data?.List?.Count > 0)
{
var vods = data.List.Select(x => new VideoViewModel(x));
foreach (var v in vods)
{
Videos.Add(v);
}
}
}

public async void NextPage()
{
PgIndex++;
var data = await vod?.ClassifyAsync(Class.Type_Id, PgIndex, "", "");
if (data?.List?.Count > 0)
{
var vods = data.List.Select(x => new VideoViewModel(x));
foreach (var v in vods)
{
Videos.Add(v);
}
}
}



}
}
36 changes: 29 additions & 7 deletions PeachPlayer/ViewModels/FilmTelevisionViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Peach.Application.Interfaces;
using DynamicData;
using Jint.Runtime;
using Peach.Application.Interfaces;
using Peach.Model.Models;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Splat;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;

namespace PeachPlayer.ViewModels;
Expand All @@ -18,9 +21,16 @@ public class FilmTelevisionViewModel : ViewModelBase
// private set => this.RaiseAndSetIfChanged(ref listItems, value);
//}
[Reactive]
public ObservableCollection<ClassModel> Types { get; set; }
[Reactive]
public ObservableCollection<SmallVodModel> VodList { get; set; }
public ObservableCollection<ClassifyListViewModel> Types { get; set; } = new();


private ClassifyListViewModel selectedType;

public ClassifyListViewModel SelectedType
{
get { return selectedType; }
set { selectedType = value; this.RaiseAndSetIfChanged(ref selectedType, value); selectedType?.LoadVodList(); }
}

public ReactiveCommand<SiteModel, Unit> SwitchSiteCommand { get; }

Expand Down Expand Up @@ -49,11 +59,23 @@ private async void LoadSource()

public async void SwitchSite(SiteModel site)
{
Types.Clear();
await vod.InitSite(site);
var filter = await vod.HomeAsync();
Types = new ObservableCollection<ClassModel>(filter.Class);
//var vods = await vod.HomeVodAsync("");
//VodList = new ObservableCollection<SmallVodModel>(vods.List);
if (filter != null && filter?.Class?.Count > 0)
{
var classify = filter.Class.Select(x =>
{
if (filter.filters?.ContainsKey(x.Type_Id) == true)
return new ClassifyListViewModel(x, filter.filters[x.Type_Id]);
else
return new ClassifyListViewModel(x);
});
foreach (var item in classify)
{
Types.Add(item);
}
}
}


Expand Down
23 changes: 12 additions & 11 deletions PeachPlayer/ViewModels/VideoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@

using Peach.Model.Models;

namespace PeachPlayer.ViewModels
{
internal class VideoViewModel : ViewModelBase
public class VideoViewModel : ViewModelBase
{

public VideoViewModel()
{

}
private readonly SmallVodModel Vod;


private string typeId;

public string TypeId
public VideoViewModel(SmallVodModel vod)
{
get { return typeId; }
set { typeId = value; }
Vod = vod;
}

public string Vid => Vod.vod_id;
public string Vname => Vod.vod_name;
public string VRemarks => Vod.vod_remarks;
public string VPoc => Vod.vod_pic;
public string VContent => Vod.vod_content;

}
}
18 changes: 18 additions & 0 deletions PeachPlayer/Views/ClassifyListView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PeachPlayer.Views.ClassifyListView"
xmlns:vm="using:PeachPlayer.ViewModels"
x:DataType="vm:ClassifyListViewModel">

<ListBox ItemsSource="{Binding Videos}" Background="Transparent" Margin="0 10">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

</UserControl>
13 changes: 13 additions & 0 deletions PeachPlayer/Views/ClassifyListView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace PeachPlayer.Views;

public partial class ClassifyListView : UserControl
{
public ClassifyListView()
{
InitializeComponent();
}
}
7 changes: 1 addition & 6 deletions PeachPlayer/Views/FilmTelevisionView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@

<Rectangle Grid.Column="1" Width="2" Stroke="{DynamicResource SystemListLowColor}" Fill="{DynamicResource SystemListLowColor}"/>

<TabControl ItemsSource="{Binding Types}" Grid.Column="2" Margin="5">
<TabControl ItemsSource="{Binding Types}" Grid.Column="2" Margin="5" SelectedItem="{Binding SelectedType}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Type_Name}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate x:DataType="md:ClassModel">
<vods:VideoView TypeId="{Binding Type_Id}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>

</Grid>
Expand Down
17 changes: 12 additions & 5 deletions PeachPlayer/Views/VideoView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:vm="using:PeachPlayer.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
mc:Ignorable="d" d:DesignWidth="160" d:DesignHeight="230"
x:Class="PeachPlayer.Views.VideoView"
x:DataType="vm:VideoViewModel">
<StackPanel Spacing="5" Width="200">
<!--<Image Width="200" Stretch="Uniform" Source="{Binding Cover}"/>-->
<Panel>
<TextBlock HorizontalAlignment="Center" Text="{Binding TypeId}"/>
<StackPanel Width="140" Height="200">
<Panel Width="140" Height="180" HorizontalAlignment="Center">
<Image Stretch="Fill" asyncImageLoader:ImageLoader.Source="{Binding VPoc}"/>
<Border Margin="0,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Panel>
<Border Background="Black" CornerRadius="0,0,5,0" Opacity=".4"/>
<TextBlock HorizontalAlignment="Center" Text="{Binding VRemarks}"/>
</Panel>
</Border>
</Panel>
<TextBlock HorizontalAlignment="Center" Text="{Binding Vname}"/>
</StackPanel>
</UserControl>

0 comments on commit aeffdf1

Please sign in to comment.