mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-06 18:17:46 +08:00
search download
This commit is contained in:
13
pkg/utils/utils.go
Normal file
13
pkg/utils/utils.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "unicode"
|
||||||
|
|
||||||
|
func isASCII(s string) bool {
|
||||||
|
for _, c := range s {
|
||||||
|
if c > unicode.MaxASCII {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
@@ -49,9 +49,9 @@ func (s *Server) AddTorznabInfo(c *gin.Context) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type searchAndDownloadIn struct {
|
type searchAndDownloadIn struct {
|
||||||
Title string `json:"title"`
|
ID int `json:"id"`
|
||||||
Season int `json:"season"`
|
Season int `json:"season"`
|
||||||
Episode int `json:"episode"`
|
Episode int `json:"episode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
||||||
@@ -64,8 +64,16 @@ func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "connect transmission")
|
return nil, errors.Wrap(err, "connect transmission")
|
||||||
}
|
}
|
||||||
|
log.Infof("search episode resources link: %v", in)
|
||||||
|
series := s.db.GetSeriesDetails(in.ID)
|
||||||
|
if series == nil {
|
||||||
|
return nil, fmt.Errorf("no tv series of id %v", in.ID)
|
||||||
|
}
|
||||||
|
|
||||||
res := s.searchTvWithTorznab(in.Title, in.Season, in.Episode)
|
res := s.searchTvWithTorznab(series.OriginalName, in.Season, in.Episode)
|
||||||
|
if len(res) == 0 {
|
||||||
|
return "", fmt.Errorf("no resource found")
|
||||||
|
}
|
||||||
r1 := res[0]
|
r1 := res[0]
|
||||||
log.Infof("found resource to download: %v", r1)
|
log.Infof("found resource to download: %v", r1)
|
||||||
torrent, err := trc.Download(r1.Magnet)
|
torrent, err := trc.Download(r1.Magnet)
|
||||||
@@ -78,7 +86,9 @@ func (s *Server) SearchAndDownload(c *gin.Context) (interface{}, error) {
|
|||||||
// return nil, errors.Wrap(err, "download torrent")
|
// return nil, errors.Wrap(err, "download torrent")
|
||||||
// }
|
// }
|
||||||
log.Errorf("success add %s to download task", r1.Name)
|
log.Errorf("success add %s to download task", r1.Name)
|
||||||
return nil, nil
|
return gin.H{
|
||||||
|
"name": r1.Name,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type downloadClientIn struct {
|
type downloadClientIn struct {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class APIs {
|
|||||||
static final settingsUrl = "$_baseUrl/api/v1/setting/do";
|
static final settingsUrl = "$_baseUrl/api/v1/setting/do";
|
||||||
static final watchlistUrl = "$_baseUrl/api/v1/tv/watchlist";
|
static final watchlistUrl = "$_baseUrl/api/v1/tv/watchlist";
|
||||||
static final seriesDetailUrl = "$_baseUrl/api/v1/tv/series/";
|
static final seriesDetailUrl = "$_baseUrl/api/v1/tv/series/";
|
||||||
|
static final searchAndDownloadUrl = "$_baseUrl/api/v1/indexer/download";
|
||||||
|
|
||||||
static const tmdbImgBaseUrl = "https://image.tmdb.org/t/p/w500/";
|
static const tmdbImgBaseUrl = "https://image.tmdb.org/t/p/w500/";
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class MyApp extends StatelessWidget {
|
|||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: WelcomePage.route,
|
path: WelcomePage.route,
|
||||||
builder: (context, state) => WelcomePage(),
|
builder: (context, state) => const WelcomePage(),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: SearchPage.route,
|
path: SearchPage.route,
|
||||||
@@ -63,7 +63,7 @@ class MyApp extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: SystemSettingsPage.route,
|
path: SystemSettingsPage.route,
|
||||||
builder: (context, state) => SystemSettingsPage(),
|
builder: (context, state) => const SystemSettingsPage(),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: TvDetailsPage.route,
|
path: TvDetailsPage.route,
|
||||||
@@ -107,3 +107,16 @@ class MyApp extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CustomTransitionPage buildPageWithDefaultTransition<T>({
|
||||||
|
required BuildContext context,
|
||||||
|
required GoRouterState state,
|
||||||
|
required Widget child,
|
||||||
|
}) {
|
||||||
|
return CustomTransitionPage<T>(
|
||||||
|
key: state.pageKey,
|
||||||
|
child: child,
|
||||||
|
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||||
|
FadeTransition(opacity: animation, child: child),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class _TvDetailsPageState extends State<TvDetailsPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
_querySeriesDetails();
|
_querySeriesDetails();
|
||||||
}
|
}
|
||||||
@@ -62,7 +61,12 @@ class _TvDetailsPageState extends State<TvDetailsPage> {
|
|||||||
),
|
),
|
||||||
Text("${ep.title}", textAlign: TextAlign.left),
|
Text("${ep.title}", textAlign: TextAlign.left),
|
||||||
const Expanded(child: Text("")),
|
const Expanded(child: Text("")),
|
||||||
IconButton(onPressed: () {}, icon: const Icon(Icons.search))
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
_searchAndDownload(
|
||||||
|
context, seriesId, ep.seasonNumber!, ep.episodeNumber!);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.search))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -148,6 +152,24 @@ class _TvDetailsPageState extends State<TvDetailsPage> {
|
|||||||
details = SeriesDetails.fromJson(rsp.data);
|
details = SeriesDetails.fromJson(rsp.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _searchAndDownload(BuildContext context, String seriesId, int seasonNum,
|
||||||
|
int episodeNum) async {
|
||||||
|
var resp = await Dio().post(APIs.searchAndDownloadUrl, data: {
|
||||||
|
"id": int.parse(seriesId),
|
||||||
|
"season": seasonNum,
|
||||||
|
"episode": episodeNum,
|
||||||
|
});
|
||||||
|
var sp = ServerResponse.fromJson(resp.data);
|
||||||
|
if (sp.code != 0 && context.mounted) {
|
||||||
|
Utils.showAlertDialog(context, sp.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var name = (sp.data as Map<String, dynamic>)["name"];
|
||||||
|
if (context.mounted) {
|
||||||
|
Utils.showSnakeBar(context, "$name 开始下载...");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SeriesDetails {
|
class SeriesDetails {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
static Future<void> showAlertDialog(BuildContext context, String msg) async {
|
static Future<void> showAlertDialog(BuildContext context, String msg) async {
|
||||||
|
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true, // user must tap button!
|
barrierDismissible: true, // user must tap button!
|
||||||
@@ -28,4 +27,8 @@ class Utils {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static showSnakeBar(BuildContext context, String msg) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user