run.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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. # Preparing the executable of lbrynet to be running. If we don't that
  30. # there will be a nasty error of permission being denied.
  31. import os
  32. os.system("chmod u+x flbry/lbrynet")
  33. # I'm not trying to make it pretty. I'm trying to make it snappy.
  34. # It's FastLBRY not SlowLBRY.
  35. import gi
  36. import threading
  37. gi.require_version('Gtk', '3.0')
  38. from gi.repository import Gtk
  39. from gi.repository import Gdk
  40. from gi.repository import GLib
  41. # It's gonna take a couple of things to make the button run
  42. from flbry import connect
  43. from flbry import parse
  44. from flbry import settings
  45. from flbry import url
  46. from flbry import ui
  47. from flbry import claim_search
  48. from flbry import fetch
  49. from flbry import publish
  50. from flbry import downloads
  51. from flbry import analytics
  52. from flbry import livestreams
  53. from flbry import suggest
  54. from flbry import odysee
  55. settings.make_sure_file_exists()
  56. ##########################################################################
  57. # #
  58. # THE MAIN WINDOW OF FASTLBRY GTK #
  59. # #
  60. ##########################################################################
  61. win = Gtk.Window() # Make a GTK window object
  62. win.connect("destroy", Gtk.main_quit) # If you close the window, program quits
  63. win.set_title("FastLBRY GTK") # Title
  64. win.set_default_icon_from_file("icon.png") # Icon
  65. win.set_size_request(800, 900) # Minimum size
  66. ##########################################################################
  67. # #
  68. # GLOBAL VARIABLES HACK ( adding things to 'win' ) #
  69. # #
  70. ##########################################################################
  71. # This hack is very simple. Our main Gtk.Window() is a class to which we
  72. # can add variables later on. Like the example you see below.
  73. # This way, giving some function only 'win' and nothing else, will give
  74. # that other function the entire list of global variable ( added this way ).
  75. win.settings = settings.load() # Settings
  76. win.SDK_running = connect.check() # Is the SDK running ( from 0 to 1 to draw progress bar)
  77. win.resolved = {} # Last resolved data
  78. win.commenting = {} # Data for while chatting in comments
  79. win.subs = [] # What you are subscribed to
  80. win.tabs = [] # List of Gtk.Notebook tabs
  81. win.resolve_tab = 0 # What tab to resolve the page
  82. win.notebook = Gtk.Notebook() # Tabs object
  83. win.download_buttons = {} # Keep alive handlers for Download buttons
  84. win.downloads = {} # Data for the Downloads window
  85. ##########################################################################
  86. # #
  87. # TOP PANNEL #
  88. # #
  89. ##########################################################################
  90. # Gtk.HeaderBar() is like a box but it draws itself in the headerbar insead
  91. # of in the window itself.
  92. pannel = Gtk.HeaderBar()
  93. pannel.set_show_close_button(True)
  94. win.set_titlebar(pannel) # Dumbasses wrote GTK
  95. # Untill the user connected to the SDK, search and other functions should
  96. # not work. So we split the pannel into two parts. The other one is a
  97. # normal box.
  98. restofpannel = Gtk.HBox() # H for Horrizontal
  99. pannel.pack_end(restofpannel)
  100. ############## CONNECT BUTTON ################
  101. # Connect button will also be a disconnect button
  102. # Icons for both
  103. icon_connect = ui.icon(win, "network-wired")
  104. icon_disconnect = ui.icon(win, "network-wired-disconnected")
  105. # Boxes for both
  106. connect_box = Gtk.HBox()
  107. disconnect_box = Gtk.HBox()
  108. # Connect box
  109. connect_box.pack_start(icon_connect, False, False, False)
  110. connect_box.set_tooltip_text("Connect to LBRY Network")
  111. connect_box.pack_start(Gtk.Label("Connect "), False, False, False)
  112. # Disconnect box
  113. disconnect_box.pack_start(icon_disconnect, False, False, False)
  114. disconnect_box.set_tooltip_text("Disconnect from LBRY Network")
  115. disconnect_box.pack_start(Gtk.Label("Disconnect "), False, False, False)
  116. # By whether SDK was running while the software was launched
  117. # we present the correct button to the user and set the rest-of-pannel
  118. # accordingly.
  119. if win.SDK_running:
  120. title = disconnect_box
  121. restofpannel.set_sensitive(True)
  122. else:
  123. title = connect_box
  124. restofpannel.set_sensitive(False)
  125. connect_disconncet_button = Gtk.Button()
  126. connect_disconncet_button.add(title)
  127. connect_disconncet_button.set_relief(Gtk.ReliefStyle.NONE)
  128. pannel.pack_start(connect_disconncet_button)#, False, False, False)
  129. ############### CONNECT / DISCONNECT BUTTONS FUNCTION ################
  130. # The button should do something.
  131. def connect_disconnect_function(w):
  132. w.set_sensitive(False)
  133. dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
  134. for i in dynamic_box.get_children():
  135. i.destroy()
  136. progress_connect = Gtk.ProgressBar(show_text=True)
  137. dynamic_box.pack_start(progress_connect, True, True, 30)
  138. win.show_all()
  139. def do_sdk(w, pb):
  140. wasrunning = win.SDK_running
  141. if win.SDK_running == 1:
  142. connect.stop(win)
  143. else:
  144. connect.start(win)
  145. def update_pb(pb):
  146. pb.set_fraction(win.SDK_running)
  147. pb.set_text("Connecting: "+str(int(round(win.SDK_running*100)))+"%")
  148. def update_buttons(w):
  149. for i in dynamic_box.get_children():
  150. i.destroy()
  151. w.get_child().destroy()
  152. if win.SDK_running == 1:
  153. w.add(disconnect_box)
  154. restofpannel.set_sensitive(True)
  155. else:
  156. w.add(connect_box)
  157. restofpannel.set_sensitive(False)
  158. w.show_all()
  159. w.set_sensitive(True)
  160. if win.SDK_running == 1:
  161. load_following()
  162. load_channel(win)
  163. check_lock_button()
  164. ui.notify(win, "Connected to LBRY")
  165. if wasrunning == 0:
  166. while True:
  167. win.SDK_running = connect.check()
  168. if win.SDK_running == 1:
  169. break
  170. GLib.idle_add(update_pb, pb)
  171. GLib.idle_add(update_buttons, w)
  172. load_thread = threading.Thread(target=do_sdk, args=(w, progress_connect))
  173. load_thread.setDaemon(True)
  174. load_thread.start()
  175. connect_disconncet_button.connect("clicked", connect_disconnect_function)
  176. ##########################################################################
  177. # #
  178. # LOCK BUTTON #
  179. # #
  180. ##########################################################################
  181. win.lock_button = Gtk.ToggleButton()
  182. def check_lock_button():
  183. try:
  184. wallet_status = fetch.lbrynet("wallet_status")
  185. except:
  186. wallet_status = {}
  187. if wallet_status.get("is_locked"):
  188. win.lock_button.set_active(True)
  189. if not win.settings["lock_password"]:
  190. win.lock_button.set_sensitive(False)
  191. else:
  192. win.lock_button.set_sensitive(True)
  193. check_lock_button()
  194. win.lock_button.set_tooltip_text("Lock / Unlock LBRY wallet. \n\n While the wallet is locked, no transaction could be signed. So nobody could use the running SDK to harm you.\n\nTo set the password look into settings.")
  195. win.lock_button.set_relief(Gtk.ReliefStyle.NONE)
  196. win.lock_button.add(ui.icon(win, "system-lock-screen-symbolic"))
  197. restofpannel.pack_start(win.lock_button, False, False, False)
  198. def lock_unlock(w):
  199. passw = win.settings["lock_password"]
  200. wallets = fetch.lbrynet("wallet_list")
  201. ID = wallets["items"][0]["id"]
  202. if w.get_active():
  203. # If we are locking
  204. print(fetch.lbrynet("wallet_encrypt", {"new_password":passw}))
  205. print(fetch.lbrynet("wallet_lock", {"wallet_id":ID}))
  206. else:
  207. # If decrypt
  208. print(fetch.lbrynet("wallet_unlock", {"password":passw, "wallet_id":ID}))
  209. print(fetch.lbrynet("wallet_decrypt", {"wallet_id":ID}))
  210. print("I AM FUCKING PRESSED")
  211. win.lock_button.connect("clicked", lock_unlock)
  212. ##########################################################################
  213. # #
  214. # PUBLISH BUTTON #
  215. # #
  216. ##########################################################################
  217. restofpannel.pack_start(Gtk.VSeparator(), True, True, 20)
  218. publ = Gtk.Button()
  219. publ.set_tooltip_text("Publish to LBRY")
  220. publ.set_relief(Gtk.ReliefStyle.NONE)
  221. publ.add(ui.icon(win, "list-add"))
  222. restofpannel.pack_start(publ, False, False, False)
  223. def do_publish(w):
  224. publish.window(win)
  225. publ.connect("clicked", do_publish)
  226. restofpannel.pack_start(Gtk.VSeparator(), True, True, 20)
  227. ##########################################################################
  228. # #
  229. # SEARCH / URL BAR #
  230. # #
  231. ##########################################################################
  232. # Note that I add this directly into the 'win' to make it a global variable.
  233. # This let's me to start any url from anywhere in the software.
  234. win.url = Gtk.Entry() # Gtk.SearchEntry() also looks good, but nah
  235. win.url.set_size_request(400,40)
  236. restofpannel.pack_start(win.url, True, True, False)
  237. ####### SEARCH FUNCTION #######
  238. def search(w):
  239. if win.resolve_tab == "current":
  240. win.resolve_tab = win.notebook.get_current_page()
  241. try:
  242. dynamic_box = win.tabs[win.resolve_tab]["box"]
  243. except:
  244. new_tab()
  245. dynamic_box = win.tabs[win.resolve_tab]["box"]
  246. # DRAG AND DROP FOR PUBLISH
  247. if win.url.get_text().startswith("file://") or os.path.exists(win.url.get_text()):
  248. # TODO: Some filenames include weird characters like %20 for spacebar and
  249. # stuff like that. We need to filter that out.
  250. filepath = win.url.get_text().replace("file://", "")
  251. publish.window(win, {"file_path":filepath})
  252. win.url.set_text("")
  253. return
  254. for i in dynamic_box.get_children():
  255. i.destroy()
  256. ## IF WE ARE NOT FORCING IT TO SEACH, IT WILL TRY TO RESOLVE THE LBRY URL FIRST ##
  257. if not force_search.get_active() or win.url.get_text().startswith("lbry://"):
  258. win.url.set_text(parse.bar(win.url.get_text()))
  259. ltext = win.url.get_text()
  260. ltext = ltext[ltext.rfind("/")+1:]
  261. win.tabs[win.resolve_tab]["label"].set_text(ltext[:10]+"...")
  262. win.tabs[win.resolve_tab]["label"].set_tooltip_text(win.url.get_text())
  263. resolve = ui.load(win, url.resolve, url.render_resolve, w, win, win.url.get_text())
  264. dynamic_box.pack_start(resolve, True, True, True)
  265. win.show_all()
  266. else:
  267. resolve = ui.load(win, claim_search.find, claim_search.render, win, win.url.get_text(), [], 1, {"order_by":""})
  268. dynamic_box.pack_start(resolve, True, True, True)
  269. win.show_all()
  270. ltext = win.url.get_text()
  271. win.tabs[win.resolve_tab]["label"].set_text(ltext[:10]+"...")
  272. win.tabs[win.resolve_tab]["label"].set_tooltip_text(win.url.get_text())
  273. dynamic_box.show_all()
  274. win.notebook.set_current_page(win.resolve_tab)
  275. win.resolve_tab = "current"
  276. # Button to activate seach for those who don't know that you can press Enter
  277. search_button = Gtk.Button()
  278. search_icon = ui.icon(win, "system-search")
  279. search_button.add(search_icon)
  280. search_button.set_relief(Gtk.ReliefStyle.NONE)
  281. search_button.connect("clicked", search)
  282. win.url.connect("activate", search)
  283. restofpannel.pack_start(search_button, False, False, False)
  284. ##########################################################################
  285. # #
  286. # HAMBURGER MENU #
  287. # #
  288. ##########################################################################
  289. # Popover is the new GTK menu thingy that looks like a comic book dialog
  290. # box. Which is what we want here. Because we want it to look nice I suppose.
  291. def on_hamburger(w):
  292. ################# NOTIFICATIONS #####################
  293. notifications = odysee.get_odysee_notifications(win)
  294. for i in win.notifications_box.get_children():
  295. i.destroy()
  296. if notifications:
  297. scrl = Gtk.ScrolledWindow()
  298. scrl.set_size_request(200,200)
  299. win.notifications_box.pack_start(scrl, 1,1,0)
  300. notbox = Gtk.VBox()
  301. scrl.add(notbox)
  302. for i in notifications:
  303. i = i.get("notification_parameters", {})
  304. author = i.get("dynamic", {}).get("reply_author")
  305. publication = i.get("device", {}).get("target")
  306. comment = i.get("device", {}).get("text")
  307. # Channel button
  308. def resolve_channel(win, url):
  309. out = fetch.lbrynet("resolve", {"urls":url})
  310. out = out[url]
  311. return [win, out]
  312. def render_channel(out):
  313. win, out = out
  314. return ui.go_to_channel(win, out)
  315. notbox.pack_start(Gtk.HSeparator(), 1,1,5)
  316. channel_button = ui.load(win, resolve_channel, render_channel, win, author)
  317. notbox.pack_start(channel_button, 1,1,5)
  318. comment_label = Gtk.Label(comment)
  319. comment_label.set_selectable(True)
  320. comment_label.set_line_wrap_mode( Gtk.WrapMode.WORD )
  321. comment_label.set_line_wrap(True)
  322. comment_label.set_max_width_chars(20)
  323. def resolve_publication(w, publication):
  324. win.resolve_tab = "new_tab"
  325. win.url.set_text(publication)
  326. win.url.activate()
  327. comment_button = Gtk.Button()
  328. comment_button.add(comment_label)
  329. comment_button.connect("clicked", resolve_publication, publication)
  330. comment_button.set_relief(Gtk.ReliefStyle.NONE)
  331. notbox.pack_start(comment_button, 1,1,5)
  332. win.notifications_box.show_all()
  333. hamburger = Gtk.Popover()
  334. hambutton = Gtk.MenuButton(popover=hamburger)
  335. hambutton.connect("clicked", on_hamburger)
  336. hambutton_icon = ui.icon(win, "system-users")
  337. hambutton.add(hambutton_icon)
  338. hambutton.set_relief(Gtk.ReliefStyle.NONE)
  339. pannel.pack_start(hambutton)
  340. # Let's now pack the hamburger menu with items
  341. hambox = Gtk.HBox()
  342. # For the elements inside the box we need a scrolled window, to fit a lot of
  343. # them there.
  344. hamscrl = Gtk.ScrolledWindow()
  345. hamscrl.set_size_request(200,200)
  346. hamburger.add(hambox)
  347. hambox.pack_start(hamscrl, False, False, False)
  348. # "hamchannelbox" will be empty untill the user connects and it loads his channel
  349. # list
  350. hamchannelbox = Gtk.VBox()
  351. hamscrl.add_with_viewport(hamchannelbox)
  352. #hambox.pack_start(hamchannelbox, False, False, False)
  353. ###### CHANNELS SELECTOR ########
  354. win.channel = False
  355. def load_channel(win):
  356. def change_channel(w, win, channel ):
  357. win.channel = channel
  358. win.settings["channel"] = win.channel["claim_id"]
  359. settings.save(win.settings)
  360. try:
  361. hambutton.get_child().destroy()
  362. try:
  363. newicon = ui.load(win, ui.net_image_calculation, ui.net_image_render, channel["value"]["thumbnail"]["url"], 40, "", False )
  364. except:
  365. newicon = ui.icon(win, "system-users")
  366. hambutton.add(newicon)
  367. pannel.show_all()
  368. except Exception as e:
  369. print("What?", e)
  370. out = fetch.lbrynet("channel_list")
  371. win.my_channels = out
  372. # We are chooseing first only if there is no channel set in the settings
  373. try:
  374. first = out["items"][0]
  375. win.channel = first
  376. except:
  377. pass
  378. if "channel" in win.settings:
  379. try:
  380. for i in out["items"]:
  381. if i["claim_id"] == win.settings["channel"]:
  382. first = i
  383. break
  384. except:
  385. pass
  386. try:
  387. change_channel(False, win, first)
  388. except:
  389. pass
  390. try:
  391. go.set_sensitive(True)
  392. for i in out["items"]:
  393. channel_button = ui.go_to_channel(win, i, resolve=False)
  394. channel_button.connect("clicked", change_channel, win, i)
  395. hamchannelbox.pack_start(channel_button, False, False, False)
  396. hamchannelbox.show_all()
  397. second_raw.show_all()
  398. except Exception as e:
  399. print("CHANNEL ERROR:", e)
  400. second_raw = Gtk.VBox()
  401. hambox.pack_start(Gtk.VSeparator(), False, False, 5)
  402. hambox.pack_start(second_raw, False, False, False)
  403. ####### Go to channel button #####
  404. def go_to_channel(w):
  405. channel_url = win.channel["name"]
  406. try:
  407. channel_url = channel_url + "#" + win.channel["claim_id"]
  408. except:
  409. pass
  410. win.url.set_text(channel_url)
  411. win.url.activate()
  412. go = Gtk.Button()
  413. b = Gtk.HBox()
  414. b.pack_start(ui.icon(win, "folder-remote"), False, False, False)
  415. b.pack_start(Gtk.Label(" Go To Channel "), True, True, False)
  416. go.add(b)
  417. go.set_sensitive(False)
  418. go.set_relief(Gtk.ReliefStyle.NONE)
  419. go.connect("clicked", go_to_channel)
  420. second_raw.pack_start(go, False, False, False)
  421. ########## UPLOADS BUTTON #########
  422. def load_uploads(w=False):
  423. dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
  424. for i in dynamic_box.get_children():
  425. i.destroy()
  426. send = {"method":"claim_list"}
  427. resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
  428. dynamic_box.pack_start(resolve, True, True, True)
  429. dynamic_box.show_all()
  430. win.tabs[win.notebook.get_current_page()]["label"].set_text("Uploads")
  431. win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text("Uploads")
  432. following = Gtk.Button()
  433. b = Gtk.HBox()
  434. b.pack_start(ui.icon(win, "go-up-symbolic"), False, False, False)
  435. b.pack_start(Gtk.Label(" Uploads "), True, True, False)
  436. following.add(b)
  437. following.set_relief(Gtk.ReliefStyle.NONE)
  438. following.connect("clicked", load_uploads)
  439. second_raw.pack_start(following, False, False,False)
  440. ############## ANALYTICS ################
  441. def load_analytics(w):
  442. analytics.window(win)
  443. following = Gtk.Button()
  444. b = Gtk.HBox()
  445. b.pack_start(ui.icon(win, "text-csv"), False, False, False)
  446. b.pack_start(Gtk.Label(" Wallet "), True, True, False)
  447. following.add(b)
  448. following.set_relief(Gtk.ReliefStyle.NONE)
  449. following.connect("clicked", load_analytics)
  450. second_raw.pack_start(following, False, False,False)
  451. second_raw.pack_start(Gtk.HSeparator(), False, False,5)
  452. ######## FOLLOWING BUTTON ###########
  453. def load_following( w=False, mode="following"):
  454. dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
  455. for i in dynamic_box.get_children():
  456. i.destroy()
  457. try:
  458. if not win.subs:
  459. out = fetch.lbrynet("preference_get")
  460. win.subs = out["shared"]["value"]["subscriptions"]
  461. subs_raw = fetch.lbrynet("resolve", {"urls":win.subs})
  462. subs = []
  463. for i in subs_raw:
  464. try:
  465. subs.append(subs_raw[i]["claim_id"])
  466. except:
  467. pass
  468. except Exception as e:
  469. print("\n\nERROR:", e, "\n\n")
  470. subs = []
  471. if mode == "suggest":
  472. send = {"any_tags":suggest.suggest(),
  473. "order_by":"trending_mixed"}
  474. resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
  475. else:
  476. resolve = ui.load(win, claim_search.find, claim_search.render, win, "", subs)
  477. # Currently live!
  478. all_lives = livestreams.get_all()
  479. liveids = []
  480. if mode != "suggest":
  481. for livestream in all_lives.get("data", []):
  482. live_id = livestream.get("ActiveClaim", {}).get("ClaimID", "")
  483. if livestream.get("ChannelClaimID", "") in subs:
  484. liveids.append(live_id)
  485. else:
  486. for livestream in all_lives.get("data", []):
  487. live_id = livestream.get("ActiveClaim", {}).get("ClaimID", "")
  488. liveids.append(live_id)
  489. if liveids:
  490. send = {"claim_ids":liveids}
  491. if mode == "suggest":
  492. send["any_tags"] = suggest.suggest()
  493. resolve_lives = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
  494. lives_frame = Gtk.Expander(label=" Currently Live: ")
  495. if mode != "suggest":
  496. lives_frame.set_expanded(True)
  497. resolve_lives.set_size_request(350,350)
  498. lives_frame.add(resolve_lives)
  499. dynamic_box.pack_start(lives_frame, 0,0,0)
  500. dynamic_box.pack_start(Gtk.HSeparator(), 0,0,5)
  501. dynamic_box.pack_start(resolve, True, True, True)
  502. dynamic_box.show_all()
  503. if mode == "suggest":
  504. win.tabs[win.notebook.get_current_page()]["label"].set_text("Suggested")
  505. win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text("Suggested")
  506. else:
  507. win.tabs[win.notebook.get_current_page()]["label"].set_text("Following")
  508. win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text("Following")
  509. following = Gtk.Button()
  510. b = Gtk.HBox()
  511. b.pack_start(ui.icon(win, "semi-starred"), False, False, False)
  512. b.pack_start(Gtk.Label(" Suggested "), True, True, False)
  513. following.add(b)
  514. following.set_relief(Gtk.ReliefStyle.NONE)
  515. following.connect("clicked", load_following, "suggest")
  516. second_raw.pack_start(following, False, False,False)
  517. following = Gtk.Button()
  518. b = Gtk.HBox()
  519. b.pack_start(ui.icon(win, "emblem-favorite"), False, False, False)
  520. b.pack_start(Gtk.Label(" Following "), True, True, False)
  521. following.add(b)
  522. following.set_relief(Gtk.ReliefStyle.NONE)
  523. following.connect("clicked", load_following)
  524. second_raw.pack_start(following, False, False,False)
  525. ######## TRENDING BUTTONS ###########
  526. def load_trending(w=False, articles=False):
  527. dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
  528. for i in dynamic_box.get_children():
  529. i.destroy()
  530. send = {"order_by":"trending_mixed"}
  531. if articles:
  532. send["media_types"] = ["text/markdown"]
  533. resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
  534. dynamic_box.pack_start(resolve, True, True, True)
  535. dynamic_box.show_all()
  536. if articles:
  537. lname = "Articles"
  538. else:
  539. lname = "Trending"
  540. win.tabs[win.notebook.get_current_page()]["label"].set_text(lname)
  541. win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text(lname)
  542. following = Gtk.Button()
  543. b = Gtk.HBox()
  544. # The other one was showing web-browsers at some themes
  545. b.pack_start(ui.icon(win, "emblem-shared"), False, False, False)
  546. b.pack_start(Gtk.Label(" Trending "), True, True, False)
  547. following.add(b)
  548. following.set_relief(Gtk.ReliefStyle.NONE)
  549. following.connect("clicked", load_trending)
  550. second_raw.pack_start(following, False, False,False)
  551. following = Gtk.Button()
  552. b = Gtk.HBox()
  553. b.pack_start(ui.icon(win, "text-x-generic"), False, False, False)
  554. b.pack_start(Gtk.Label(" Articles "), True, True, False)
  555. following.add(b)
  556. following.set_relief(Gtk.ReliefStyle.NONE)
  557. following.connect("clicked", load_trending, True)
  558. second_raw.pack_start(following, False, False,False)
  559. #### LIVESTREAMS ####
  560. def load_livestreams(w):
  561. # First let's fetch the data about all livestreams
  562. all_lives = livestreams.get_all()
  563. liveids = []
  564. for livestream in all_lives.get("data", []):
  565. live_id = livestream.get("ActiveClaim", {}).get("ClaimID", "")
  566. liveids.append(live_id)
  567. # Then we gonna search all the liveids
  568. dynamic_box = win.tabs[win.notebook.get_current_page()]["box"]
  569. for i in dynamic_box.get_children():
  570. i.destroy()
  571. send = {"claim_ids":liveids}
  572. resolve = ui.load(win, claim_search.find, claim_search.render, win, "", [], 1, send)
  573. dynamic_box.pack_start(resolve, True, True, True)
  574. dynamic_box.show_all()
  575. lname = "Live Streams"
  576. win.tabs[win.notebook.get_current_page()]["label"].set_text(lname)
  577. win.tabs[win.notebook.get_current_page()]["label"].set_tooltip_text(lname)
  578. following = Gtk.Button()
  579. b = Gtk.HBox()
  580. b.pack_start(ui.icon(win, "emblem-new"), False, False, False)
  581. b.pack_start(Gtk.Label(" Live Streams "), True, True, False)
  582. following.add(b)
  583. following.set_relief(Gtk.ReliefStyle.NONE)
  584. following.connect("clicked", load_livestreams)
  585. second_raw.pack_start(following, False, False,False)
  586. second_raw.pack_start(Gtk.HSeparator(), False, False,5)
  587. ######## DOWNLOADS #########
  588. def load_downloads(w):
  589. downloads.window(win)
  590. following = Gtk.Button()
  591. b = Gtk.HBox()
  592. b.pack_start(ui.icon(win, "go-down-symbolic"), False, False, False)
  593. b.pack_start(Gtk.Label(" Downloads "), True, True, False)
  594. following.add(b)
  595. following.set_relief(Gtk.ReliefStyle.NONE)
  596. following.connect("clicked", load_downloads)
  597. second_raw.pack_start(following, False, False,False)
  598. second_raw.pack_start(Gtk.HSeparator(), False, False,5)
  599. ######## SETTINGS BUTTON ############
  600. second_raw.pack_start(Gtk.HSeparator(), False, False,5)
  601. settings_button = Gtk.Button()
  602. b = Gtk.HBox()
  603. b.pack_start(ui.icon(win, "preferences-system"), False, False, False)
  604. b.pack_start(Gtk.Label(" Settings "), True, True, False)
  605. settings_button.add(b)
  606. settings_button.set_relief(Gtk.ReliefStyle.NONE)
  607. settings_button.connect("clicked", settings.dialogue, win)
  608. second_raw.pack_start(settings_button, False, False, False)
  609. second_raw.pack_start(Gtk.HSeparator(), False, False,5)
  610. ########## FORCE SEARCH BUTTON #######
  611. force_search_box = Gtk.HBox()
  612. force_search = Gtk.Switch()
  613. force_search_box.pack_end(force_search, False, False, 0)
  614. force_search_box.pack_start(ui.icon(win, "system-search"), False, False, 0)
  615. force_search_box.pack_start(Gtk.Label(" Force Search "), True, True, 0)
  616. force_search.set_tooltip_text("If not activated it will try to resolve the claim first.")
  617. second_raw.pack_start(force_search_box, False, False, False)
  618. ###### THE BOX FOR THE NOTIFICATIONS #####
  619. win.notifications_box = Gtk.VBox()
  620. hambox.pack_start(Gtk.VSeparator(), False, False, 5)
  621. hambox.pack_start(win.notifications_box, False, False, False)
  622. hambox.show_all()
  623. ##########################################################################
  624. # #
  625. # DYNAMIC BOX ( REST ) #
  626. # #
  627. ##########################################################################
  628. # Dynamic box is a box contents of which will change depending on the "page"
  629. # that the user is loading.
  630. box = Gtk.VBox() # I'm making a top level box just in case
  631. win.add(box)
  632. win.notebook.set_scrollable(True)
  633. def new_tab():
  634. dynamic_box = Gtk.VBox() # And here our dynamic box
  635. label = Gtk.Label("Tab "+str(len(win.tabs)+1))
  636. kill = Gtk.Button()
  637. kill.add(ui.icon(win, "delete"))
  638. kill.set_relief(Gtk.ReliefStyle.NONE)
  639. box = Gtk.HBox()
  640. box.pack_start(label, False, False, 5)
  641. box.pack_start(kill, False, False, 0)
  642. box.show_all()
  643. tab = {"box":dynamic_box, "label":label, "index":len(win.tabs)}
  644. def on_kill(w, tab):
  645. if len(win.tabs) == 1:
  646. load_following(mode=win.settings["default_tab"])
  647. return
  648. i = tab["index"]
  649. win.notebook.remove_page(i)
  650. del win.tabs[i]
  651. for r, t in enumerate(win.tabs):
  652. t["index"] = r
  653. kill.connect("clicked", on_kill, tab)
  654. win.tabs.append(tab)
  655. win.resolve_tab = len(win.tabs) - 1
  656. win.notebook.append_page(win.tabs[-1]["box"], box)
  657. new_tab()
  658. box.pack_start(win.notebook, True, True, False)
  659. # Just something to run if we are connected
  660. if win.SDK_running == 1:
  661. load_following(mode=win.settings["default_tab"])
  662. load_channel(win)
  663. else:
  664. win.tabs[0]["box"].pack_start(Gtk.Label("LBRY is not connected. Please connect."), True, True, 20)
  665. ##########################################################################
  666. # #
  667. # DRAG AND DROP #
  668. # #
  669. ##########################################################################
  670. def on_drop(widget, drag_context, x, y, data, info, time):
  671. win.url.set_text(data.get_text())
  672. win.url.activate()
  673. enforce_target = Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags(4), 129)
  674. box.drag_dest_set(Gtk.DestDefaults.ALL, [enforce_target], Gdk.DragAction.COPY)
  675. box.connect("drag-data-received", on_drop)
  676. if win.settings["autoconnect"] and win.SDK_running != 1:
  677. connect_disconnect_function(connect_disconncet_button)
  678. # Starting Everything
  679. win.show_all()
  680. Gtk.main()
  681. #### Clearing the cache of images ###
  682. ui.clean_image_cache()
  683. if win.settings["autoconnect"]:
  684. connect.stop(win)