claim_search.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #####################################################################
  2. # #
  3. # THIS IS A SOURCE CODE FILE FROM A PROGRAM TO INTERACT WITH THE #
  4. # LBRY PROTOCOL ( lbry.com ). IT WILL USE THE LBRY SDK ( lbrynet ) #
  5. # FROM THEIR REPOSITORY ( https://github.com/lbryio/lbry-sdk ) #
  6. # WHICH I GONNA PRESENT TO YOU AS A BINARY. SINCE I DID NOT DEVELOP #
  7. # IT AND I'M LAZY TO INTEGRATE IN A MORE SMART WAY. THE SOURCE CODE #
  8. # OF THE SDK IS AVAILABLE IN THE REPOSITORY MENTIONED ABOVE. #
  9. # #
  10. # ALL THE CODE IN THIS REPOSITORY INCLUDING THIS FILE IS #
  11. # (C) J.Y.Amihud and Other Contributors 2021. EXCEPT THE LBRY SDK. #
  12. # YOU CAN USE THIS FILE AND ANY OTHER FILE IN THIS REPOSITORY UNDER #
  13. # THE TERMS OF GNU GENERAL PUBLIC LICENSE VERSION 3 OR ANY LATER #
  14. # VERSION. TO FIND THE FULL TEXT OF THE LICENSE GO TO THE GNU.ORG #
  15. # WEBSITE AT ( https://www.gnu.org/licenses/gpl-3.0.html ). #
  16. # #
  17. # THE LBRY SDK IS UNFORTUNATELY UNDER THE MIT LICENSE. IF YOU ARE #
  18. # NOT INTENDING TO USE MY CODE AND JUST THE SDK. YOU CAN FIND IT ON #
  19. # THEIR OFFICIAL REPOSITORY ABOVE. THEIR LICENSE CHOICE DOES NOT #
  20. # SPREAD ONTO THIS PROJECT. DON'T GET A FALSE ASSUMPTION THAT SINCE #
  21. # THEY USE A PUSH-OVER LICENSE, I GONNA DO THE SAME. I'M NOT. #
  22. # #
  23. # THE LICENSE CHOSEN FOR THIS PROJECT WILL PROTECT THE 4 ESSENTIAL #
  24. # FREEDOMS OF THE USER FURTHER, BY NOT ALLOWING ANY WHO TO CHANGE #
  25. # THE LICENSE AT WILL. SO NO PROPRIETARY SOFTWARE DEVELOPER COULD #
  26. # TAKE THIS CODE AND MAKE THEIR USER-SUBJUGATING SOFTWARE FROM IT. #
  27. # #
  28. #####################################################################
  29. # This is the seach mechanism
  30. import threading
  31. from flbry import ui
  32. from flbry import fetch
  33. from gi.repository import Gtk
  34. from gi.repository import GLib
  35. def find(win, arg="", channel_ids=[], page=1, r={}, flowbox=False):
  36. #if arg:
  37. # c["text"] = arg
  38. c = {}
  39. c["text"] = arg
  40. c["channel_ids"] = channel_ids
  41. c["page"] = page
  42. c["order_by"] = "release_time" #{"order_by":"release_time"}
  43. c["remove_duplicates"] = True
  44. for i in r:
  45. c[i] = r[i]
  46. channel_load = True
  47. if len(channel_ids) == 1:
  48. channel_load = False
  49. out = fetch.lbrynet("claim_search", c)
  50. same = [win, arg, channel_ids, page+1, r]
  51. if flowbox:
  52. def add_to_flowbox(flowbox, out):
  53. for i in out["items"]:
  54. flowbox.add(ui.search_item(win, i, channel_load))
  55. if len(out["items"]) > 1:
  56. lastthing(win, same, flowbox)
  57. flowbox.show_all()
  58. GLib.idle_add(add_to_flowbox, flowbox, out)
  59. else:
  60. return [win, out, channel_load, same]
  61. def render(out):
  62. win, out, channel_load, same = out
  63. scrolled = Gtk.ScrolledWindow()
  64. scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
  65. flowbox = Gtk.FlowBox()
  66. flowbox.set_valign(Gtk.Align.START)
  67. flowbox.set_max_children_per_line(30)
  68. flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
  69. scrolled.add(flowbox)
  70. box = Gtk.VBox()
  71. for i in out["items"]:
  72. flowbox.add(ui.search_item(win, i, channel_load))
  73. if len(out["items"]) > 1:
  74. lastthing(win, same, flowbox)
  75. return scrolled
  76. def lastthing(win, same, flowbox):
  77. # THis is a hack. I use a spinner to get a draw event
  78. # when the user scrolls far enough, it will execute it
  79. # to load more stuff
  80. spinner_more = ui.icon(win, "loading", "gif")
  81. flowbox.add(spinner_more)
  82. def draw_event(w, e):
  83. print("EVENT MOTHERFUCKER")
  84. w.destroy()
  85. same.append(flowbox)
  86. load_thread = threading.Thread(target=find, args=[*same])
  87. load_thread.setDaemon(True)
  88. load_thread.start()
  89. spinner_more.connect("draw", draw_event)