claim_search.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. if r[i]:
  46. c[i] = r[i]
  47. elif c[i]:
  48. del c[i]
  49. channel_load = True
  50. if len(channel_ids) == 1:
  51. channel_load = False
  52. out = fetch.lbrynet("claim_search", c)
  53. same = [win, arg, channel_ids, page+1, r]
  54. if flowbox:
  55. def add_to_flowbox(flowbox, out):
  56. for i in out["items"]:
  57. flowbox.add(ui.search_item(win, i, channel_load))
  58. if len(out["items"]) > 1:
  59. lastthing(win, same, flowbox)
  60. flowbox.show_all()
  61. GLib.idle_add(add_to_flowbox, flowbox, out)
  62. else:
  63. return [win, out, channel_load, same]
  64. def render(out):
  65. win, out, channel_load, same = out
  66. scrolled = Gtk.ScrolledWindow()
  67. scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
  68. flowbox = Gtk.FlowBox()
  69. flowbox.set_valign(Gtk.Align.START)
  70. flowbox.set_max_children_per_line(30)
  71. flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
  72. scrolled.add(flowbox)
  73. box = Gtk.VBox()
  74. for i in out["items"]:
  75. flowbox.add(ui.search_item(win, i, channel_load))
  76. if len(out["items"]) > 1:
  77. lastthing(win, same, flowbox)
  78. return scrolled
  79. def lastthing(win, same, flowbox):
  80. # THis is a hack. I use a spinner to get a draw event
  81. # when the user scrolls far enough, it will execute it
  82. # to load more stuff
  83. spinner_more = ui.icon(win, "loading", "gif")
  84. flowbox.add(spinner_more)
  85. def draw_event(w, e):
  86. print("EVENT MOTHERFUCKER")
  87. w.destroy()
  88. same.append(flowbox)
  89. load_thread = threading.Thread(target=find, args=[*same])
  90. load_thread.setDaemon(True)
  91. load_thread.start()
  92. spinner_more.connect("draw", draw_event)