an open source osu! mirror. Outdated, replaced by cheesegull.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

beatmap_finder.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "strconv"
  7. "strings"
  8. "sync/atomic"
  9. "github.com/fatih/color"
  10. "gopkg.in/thehowl/go-osuapi.v1"
  11. )
  12. var (
  13. current int64
  14. stopAt = int64(5000)
  15. beatmapsToFind = make(chan int, 10)
  16. beatmaps = make(chan []osuapi.Beatmap, 50)
  17. )
  18. // NumberFinder finds numbers in sequence, until it is told to stop by Common Sense™.
  19. func NumberFinder() {
  20. for {
  21. if atomic.LoadInt64(&stopAt) < atomic.LoadInt64(&current) {
  22. color.Yellow("5,000 beatmaps not found in a row. Giving up.")
  23. break
  24. }
  25. atomic.AddInt64(&current, 1)
  26. beatmapsToFind <- int(atomic.LoadInt64(&current))
  27. }
  28. close(beatmapsToFind)
  29. wg.Done()
  30. }
  31. // NumberAdder adds numbers to beatmapsToFind from sets.
  32. func NumberAdder() {
  33. for _, i := range sets {
  34. beatmapsToFind <- i
  35. }
  36. close(beatmapsToFind)
  37. wg.Done()
  38. }
  39. var finished int32
  40. // BeatmapFinder looks for new beatmaps.
  41. func BeatmapFinder() {
  42. for i := range beatmapsToFind {
  43. if isIgnored(strconv.Itoa(i)) {
  44. continue
  45. }
  46. beatmapsF, err := c.GetBeatmaps(osuapi.GetBeatmapsOpts{
  47. BeatmapSetID: i,
  48. })
  49. if err != nil {
  50. color.Red("%v", err)
  51. continue
  52. }
  53. if len(beatmapsF) == 0 {
  54. continue
  55. }
  56. if atomic.LoadInt64(&stopAt) < int64(i+5000) {
  57. atomic.StoreInt64(&stopAt, int64(i+5000))
  58. }
  59. data, err := ioutil.ReadFile(fmt.Sprintf("data/s/%d.json", beatmapsF[0].BeatmapSetID))
  60. switch {
  61. case err == nil:
  62. var b DataBeatmapSet
  63. json.Unmarshal(data, &b)
  64. if b.LastUpdate.Equal(beatmapsF[0].LastUpdate.GetTime()) {
  65. if fixBeatmaps {
  66. UpdateBeatmapSet(beatmapsF, b.HasVideo)
  67. }
  68. continue
  69. }
  70. case strings.Index(err.Error(), "no such file or directory") != -1:
  71. // Nothing. Just keep on going, export the file and download beatmap.
  72. case err != nil:
  73. color.Red("%v", err)
  74. continue
  75. }
  76. beatmaps <- beatmapsF
  77. }
  78. if atomic.AddInt32(&finished, 1) == 50 {
  79. close(beatmaps)
  80. }
  81. }