mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-08 02:57:38 +08:00
chore: update watchlist
This commit is contained in:
@@ -3,17 +3,28 @@ package douban
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"polaris/log"
|
||||
"polaris/pkg/importlist"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
type DoulistItem struct {
|
||||
Name string
|
||||
ImdbID string
|
||||
}
|
||||
const ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
|
||||
|
||||
func ParseDoulist(doulistUrl string) ([]DoulistItem, error) {
|
||||
res, err := http.Get(doulistUrl)
|
||||
func ParseDoulist(doulistUrl string) (*importlist.Response, error) {
|
||||
if !strings.Contains(doulistUrl, "doulist") {
|
||||
return nil, fmt.Errorf("not doulist")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", doulistUrl, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("User-Agent", ua)
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -26,6 +37,64 @@ func ParseDoulist(doulistUrl string) ([]DoulistItem, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc.Find("")
|
||||
doc.Find("div[class=doulist-item]").Each(func(i int, selection *goquery.Selection) {
|
||||
titleDiv := selection.Find("div[class=title]")
|
||||
link := titleDiv.Find("div>a")
|
||||
href, ok := link.Attr("href")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
abstract := selection.Find("div[class=abstract]")
|
||||
|
||||
lines := strings.Split(abstract.Text(), "\n")
|
||||
year := 0
|
||||
for _, l := range lines {
|
||||
if strings.Contains(l, "年份") {
|
||||
ppp := strings.Split(l, ":")
|
||||
if len(ppp) < 2 {
|
||||
continue
|
||||
} else {
|
||||
n := ppp[1]
|
||||
n1, err := strconv.Atoi(n)
|
||||
if err != nil {
|
||||
log.Errorf("convert year number %s to int error: %v", n, err)
|
||||
continue
|
||||
}
|
||||
year = n1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item := importlist.Item{
|
||||
Title: strings.TrimSpace(link.Text()),
|
||||
Year: year,
|
||||
}
|
||||
_ = item
|
||||
println(link.Text(), href)
|
||||
})
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func parseDetailPage(url string) (string, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("User-Agent", ua)
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
return "", fmt.Errorf("status code error: %d %s", res.StatusCode, res.Status)
|
||||
|
||||
}
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_ = doc
|
||||
return "", nil
|
||||
}
|
||||
|
||||
11
pkg/importlist/douban/douban_test.go
Normal file
11
pkg/importlist/douban/douban_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package douban
|
||||
|
||||
import (
|
||||
"polaris/log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseDoulist(t *testing.T) {
|
||||
r, err := ParseDoulist("https://www.douban.com/doulist/166422/")
|
||||
log.Info(r, err)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package importlist
|
||||
|
||||
type Item struct {
|
||||
Title string
|
||||
Year int
|
||||
ImdbID string
|
||||
TvdbID string
|
||||
TmdbID string
|
||||
|
||||
@@ -17,7 +17,7 @@ Future<void> showSettingDialog(
|
||||
content: SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
child: body,
|
||||
child: SelectionArea(child: body),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
|
||||
@@ -17,6 +17,7 @@ class Importlist extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _ImportlistState extends ConsumerState<Importlist> {
|
||||
String? _selectedType;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var importlists = ref.watch(importlistProvider);
|
||||
@@ -42,16 +43,39 @@ class _ImportlistState extends ConsumerState<Importlist> {
|
||||
Future<void> showImportlistDetails(ImportList list) {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
|
||||
setState(() {
|
||||
_selectedType = list.type;
|
||||
});
|
||||
var body = FormBuilder(
|
||||
key: _formKey,
|
||||
initialValue: {
|
||||
"name": list.name,
|
||||
"url": list.url,
|
||||
"qulity": list.qulity,
|
||||
"type": list.type,
|
||||
"storage_id": list.storageId
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderDropdown(
|
||||
name: "type",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "类型",
|
||||
hintText:
|
||||
"Plex Watchlist: https://support.plex.tv/articles/universal-watchlist/"),
|
||||
items: const [
|
||||
DropdownMenuItem(value: "plex", child: Text("Plex Watchlist")),
|
||||
],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedType = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
_selectedType == "plex"
|
||||
? const Text(
|
||||
"Plex Watchlist: https://support.plex.tv/articles/universal-watchlist/")
|
||||
: const Text(""),
|
||||
FormBuilderTextField(
|
||||
name: "name",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
@@ -103,12 +127,12 @@ class _ImportlistState extends ConsumerState<Importlist> {
|
||||
onSubmit() async {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
|
||||
|
||||
return ref.read(importlistProvider.notifier).addImportlist(ImportList(
|
||||
id: list.id,
|
||||
name: values["name"],
|
||||
url: values["url"],
|
||||
type: "plex",
|
||||
type: values["type"],
|
||||
qulity: values["qulity"],
|
||||
storageId: values["storage_id"],
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user