1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480 |
- package search
- import (
- "context"
- "net/http"
- "net/url"
- "strconv"
- "time"
- "go-common/app/interface/main/app-interface/conf"
- arcdao "go-common/app/interface/main/app-interface/dao/archive"
- bangumidao "go-common/app/interface/main/app-interface/dao/bangumi"
- livedao "go-common/app/interface/main/app-interface/dao/live"
- "go-common/app/interface/main/app-interface/model"
- bangumimdl "go-common/app/interface/main/app-interface/model/bangumi"
- livemdl "go-common/app/interface/main/app-interface/model/live"
- "go-common/app/interface/main/app-interface/model/search"
- "go-common/app/service/main/archive/api"
- locmdl "go-common/app/service/main/location/model"
- locrpc "go-common/app/service/main/location/rpc/client"
- seasongrpc "go-common/app/service/openplatform/pgc-season/api/grpc/season/v1"
- "go-common/library/ecode"
- "go-common/library/log"
- httpx "go-common/library/net/http/blademaster"
- "go-common/library/net/metadata"
- "go-common/library/sync/errgroup"
- "github.com/pkg/errors"
- )
- const (
- _main = "/main/search"
- _suggest = "/main/suggest"
- _hot = "/main/hotword"
- _defaultWords = "/widget/getSearchDefaultWords"
- _rcmd = "/query/recommend"
- _rcmdNoResult = "/search/recommend"
- _suggest3 = "/main/suggest/new"
- _pre = "/search/frontpage"
- )
- const (
- _oldAndroid = 514000
- _oldIOS = 6090
- _searchCodeLimitAndroid = 5250001
- _searchCodeLimitIPhone = 6680
- )
- // Dao is search dao
- type Dao struct {
- c *conf.Config
- arcDao *arcdao.Dao
- liveDao *livedao.Dao
- bangumiDao *bangumidao.Dao
- client *httpx.Client
- client2 *httpx.Client
- main string
- suggest string
- hot string
- defaultWords string
- rcmd string
- rcmdNoResult string
- suggest3 string
- pre string
- // rpc
- locRPC *locrpc.Service
- }
- // New initial search dao
- func New(c *conf.Config) (d *Dao) {
- d = &Dao{
- c: c,
- arcDao: arcdao.New(c),
- liveDao: livedao.New(c),
- bangumiDao: bangumidao.New(c),
- client: httpx.NewClient(c.HTTPSearch),
- client2: httpx.NewClient(c.HTTPClient),
- main: c.Host.Search + _main,
- suggest: c.Host.Search + _suggest,
- hot: c.Host.Search + _hot,
- defaultWords: c.Host.WWW + _defaultWords,
- rcmd: c.Host.Search + _rcmd,
- rcmdNoResult: c.Host.Search + _rcmdNoResult,
- suggest3: c.Host.Search + _suggest3,
- pre: c.Host.Search + _pre,
- locRPC: locrpc.New(c.LocationRPC),
- }
- return
- }
- // Search app all search .
- func (d *Dao) Search(c context.Context, mid, zoneid int64, mobiApp, device, platform, buvid, keyword, duration, order, filtered, fromSource, recommend, parent string, plat int8, seasonNum, movieNum, upUserNum, uvLimit, userNum, userVideoLimit, biliUserNum, biliUserVideoLimit, rid, highlight, build, pn, ps, isQuery int, old bool, now time.Time, newPGC, flow bool) (res *search.Search, code int, err error) {
- var (
- req *http.Request
- ip = metadata.String(c, metadata.RemoteIP)
- ipInfo *locmdl.Info
- )
- if ipInfo, err = d.locRPC.Info(c, &locmdl.ArgIP{IP: ip}); err != nil {
- log.Warn("%v", err)
- err = nil
- }
- res = &search.Search{}
- params := url.Values{}
- params.Set("build", strconv.Itoa(build))
- params.Set("keyword", keyword)
- params.Set("main_ver", "v3")
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("tids", strconv.Itoa(rid))
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- if newPGC {
- params.Set("media_bangumi_num", strconv.Itoa(seasonNum))
- } else {
- params.Set("bangumi_num", strconv.Itoa(seasonNum))
- params.Set("smerge", "1")
- }
- if (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) {
- params.Set("is_new_user", "1")
- } else {
- if old {
- params.Set("upuser_num", strconv.Itoa(upUserNum))
- params.Set("uv_limit", strconv.Itoa(uvLimit))
- } else {
- params.Set("bili_user_num", strconv.Itoa(biliUserNum))
- params.Set("bili_user_vl", strconv.Itoa(biliUserVideoLimit))
- }
- params.Set("user_num", strconv.Itoa(userNum))
- params.Set("user_video_limit", strconv.Itoa(userVideoLimit))
- params.Set("query_rec_need", recommend)
- }
- params.Set("platform", platform)
- params.Set("duration", duration)
- params.Set("order", order)
- params.Set("search_type", "all")
- params.Set("from_source", fromSource)
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- if model.IsOverseas(plat) {
- params.Set("use_area", "1")
- params.Set("zone_id", strconv.FormatInt(zoneid, 10))
- } else if newPGC {
- params.Set("media_ft_num", strconv.Itoa(movieNum))
- params.Set("is_new_pgc", "1")
- } else {
- params.Set("movie_num", strconv.Itoa(movieNum))
- }
- if flow {
- params.Set("flow_need", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.ComicAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.ComicIOS) || model.IsIPhoneB(plat) {
- params.Set("is_comic", "1")
- }
- if (model.IsAndroid(plat) && build > search.SearchLiveAllAndroid) || (model.IsIPhone(plat) && build > search.SearchLiveAllIOS) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- params.Set("new_live", "1")
- }
- if (model.IsAndroid(plat) && build > search.SearchTwitterAndroid) || (model.IsIPhone(plat) && build > search.SearchTwitterIOS) || model.IsIPhoneB(plat) {
- params.Set("is_twitter", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.PGCHighLightAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.PGCHighLightIOS) {
- params.Set("app_highlight", "media_bangumi,media_ft")
- }
- if (model.IsAndroid(plat) && build >= search.SearchConvergeAndroid) || (model.IsIPhone(plat) && build >= search.SearchConvergeIOS) || model.IsIPhoneB(plat) {
- params.Set("card_num", "1")
- }
- params.Set("is_parents", parent)
- if (model.IsAndroid(plat) && build > search.SearchStarAndroid) || (model.IsIPhone(plat) && build > search.SearchStarIOS) || model.IsIPhoneB(plat) {
- params.Set("is_star", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.PGCALLAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.PGCALLIOS) || model.IsIPhoneB(plat) {
- params.Set("is_pgc_all", "1")
- }
- if (model.IsAndroid(plat) && build > search.SearchTicketAndroid) || (model.IsIPhone(plat) && build > search.SearchTicketIOS) || model.IsIPhoneB(plat) {
- params.Set("is_ticket", "1")
- }
- if (model.IsAndroid(plat) && build > search.SearchProductAndroid) || (model.IsIPhone(plat) && build > search.SearchProductIOS) || model.IsIPhoneB(plat) {
- params.Set("is_product", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SearchArticleAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SearchArticleIOS) || model.IsIPhoneB(plat) {
- params.Set("is_article", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.ChannelAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.ChannelIOS) {
- params.Set("is_tag", "1")
- }
- params.Set("is_org_query", strconv.Itoa(isQuery))
- if ipInfo != nil {
- params.Set("user_city", ipInfo.City)
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- if err = d.client.Do(c, req, res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- }
- for _, flow := range res.FlowResult {
- flow.Change()
- }
- code = res.Code
- return
- }
- // Season search season data.
- func (d *Dao) Season(c context.Context, mid, zoneID int64, keyword, mobiApp, device, platform, buvid, filtered string, plat int8, build, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("build", strconv.Itoa(build))
- params.Set("keyword", keyword)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("func", "search")
- params.Set("smerge", "1")
- params.Set("search_type", "bangumi")
- params.Set("source_type", "0")
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- if model.IsOverseas(plat) {
- params.Set("use_area", "1")
- params.Set("zone_id", strconv.FormatInt(zoneID, 10))
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Bangumi `json:"result"`
- }
- // do
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- if (model.IsAndroid(plat) && build <= _oldAndroid) || (model.IsIPhone(plat) && build <= _oldIOS) {
- si.FromSeason(v, model.GotoBangumi)
- } else {
- si.FromSeason(v, model.GotoBangumiWeb)
- }
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // Upper search upper data.
- func (d *Dao) Upper(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid, filtered, order string, biliUserVL, highlight, build, userType, orderSort, pn, ps int, old bool, now time.Time) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- avids []int64
- avm map[int64]*api.Arc
- roomIDs []int64
- lm map[int64]*livemdl.RoomInfo
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("keyword", keyword)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("func", "search")
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("smerge", "1")
- params.Set("platform", platform)
- params.Set("build", strconv.Itoa(build))
- if old {
- params.Set("search_type", "upuser")
- } else {
- params.Set("search_type", "bili_user")
- params.Set("bili_user_vl", strconv.Itoa(biliUserVL))
- params.Set("user_type", strconv.Itoa(userType))
- params.Set("order_sort", strconv.Itoa(orderSort))
- }
- params.Set("order", order)
- params.Set("source_type", "0")
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.User `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- for _, vr := range v.Res {
- avids = append(avids, vr.Aid)
- }
- roomIDs = append(roomIDs, v.RoomID)
- }
- g, ctx := errgroup.WithContext(c)
- if len(avids) != 0 {
- g.Go(func() (err error) {
- if avm, err = d.arcDao.Archives2(ctx, avids); err != nil {
- log.Error("Upper %+v", err)
- err = nil
- }
- return
- })
- }
- if len(roomIDs) > 0 {
- g.Go(func() (err error) {
- if lm, err = d.liveDao.LiveByRIDs(ctx, roomIDs); err != nil {
- log.Error("Upper %+v", err)
- err = nil
- }
- return
- })
- }
- if err = g.Wait(); err != nil {
- log.Error("%+v", err)
- return
- }
- for _, v := range res.List {
- si := &search.Item{}
- si.FromUpUser(v, avm, lm[v.RoomID])
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // MovieByType search movie data from api .
- func (d *Dao) MovieByType(c context.Context, mid, zoneid int64, keyword, mobiApp, device, platform, buvid, filtered string, plat int8, build, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- avids []int64
- avm map[int64]*api.Arc
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", "pgc")
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("order", "totalrank")
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- if model.IsOverseas(plat) {
- params.Set("use_area", "1")
- params.Set("zone_id", strconv.FormatInt(zoneid, 10))
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Movie `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- if v.Type == "movie" {
- avids = append(avids, v.Aid)
- }
- }
- if len(avids) != 0 {
- if avm, err = d.arcDao.Archives2(c, avids); err != nil {
- log.Error("RecommendNoResult %+v", err)
- err = nil
- }
- }
- for _, v := range res.List {
- si := &search.Item{}
- si.FromMovie(v, avm)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // LiveByType search by diff type
- func (d *Dao) LiveByType(c context.Context, mid, zoneid int64, keyword, mobiApp, device, platform, buvid, filtered, order, sType string, plat int8, build, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- ip = metadata.String(c, metadata.RemoteIP)
- // roomIDs []int64
- // lm map[int64]*livemdl.RoomInfo
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", sType)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("order", order)
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- if model.IsOverseas(plat) {
- params.Set("use_area", "1")
- params.Set("zone_id", strconv.FormatInt(zoneid, 10))
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Live `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- // for _, v := range res.List {
- // roomIDs = append(roomIDs, v.RoomID)
- // }
- // if len(roomIDs) > 0 {
- // if lm, err = d.liveDao.LiveByRIDs(c, roomIDs, ip); err != nil {
- // log.Error("LiveByType %+v", err)
- // err = nil
- // }
- // }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromLive(v, nil)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // Live search for live
- func (d *Dao) Live(c context.Context, mid int64, keyword, mobiApp, platform, buvid, device, order, sType string, build, pn, ps int) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- roomIDs []int64
- lm map[int64]*livemdl.RoomInfo
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", sType)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("device", device)
- params.Set("order", order)
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Live `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- if !model.IsAndroid(plat) || (model.IsAndroid(plat) && build > search.LiveBroadcastTypeAndroid) {
- for _, v := range res.List {
- roomIDs = append(roomIDs, v.RoomID)
- }
- if len(roomIDs) > 0 {
- if lm, err = d.liveDao.LiveByRIDs(c, roomIDs); err != nil {
- log.Error("Live %+v", err)
- err = nil
- }
- }
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromLive2(v, lm[v.RoomID])
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // LiveAll search for live version > 5.28
- func (d *Dao) LiveAll(c context.Context, mid int64, keyword, mobiApp, platform, buvid, device, order, sType string, build, pn, ps int) (st *search.TypeSearchLiveAll, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- roomIDs []int64
- lm map[int64]*livemdl.RoomInfo
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", sType)
- params.Set("page", strconv.Itoa(pn))
- params.Set("live_room_num", strconv.Itoa(ps))
- params.Set("device", device)
- params.Set("order", order)
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- PageInfo *struct {
- Master *search.Live `json:"live_master"`
- Room *search.Live `json:"live_room"`
- } `json:"pageinfo"`
- List *struct {
- Master []*search.Live `json:"live_master"`
- Room []*search.Live `json:"live_room"`
- } `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || model.IsIPad(plat) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- st = &search.TypeSearchLiveAll{
- TrackID: res.SeID,
- Pages: res.Pages,
- Master: &search.TypeSearch{},
- Room: &search.TypeSearch{},
- }
- if res.PageInfo != nil {
- if res.PageInfo.Master != nil {
- st.Master.Pages = res.PageInfo.Master.Pages
- st.Master.Total = res.PageInfo.Master.Total
- }
- if res.PageInfo.Room != nil {
- st.Room.Pages = res.PageInfo.Room.Pages
- st.Room.Total = res.PageInfo.Room.Total
- }
- }
- if res.List != nil {
- if !model.IsAndroid(plat) || (model.IsAndroid(plat) && build > search.LiveBroadcastTypeAndroid) {
- for _, v := range res.List.Master {
- roomIDs = append(roomIDs, v.RoomID)
- }
- for _, v := range res.List.Room {
- roomIDs = append(roomIDs, v.RoomID)
- }
- if len(roomIDs) > 0 {
- if lm, err = d.liveDao.LiveByRIDs(c, roomIDs); err != nil {
- log.Error("LiveAll %+v", err)
- err = nil
- }
- }
- }
- st.Master.Items = make([]*search.Item, 0, len(res.List.Master))
- for _, v := range res.List.Master {
- si := &search.Item{}
- si.FromLiveMaster(v, lm[v.RoomID])
- st.Master.Items = append(st.Master.Items, si)
- }
- st.Room.Items = make([]*search.Item, 0, len(res.List.Room))
- for _, v := range res.List.Room {
- si := &search.Item{}
- si.FromLive2(v, lm[v.RoomID])
- st.Room.Items = append(st.Room.Items, si)
- }
- }
- return
- }
- // ArticleByType search article.
- func (d *Dao) ArticleByType(c context.Context, mid, zoneid int64, keyword, mobiApp, device, platform, buvid, filtered, order, sType string, plat int8, categoryID, build, highlight, pn, ps int, now time.Time) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("search_type", sType)
- params.Set("category_id", strconv.Itoa(categoryID))
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("order", order)
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- if model.IsOverseas(plat) {
- params.Set("use_area", "1")
- params.Set("zone_id", strconv.FormatInt(zoneid, 10))
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Article `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromArticle(v, nil)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // HotSearch is hot words search data.
- func (d *Dao) HotSearch(c context.Context, buvid string, mid int64, build, limit int, mobiApp, device, platform string, now time.Time) (res *search.Hot, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("actionKey", "appkey")
- params.Set("limit", strconv.Itoa(limit))
- params.Set("build", strconv.Itoa(build))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- req, err := d.client.NewRequest("GET", d.hot, ip, params)
- if err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- err = errors.Wrap(ecode.Int(res.Code), d.hot+"?"+params.Encode())
- }
- return
- }
- // Suggest suggest data.
- func (d *Dao) Suggest(c context.Context, mid int64, buvid, term string, build int, mobiApp, device string, now time.Time) (res *search.Suggest, err error) {
- plat := model.Plat(mobiApp, device)
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v4")
- params.Set("func", "suggest")
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("buvid", buvid)
- params.Set("build", strconv.Itoa(build))
- params.Set("mobi_app", mobiApp)
- params.Set("bangumi_acc_num", "3")
- params.Set("special_acc_num", "3")
- params.Set("topic_acc_num", "3")
- params.Set("upuser_acc_num", "1")
- params.Set("tag_num", "10")
- params.Set("special_num", "10")
- params.Set("bangumi_num", "10")
- params.Set("upuser_num", "3")
- params.Set("suggest_type", "accurate")
- params.Set("term", term)
- res = &search.Suggest{}
- if err = d.client.Get(c, d.suggest, ip, params, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.suggest+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.suggest+"?"+params.Encode())
- }
- return
- }
- if res.ResultBs == nil {
- return
- }
- switch v := res.ResultBs.(type) {
- case []interface{}:
- return
- case map[string]interface{}:
- if acc, ok := v["accurate"]; ok {
- if accm, ok := acc.(map[string]interface{}); ok && accm != nil {
- res.Result.Accurate.UpUser = accm["upuser"]
- res.Result.Accurate.Bangumi = accm["bangumi"]
- }
- }
- if tag, ok := v["tag"]; ok {
- if tags, ok := tag.([]interface{}); ok {
- for _, t := range tags {
- if tm, ok := t.(map[string]interface{}); ok && tm != nil {
- if v, ok := tm["value"]; ok {
- if vs, ok := v.(string); ok {
- res.Result.Tag = append(res.Result.Tag, &struct {
- Value string `json:"value,omitempty"`
- }{vs})
- }
- }
- }
- }
- }
- }
- }
- return
- }
- // Suggest2 suggest data.
- func (d *Dao) Suggest2(c context.Context, mid int64, platform, buvid, term string, build int, mobiApp string, now time.Time) (res *search.Suggest2, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v4")
- params.Set("suggest_type", "accurate")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("build", strconv.Itoa(build))
- if mid != 0 {
- params.Set("userid", strconv.FormatInt(mid, 10))
- }
- params.Set("term", term)
- params.Set("sug_num", "10")
- params.Set("buvid", buvid)
- res = &search.Suggest2{}
- if err = d.client.Get(c, d.suggest, ip, params, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- err = errors.Wrap(ecode.Int(res.Code), d.suggest+"?"+params.Encode())
- }
- return
- }
- // Suggest3 suggest data.
- func (d *Dao) Suggest3(c context.Context, mid int64, platform, buvid, term, device string, build, highlight int, mobiApp string, now time.Time) (res *search.Suggest3, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("suggest_type", "accurate")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("build", strconv.Itoa(build))
- if mid != 0 {
- params.Set("userid", strconv.FormatInt(mid, 10))
- }
- params.Set("term", term)
- params.Set("sug_num", "10")
- params.Set("buvid", buvid)
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SugDetailAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SugDetailIOS) {
- params.Set("is_detail_info", "1")
- }
- if req, err = d.client.NewRequest("GET", d.suggest3, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- res = &search.Suggest3{}
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- err = errors.Wrap(ecode.Int(res.Code), d.suggest3+"?"+params.Encode())
- return
- }
- for _, flow := range res.Result {
- flow.SugChange()
- }
- return
- }
- // Season2 search new season data.
- func (d *Dao) Season2(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid string, highlight, build, pn, ps int) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- ip = metadata.String(c, metadata.RemoteIP)
- seasonIDs []int64
- bangumis map[string]*bangumimdl.Card
- )
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("build", strconv.Itoa(build))
- params.Set("keyword", keyword)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("search_type", "media_bangumi")
- params.Set("order", "totalrank")
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("app_highlight", "media_bangumi")
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.PGCALLAndroid) || (model.IsIPhone(plat) && build >= d.c.SearchBuildLimit.PGCALLIOS) || model.IsIPhoneB(plat) {
- params.Set("is_pgc_all", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Total int `json:"numResults"`
- Pages int `json:"numPages"`
- List []*search.Media `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- for _, v := range res.List {
- seasonIDs = append(seasonIDs, v.SeasonID)
- }
- if len(seasonIDs) > 0 {
- if bangumis, err = d.bangumiDao.Card(c, mid, seasonIDs); err != nil {
- log.Error("Season2 %+v", err)
- err = nil
- }
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromMedia(v, "", model.GotoBangumi, bangumis)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Total: res.Total, Items: items}
- return
- }
- // MovieByType2 search new movie data from api .
- func (d *Dao) MovieByType2(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid string, highlight, build, pn, ps int) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- ip = metadata.String(c, metadata.RemoteIP)
- seasonIDs []int64
- bangumis map[string]*bangumimdl.Card
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", "media_ft")
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("order", "totalrank")
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("app_highlight", "media_ft")
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.PGCALLAndroid) || (model.IsIPhone(plat) && build >= d.c.SearchBuildLimit.PGCALLIOS) || model.IsIPhoneB(plat) {
- params.Set("is_pgc_all", "1")
- }
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Total int `json:"numResults"`
- Pages int `json:"numPages"`
- List []*search.Media `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- for _, v := range res.List {
- seasonIDs = append(seasonIDs, v.SeasonID)
- }
- if len(seasonIDs) > 0 {
- if bangumis, err = d.bangumiDao.Card(c, mid, seasonIDs); err != nil {
- log.Error("MovieByType2 %+v", err)
- err = nil
- }
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromMedia(v, "", model.GotoMovie, bangumis)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Total: res.Total, Items: items}
- return
- }
- // User search user data.
- func (d *Dao) User(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid, filtered, order, fromSource string, highlight, build, userType, orderSort, pn, ps int, now time.Time) (user []*search.User, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("build", strconv.Itoa(build))
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("keyword", keyword)
- params.Set("highlight", strconv.Itoa(highlight))
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("main_ver", "v3")
- params.Set("func", "search")
- params.Set("smerge", "1")
- params.Set("source_type", "0")
- params.Set("search_type", "bili_user")
- params.Set("user_type", strconv.Itoa(userType))
- params.Set("order", order)
- params.Set("order_sort", strconv.Itoa(orderSort))
- params.Set("from_source", fromSource)
- if filtered == "1" {
- params.Set("filtered", filtered)
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.User `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if (model.IsAndroid(plat) && build > _searchCodeLimitAndroid) || (model.IsIPhone(plat) && build > _searchCodeLimitIPhone) || (plat == model.PlatIPad && build >= search.SearchNewIPad) || (plat == model.PlatIpadHD && build >= search.SearchNewIPadHD) || model.IsIPhoneB(plat) {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- } else if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- user = res.List
- return
- }
- // Recommend is recommend search data.
- func (d *Dao) Recommend(c context.Context, mid int64, build, from, show int, buvid, platform, mobiApp, device string) (res *search.RecommendResult, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("device", device)
- params.Set("build", strconv.Itoa(build))
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("search_type", "guess")
- params.Set("req_source", strconv.Itoa(from))
- params.Set("show_area", strconv.Itoa(show))
- req, err := d.client.NewRequest("GET", d.rcmd, ip, params)
- if err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var rcmdRes struct {
- Code int `json:"code,omitempty"`
- SeID string `json:"seid,omitempty"`
- Tips string `json:"recommend_tips,omitempty"`
- NumResult int `json:"numResult,omitempty"`
- Resutl []struct {
- ID int64 `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Type string `json:"type,omitempty"`
- } `json:"result,omitempty"`
- }
- if err = d.client.Do(c, req, &rcmdRes); err != nil {
- return
- }
- if rcmdRes.Code != ecode.OK.Code() {
- if rcmdRes.Code != model.ForbidCode {
- err = errors.Wrap(ecode.Int(rcmdRes.Code), d.rcmd+"?"+params.Encode())
- }
- return
- }
- res = &search.RecommendResult{TrackID: rcmdRes.SeID, Title: rcmdRes.Tips, Pages: rcmdRes.NumResult}
- for _, v := range rcmdRes.Resutl {
- item := &search.Item{}
- item.ID = v.ID
- item.Param = strconv.Itoa(int(v.ID))
- item.Title = v.Name
- item.Type = v.Type
- res.Items = append(res.Items, item)
- }
- return
- }
- // DefaultWords is default words search data.
- func (d *Dao) DefaultWords(c context.Context, mid int64, build, from int, buvid, platform, mobiApp, device string) (res *search.DefaultWords, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("device", device)
- params.Set("build", strconv.Itoa(build))
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("search_type", "default")
- params.Set("req_source", strconv.Itoa(from))
- req, err := d.client.NewRequest("GET", d.rcmd, ip, params)
- if err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var rcmdRes struct {
- Code int `json:"code,omitempty"`
- SeID string `json:"seid,omitempty"`
- Tips string `json:"recommend_tips,omitempty"`
- NumResult int `json:"numResult,omitempty"`
- ShowFront int `json:"show_front,omitempty"`
- Resutl []struct {
- ID int64 `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- ShowName string `json:"show_name,omitempty"`
- Type string `json:"type,omitempty"`
- } `json:"result,omitempty"`
- }
- if err = d.client.Do(c, req, &rcmdRes); err != nil {
- return
- }
- if rcmdRes.Code != ecode.OK.Code() {
- if rcmdRes.Code != model.ForbidCode {
- err = errors.Wrap(ecode.Int(rcmdRes.Code), d.rcmd+"?"+params.Encode())
- }
- return
- }
- if len(rcmdRes.Resutl) == 0 {
- err = ecode.NothingFound
- return
- }
- res = &search.DefaultWords{}
- for _, v := range rcmdRes.Resutl {
- res.Trackid = rcmdRes.SeID
- res.Param = strconv.Itoa(int(v.ID))
- res.Show = v.ShowName
- res.Word = v.Name
- res.ShowFront = rcmdRes.ShowFront
- }
- return
- }
- // RecommendNoResult is no result recommend search data.
- func (d *Dao) RecommendNoResult(c context.Context, platform, mobiApp, device, buvid, keyword string, build, pn, ps int, mid int64) (res *search.NoResultRcndResult, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("device", device)
- params.Set("build", strconv.Itoa(build))
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("search_type", "video")
- params.Set("keyword", keyword)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- req, err := d.client.NewRequest("GET", d.rcmdNoResult, ip, params)
- if err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var (
- resTmp *search.NoResultRcmd
- avids []int64
- avm map[int64]*api.Arc
- cooperation bool
- )
- if err = d.client.Do(c, req, &resTmp); err != nil {
- return
- }
- if resTmp.Code != ecode.OK.Code() {
- if resTmp.Code != model.ForbidCode {
- err = errors.Wrap(ecode.Int(resTmp.Code), d.rcmdNoResult+"?"+params.Encode())
- }
- return
- }
- res = &search.NoResultRcndResult{TrackID: resTmp.Trackid, Title: resTmp.RecommendTips, Pages: resTmp.NumResults}
- for _, v := range resTmp.Result {
- avids = append(avids, v.ID)
- }
- if len(avids) != 0 {
- if avm, err = d.arcDao.Archives2(c, avids); err != nil {
- log.Error("RecommendNoResult %+v", err)
- err = nil
- }
- }
- items := make([]*search.Item, 0, len(resTmp.Result))
- for _, v := range resTmp.Result {
- ri := &search.Item{}
- ri.FromVideo(v, avm[v.ID], cooperation)
- items = append(items, ri)
- }
- res.Items = items
- return
- }
- // Channel for search channel
- func (d *Dao) Channel(c context.Context, mid int64, keyword, mobiApp, platform, buvid, device, order, sType string, build, pn, ps, highlight int) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- plat = model.Plat(mobiApp, device)
- ip = metadata.String(c, metadata.RemoteIP)
- )
- params := url.Values{}
- params.Set("keyword", keyword)
- params.Set("mobi_app", mobiApp)
- params.Set("platform", platform)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("build", strconv.Itoa(build))
- params.Set("main_ver", "v3")
- params.Set("search_type", sType)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("device", device)
- params.Set("order", order)
- params.Set("highlight", strconv.Itoa(highlight))
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- // new request
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Pages int `json:"numPages"`
- List []*search.Channel `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- if res.Code != model.ForbidCode && res.Code != model.NoResultCode {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- }
- return
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- avm := make(map[int64]*api.Arc)
- bangumis := make(map[int32]*seasongrpc.CardInfoProto)
- lm := make(map[int64]*livemdl.RoomInfo)
- si.FromChannel(v, avm, bangumis, lm, nil)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Items: items}
- return
- }
- // RecommendPre search at pre-page
- func (d *Dao) RecommendPre(c context.Context, platform, mobiApp, device, buvid string, build, ps int, mid int64) (res *search.RecommendPreResult, err error) {
- ip := metadata.String(c, metadata.RemoteIP)
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("mobi_app", mobiApp)
- params.Set("clientip", ip)
- params.Set("device", device)
- params.Set("build", strconv.Itoa(build))
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("search_type", "discover_page")
- params.Set("pagesize", strconv.Itoa(ps))
- req, err := d.client.NewRequest("GET", d.pre, ip, params)
- if err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var (
- resTmp *search.RecommendPre
- avids []int64
- avm map[int64]*api.Arc
- seasonIDs []int32
- bangumis map[int32]*seasongrpc.CardInfoProto
- )
- if err = d.client.Do(c, req, &resTmp); err != nil {
- return
- }
- if resTmp.Code != ecode.OK.Code() {
- if resTmp.Code != model.ForbidCode {
- err = errors.Wrap(ecode.Int(resTmp.Code), d.pre+"?"+params.Encode())
- }
- return
- }
- for _, v := range resTmp.Result {
- for _, vv := range v.List {
- if vv.Type == "video" {
- avids = append(avids, vv.ID)
- } else if vv.Type == "pgc" {
- seasonIDs = append(seasonIDs, int32(vv.ID))
- }
- }
- }
- g, ctx := errgroup.WithContext(c)
- if len(avids) != 0 {
- g.Go(func() (err error) {
- if avm, err = d.arcDao.Archives2(ctx, avids); err != nil {
- log.Error("RecommendPre avids(%v) error(%v)", avids, err)
- err = nil
- }
- return
- })
- }
- if len(seasonIDs) > 0 {
- g.Go(func() (err error) {
- if bangumis, err = d.bangumiDao.Cards(c, seasonIDs); err != nil {
- log.Error("RecommendPre seasonIDs(%v) error(%v)", seasonIDs, err)
- err = nil
- }
- return
- })
- }
- if err = g.Wait(); err != nil {
- log.Error("%+v", err)
- return
- }
- res = &search.RecommendPreResult{TrackID: resTmp.Trackid, Total: resTmp.NumResult}
- items := make([]*search.Item, 0, len(resTmp.Result))
- for _, v := range resTmp.Result {
- rs := &search.Item{Title: v.Query}
- for _, vv := range v.List {
- if vv.Type == "video" {
- if a, ok := avm[vv.ID]; ok {
- r := &search.Item{}
- r.FromRcmdPre(vv.ID, a, nil)
- rs.Item = append(rs.Item, r)
- }
- } else if vv.Type == "pgc" {
- if b, ok := bangumis[int32(vv.ID)]; ok {
- r := &search.Item{}
- r.FromRcmdPre(vv.ID, nil, b)
- rs.Item = append(rs.Item, r)
- }
- }
- }
- items = append(items, rs)
- }
- res.Items = items
- return
- }
- // Video search new archive data.
- func (d *Dao) Video(c context.Context, mid int64, keyword, mobiApp, device, platform, buvid string, highlight, build, pn, ps int) (st *search.TypeSearch, err error) {
- var (
- req *http.Request
- ip = metadata.String(c, metadata.RemoteIP)
- plat = model.Plat(mobiApp, device)
- avids []int64
- avm map[int64]*api.Arc
- cooperation bool
- )
- params := url.Values{}
- params.Set("main_ver", "v3")
- params.Set("platform", platform)
- params.Set("build", strconv.Itoa(build))
- params.Set("keyword", keyword)
- params.Set("userid", strconv.FormatInt(mid, 10))
- params.Set("mobi_app", mobiApp)
- params.Set("device", device)
- params.Set("page", strconv.Itoa(pn))
- params.Set("pagesize", strconv.Itoa(ps))
- params.Set("search_type", "video")
- params.Set("order", "totalrank")
- params.Set("highlight", strconv.Itoa(highlight))
- if (model.IsAndroid(plat) && build > d.c.SearchBuildLimit.SpecialerGuideAndroid) || (model.IsIPhone(plat) && build > d.c.SearchBuildLimit.SpecialerGuideIOS) {
- params.Set("is_special_guide", "1")
- }
- if req, err = d.client.NewRequest("GET", d.main, ip, params); err != nil {
- return
- }
- req.Header.Set("Buvid", buvid)
- var res struct {
- Code int `json:"code"`
- SeID string `json:"seid"`
- Total int `json:"numResults"`
- Pages int `json:"numPages"`
- List []*search.Video `json:"result"`
- }
- if err = d.client.Do(c, req, &res); err != nil {
- return
- }
- if res.Code != ecode.OK.Code() {
- err = errors.Wrap(ecode.Int(res.Code), d.main+"?"+params.Encode())
- return
- }
- for _, v := range res.List {
- avids = append(avids, v.ID)
- }
- if len(avids) > 0 {
- if avm, err = d.arcDao.Archives2(c, avids); err != nil {
- log.Error("Upper %+v", err)
- err = nil
- }
- }
- items := make([]*search.Item, 0, len(res.List))
- for _, v := range res.List {
- si := &search.Item{}
- si.FromVideo(v, avm[v.ID], cooperation)
- items = append(items, si)
- }
- st = &search.TypeSearch{TrackID: res.SeID, Pages: res.Pages, Total: res.Total, Items: items}
- return
- }
|