Last active
December 28, 2023 08:56
-
-
Save syhily/0a7ca1f1da67821a479528486544fd03 to your computer and use it in GitHub Desktop.
Revisions
-
syhily revised this gist
Oct 11, 2022 . 1 changed file with 173 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,173 @@ package main import ( "fmt" "net/http" "net/url" "regexp" "strconv" "strings" "time" "github.com/go-resty/resty/v2" _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" ) var resultSet = make(map[string][]int64) var matcher = regexp.MustCompile("\\d+") var hashes = []string{"02628a5f5eadcc322c10a7e232066d4707cb81ba", "0267b9c53df202d5fb6fa59bac434e98db66db75", "031b3a61dde30a8d8160e07a7ab82ce1b886e855", "096c83b5aec01e1134b0f3191acecb610152974c", "0ec68fe770446d589b4de93c92db63915e91a59d", "1314086d62663ce207a7ac640af0dc6b3bcdef9c", "1400d50d33d1995f4a2d6b6a935b5fef1ea014fb", "1c434f3525205c86d46f25fbecd9cc8a2d233bb8", "266464102ac8a0da358b134028d11bb09a8f8cb5", "28b90ac630aa6899ebdf7c31f99638cd86f91bbb", "293813825cc9f4faf7c22a4f4d5c3c7fec5ff731", "2e16a6626de4bc0e947f7962c1da7f74e527b713", "2eb0cf03b5985dda2f79c5c6314570212f3e6efb", "31ce13dd5c62f392b9fb64ac091ceb5989896e58", "34d5692f2f0c19936bfbfa0d8d990b943e62907a", "3851fc8664bfa4fd1c368cc961a3f79fc7be68c0", "3f7ebcfd846048dc5892d6b1e39b4fb77641e5d9", "43ad3bbeacb5ac857c84058661ac068b5ebb28e4", "493ea5470835a756a00f39d34573a6dc1049e04a", "5725da392c88e97f81d91b8e0d96389092969b55", "58edd6983ec49f3bb9f05f0faff1093e10ac65cf", "6392f1d06973ed88e273b9afbabf1f3d26ec6486", "64618f9ed5c4ef513a9df1bdd7b968e65a791627", "66542c72b152159d4c385360dddeae65e5431ca7", "6a5e0872b423b51d87a9d005b0f2572dac8ba812", "7265dec0e104ffb4ef1d76695ac0c2b7e028a867", "7604f23b2132588afb1c908df41edd2ce4ee3730", "767dfc63d9ffa6bb68cc5f0376d00d787b9c94db", "7844374063b845128c030078947fb14b6722ab54", "7eadd98d867f83e7955b9911fc291a45d3d94e4b", "7ff294d8bf7098027fe7f5d0b2c9b7a4ff8b5480", "85251aa6f9f4bfa81f1ea8fdb08d9b4157be1bc8", "9ecfce194c021529a9d164a4dfd040d0e377e135", "a2af77b3d867439afec0e5032e06efe83d2d5cc7", "a2dccd09b775a31a36153e569de168c0682c096d", "a5cdccc82a4b2ad8e0be50146b15dc5dacdbed37", "abe2dcfc4d6da4b7ee8f0c7b60429d3657531d35", "b19cf584b49bfae1edce346de0e97174c5f13015", "b1a229acbb06cf18cba99b7501d0610ce9b4a111", "bb9faa7aed664c13b181e7227e6385cee161a42f", "c087780290781ec3a8502509fa04db3e80a93faa", "c7b43de887da2c0e6108cb59461272b78b0d1ca4", "d9c4d195f7d7581549a728113ffb5f7a9cd1d7a5", "dd6fe987a32848184e9d202aeec82698bd3702c1", "de8881fc331531710cd3ebe237f1d04c8afe573d", "e7e36c4dbdfe7f2007a76b710bc169fbebaec3cc", "ecee4d534ddd8af21da27742ff8d4eaa85684ba6", "f10a36474ce221b9f4d7b40e3c357b6507ea9fe7", "f734b706c3c7dbd986daa8a40d3c1604558e5bfe", "f8a21cff7bfd4d4ef8c396f58c4fdadfa402c94e", "f9c1f0c6448ff71318217337797e7acca0ffdd85"} type Column struct { Name string `db:"name"` ID int64 `db:"id"` } func main() { db, err := sqlx.Open("mysql", "CHANGE THIS TO YOUR LOCAL PILIMI MYSQL") if err != nil { panic(err) } db.SetConnMaxLifetime(time.Minute * 3) db.SetMaxOpenConns(10) db.SetMaxIdleConns(10) col := &Column{} rows, err := db.Queryx("SELECT pilimi_torrent AS name, zlibrary_id as id FROM `books` WHERE in_libgen = 0 AND pilimi_torrent IS NOT NULL AND language = 'chinese'") if err != nil { panic(err) } for rows.Next() { if err := rows.StructScan(col); err != nil { panic(err) } ids := resultSet[col.Name] ids = append(ids, col.ID) resultSet[col.Name] = ids } rows, err = db.Queryx("SELECT zlibrary_id as id FROM `books` WHERE in_libgen = 0 AND pilimi_torrent IS NULL AND language = 'chinese'") if err != nil { panic(err) } for rows.Next() { if err := rows.StructScan(col); err != nil { panic(err) } find: for file := range resultSet { ranges := matcher.FindAllString(file, -1) if len(ranges) > 2 { continue } low, _ := strconv.ParseInt(ranges[0], 10, 64) upper, _ := strconv.ParseInt(ranges[1], 10, 64) id := col.ID if id >= low && id <= upper { ids := resultSet[file] ids = append(ids, id) resultSet[file] = ids break find } } } client := resty.New() client.SetBaseURL("https://XXXXX") cookie, err := sendLogin(client) println(cookie.String()) if err != nil { panic(err) } for _, hash := range hashes { files, err := getFiles(client.SetCookie(cookie), hash) if err != nil { panic(err) } indexs := make([]int64, 0) for _, file := range files { after := strings.Split(file.Name, "/") key := after[0] id, _ := strconv.ParseInt(after[1], 10, 64) fmt.Println(key+".torrent", file.Index, id) int64s := resultSet[key+".torrent"] if !Contains(int64s, id) { indexs = append(indexs, file.Index) } } if len(indexs) == 0 { fmt.Println("没有文件") } err = setFiles(client.SetCookie(cookie), hash, indexs) if err != nil { panic(err) } } } func setFiles(client *resty.Client, hash string, indexs []int64) error { params := url.Values{} params.Set("hash", hash) trim := strings.Trim(strings.Replace(fmt.Sprint(indexs), " ", "|", -1), "[]") println(trim) params.Set("id", trim) params.Set("priority", "0") resp, err2 := client.R().SetFormDataFromValues(params). Post("/api/v2/torrents/filePrio") if err2 != nil { return err2 } if resp.IsError() { fmt.Println(resp.Request.Header) fmt.Println(resp.String()) fmt.Println(resp.StatusCode()) return fmt.Errorf("更新状态失败") } return nil } func sendLogin(client *resty.Client) (*http.Cookie, error) { params := url.Values{} params.Set("username", "XXXXX") params.Set("password", "XXXXX") resp, err := client.R().SetFormDataFromValues(params).SetHeader("Referer", "https://XXXXX").Post("/api/v2/auth/login") return resp.Cookies()[0], err } func getFiles(client *resty.Client, hash string) (Files, error) { var files Files _, err2 := client.R().SetQueryParam("hash", hash).SetResult(&files).Get("/api/v2/torrents/files") return files, err2 } type Files []struct { Availability float64 `json:"availability"` Index int64 `json:"index"` IsSeed bool `json:"is_seed,omitempty"` Name string `json:"name"` PieceRange []int `json:"piece_range"` Priority int `json:"priority"` Progress float64 `json:"progress"` Size int `json:"size"` } func Contains[T comparable](s []T, e T) bool { for _, v := range s { if v == e { return true } } return false } -
syhily revised this gist
Oct 9, 2022 . 1 changed file with 0 additions and 4332 deletions.There are no files selected for viewing
-
syhily revised this gist
Oct 9, 2022 . 1 changed file with 4332 additions and 0 deletions.There are no files selected for viewing
-
syhily revised this gist
Oct 9, 2022 . 1 changed file with 95 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,95 @@ package main import ( "fmt" _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" "os" "regexp" "strconv" "strings" "time" ) var resultSet = make(map[string][]int64) var matcher = regexp.MustCompile("\\d+") type Column struct { Name string `db:"name"` ID int64 `db:"id"` } func main() { db, err := sqlx.Open("mysql", "CHANGE THIS TO YOUR LOCAL PILIMI MYSQL") if err != nil { panic(err) } // See "Important settings" section. db.SetConnMaxLifetime(time.Minute * 3) db.SetMaxOpenConns(10) db.SetMaxIdleConns(10) col := &Column{} rows, err := db.Queryx("SELECT pilimi_torrent AS name, zlibrary_id as id FROM `books` WHERE in_libgen = 0 AND pilimi_torrent IS NOT NULL AND language = 'chinese'") if err != nil { panic(err) } for rows.Next() { if err := rows.StructScan(col); err != nil { panic(err) } ids := resultSet[col.Name] ids = append(ids, col.ID) resultSet[col.Name] = ids } rows, err = db.Queryx("SELECT zlibrary_id as id FROM `books` WHERE in_libgen = 0 AND pilimi_torrent IS NULL AND language = 'chinese'") if err != nil { panic(err) } for rows.Next() { if err := rows.StructScan(col); err != nil { panic(err) } find: for file := range resultSet { ranges := matcher.FindAllString(file, -1) if len(ranges) > 2 { continue } low, _ := strconv.ParseInt(ranges[0], 10, 64) upper, _ := strconv.ParseInt(ranges[1], 10, 64) id := col.ID if id >= low && id <= upper { ids := resultSet[file] ids = append(ids, id) resultSet[file] = ids break find } } } _ = os.Mkdir("scripts", os.ModePerm) for tor, ids := range resultSet { dir := tor[0:strings.LastIndex(tor, ".")] file, err := os.Create("scripts/" + dir + ".sh") if err != nil { panic(err) } _, _ = file.WriteString("#!/bin/bash\n\n") for _, id := range ids { _, _ = file.WriteString(fmt.Sprintf("mv /volume2/video/%s/%d /volume2/Download/EPUBs/%d.epub\n", dir, id, id)) } _, _ = file.WriteString(fmt.Sprintf("\nrm -rf /volume2/video/%s\n", dir)) _ = file.Close() } } -
syhily revised this gist
Oct 9, 2022 . No changes.There are no files selected for viewing
-
syhily revised this gist
Oct 8, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ pilimi-zlib-420000-2379999.torrent pilimi-zlib-2380000-2829999.torrent pilimi-zlib-2830000-5239999.torrent pilimi-zlib-5240000-5329999.torrent pilimi-zlib-5330000-5359999.torrent pilimi-zlib-5360000-5379999.torrent pilimi-zlib-5380000-5449999.torrent @@ -68,4 +67,5 @@ pilimi-zlib-13850000-13959999.torrent pilimi-zlib-13960000-14029999.torrent pilimi-zlib-14030000-14379999.torrent pilimi-zlib-14380000-14679999.torrent pilimi-zlib2-0-14679999-extra.torrent pilimi-zlib2-14680000-14999999.torrent -
syhily created this gist
Oct 8, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ pilimi-zlib-420000-2379999.torrent pilimi-zlib-2380000-2829999.torrent pilimi-zlib-2830000-5239999.torrent pilimi-zlib-5240000-5329999.torrent pilimi-zlib2-0-14679999-extra.torrent pilimi-zlib-5330000-5359999.torrent pilimi-zlib-5360000-5379999.torrent pilimi-zlib-5380000-5449999.torrent pilimi-zlib-5450000-5479999.torrent pilimi-zlib-5480000-5499999.torrent pilimi-zlib-5500000-5519999.torrent pilimi-zlib-5520000-5549999.torrent pilimi-zlib-5550000-5579999.torrent pilimi-zlib-5580000-5609999.torrent pilimi-zlib-5610000-5639999.torrent pilimi-zlib-5640000-5659999.torrent pilimi-zlib-5660000-5709999.torrent pilimi-zlib-5710000-5729999.torrent pilimi-zlib-5730000-5749999.torrent pilimi-zlib-5750000-5769999.torrent pilimi-zlib-5770000-5789999.torrent pilimi-zlib-5790000-5809999.torrent pilimi-zlib-5810000-6039999.torrent pilimi-zlib-6040000-6069999.torrent pilimi-zlib-6070000-6129999.torrent pilimi-zlib-6130000-6159999.torrent pilimi-zlib-6160000-7229999.torrent pilimi-zlib-7230000-9459999.torrent pilimi-zlib-9460000-10999999.torrent pilimi-zlib-11000000-11039999.torrent pilimi-zlib-11040000-11079999.torrent pilimi-zlib-11080000-11129999.torrent pilimi-zlib-11130000-11169999.torrent pilimi-zlib-11170000-11209999.torrent pilimi-zlib-11210000-11269999.torrent pilimi-zlib-11270000-11299999.torrent pilimi-zlib-11300000-11329999.torrent pilimi-zlib-11330000-11359999.torrent pilimi-zlib-11360000-11399999.torrent pilimi-zlib-11400000-11449999.torrent pilimi-zlib-11450000-11499999.torrent pilimi-zlib-11500000-11549999.torrent pilimi-zlib-11550000-11579999.torrent pilimi-zlib-11580000-11599999.torrent pilimi-zlib-11600000-11659999.torrent pilimi-zlib-11660000-11699999.torrent pilimi-zlib-11700000-11729999.torrent pilimi-zlib-11730000-11759999.torrent pilimi-zlib-11760000-11799999.torrent pilimi-zlib-11800000-11829999.torrent pilimi-zlib-11830000-11859999.torrent pilimi-zlib-11860000-11899999.torrent pilimi-zlib-11900000-11929999.torrent pilimi-zlib-11930000-11949999.torrent pilimi-zlib-11950000-11969999.torrent pilimi-zlib-11970000-11999999.torrent pilimi-zlib-12000000-12039999.torrent pilimi-zlib-12040000-12099999.torrent pilimi-zlib-12100000-12159999.torrent pilimi-zlib-12160000-12229999.torrent pilimi-zlib-12230000-12349999.torrent pilimi-zlib-12350000-12619999.torrent pilimi-zlib-12620000-12769999.torrent pilimi-zlib-12810000-13229999.torrent pilimi-zlib-13230000-13529999.torrent pilimi-zlib-13530000-13849999.torrent pilimi-zlib-13850000-13959999.torrent pilimi-zlib-13960000-14029999.torrent pilimi-zlib-14030000-14379999.torrent pilimi-zlib-14380000-14679999.torrent pilimi-zlib2-14680000-14999999.torrent