url.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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. import os
  30. import time
  31. import urllib.request
  32. import threading
  33. import json
  34. from subprocess import *
  35. from gi.repository import Gtk
  36. from gi.repository import Gdk
  37. from gi.repository import GLib
  38. from gi.repository import Pango
  39. from gi.repository import GdkPixbuf
  40. from PIL import Image, ImageSequence
  41. from flbry import markdown
  42. from flbry import data_view
  43. from flbry import ui
  44. from flbry import fetch
  45. from flbry import claim_search
  46. from flbry import comments
  47. from flbry import follow
  48. from flbry import publish
  49. from flbry import analytics
  50. def resolve(w, win, url):
  51. # This function will draw a widget of rsolved url
  52. #####################################################
  53. # RESOLVING PART ( NO GTK ) #
  54. #####################################################
  55. out = fetch.lbrynet("resolve",
  56. {"urls":[url]}
  57. )
  58. out = out[url]
  59. # Saving the resolved thing into the win for later use
  60. win.resolved = out
  61. # out = check_output(["flbry/lbrynet",
  62. # "resolve", url])
  63. # raw_data = out.decode("utf-8")
  64. # # Now we want to parse the json
  65. # try:
  66. # out = json.loads(out)
  67. # out = out[url]
  68. # except:
  69. # print("Resolve Failed")
  70. # return False
  71. try:
  72. is_channel = "value_type" in out and out["value_type"] == "channel"
  73. percentage = downloaded(out["claim_id"])
  74. except:
  75. # If this fails we activate search
  76. return ["search", False, False, w, win, url]
  77. # make sure the url path starts with lbry://
  78. if not url.startswith("lbry://"):
  79. url = "lbry://"+url
  80. win.url.set_text(url)
  81. return [out, is_channel, percentage, w, win, url]
  82. def render_resolve(data):
  83. out, is_channel, percentage, w, win, url = data
  84. # It could be failed
  85. if out == "search":
  86. return ui.load(win, claim_search.find, claim_search.render, win, win.url.get_text(), [], 1, {"order_by":""})
  87. #####################################################
  88. # DRAWING PART ( GTK ) #
  89. #####################################################
  90. try:
  91. price = out["value"]["fee"]["amount"]
  92. except:
  93. price = 0
  94. try:
  95. currency = out["value"]["fee"]["currency"]
  96. except:
  97. currency = "LBC"
  98. box = Gtk.HBox()
  99. outbox = Gtk.VBox()
  100. #### THUMBNAIL ###
  101. thumb = ""
  102. try:
  103. thumb = out["value"]["thumbnail"]["url"]
  104. thumb_url = ui.image_save_name(thumb)
  105. def thumb_open(w):
  106. os.system("xdg-open "+thumb_url)
  107. thumb_button = Gtk.Button()
  108. thumb_button.set_tooltip_text(thumb)
  109. if is_channel:
  110. thumb_image = ui.load(win, ui.net_image_calculation, ui.net_image_render, thumb, 150, "", True)
  111. else:
  112. thumb_image = ui.load(win, ui.net_image_calculation, ui.net_image_render, thumb, 400, "", True)
  113. thumb_button.add(thumb_image)
  114. thumb_button.set_relief(Gtk.ReliefStyle.NONE)
  115. thumb_button.connect("clicked", thumb_open)
  116. box.pack_start(thumb_button, False, False, False)
  117. except:
  118. pass
  119. outbox.pack_start(box, False, False, False)
  120. from_right_to_thumbnail = Gtk.VBox()
  121. box.pack_end(from_right_to_thumbnail, True, True, False)
  122. # If channel load banner
  123. if is_channel:
  124. if "cover" in out["value"]:
  125. # This is a hack to set the scroller at the center
  126. # of the cover image
  127. def render_cover(calc):
  128. # So this fucntion pretends to be the net_image_render
  129. r = ui.net_image_render(calc) # It does call it though
  130. # But we need the size of the image and we need to do
  131. # something after the image is loaded.
  132. def wait():
  133. # This will execute after a delay
  134. v = channel_scroll.get_vadjustment()
  135. h = channel_scroll.get_hadjustment()
  136. # TODO: Check that the math is correct. It seems
  137. # to move the scrolls a bit too far.
  138. v.set_value( r.get_pixbuf().get_height() / 2 - 75)
  139. h.set_value( r.get_pixbuf().get_width() / 2 - 100)
  140. def start_waiting():
  141. # This is the delay thread
  142. time.sleep(0.1)
  143. GLib.idle_add(wait) # Making sure to use GLib so not
  144. # to get Segmentation Fault
  145. load_thread = threading.Thread(target=start_waiting)
  146. load_thread.start()
  147. # And we need to give the renderer the image itself, so it
  148. # could be added into the UI.
  149. return r # This happens before we scroll to the center
  150. # So think about it:
  151. # 1. ui.load loads the ui.net_image_calclation which downloads the cover
  152. # 2. This function runs. Activating ui.net_image_render getting the Gtk.Image
  153. # 3. We setup the thread that waits for 0.1 seconds
  154. # 4. Meanwhile ui.load recieves the ui.image and window updates with it
  155. # 5. 0.1 seconds later: we calculate the width and height of the image
  156. # and set the scroll adjustments accordilgly.
  157. # Simple isn't it?
  158. channel_banner = ui.load(win, ui.net_image_calculation, render_cover, out["value"]["cover"]["url"], False, "", True)
  159. channel_scroll = Gtk.ScrolledWindow()
  160. channel_scroll.set_size_request(400,150)
  161. channel_scroll.add_with_viewport(channel_banner)
  162. from_right_to_thumbnail.pack_start(channel_scroll, False, False, False)
  163. else:
  164. try:
  165. channel_scroll.destroy()
  166. except:
  167. pass
  168. #### NAME / CHANNEL ####
  169. the_packing_box = from_right_to_thumbnail
  170. if is_channel:
  171. the_packing_box = outbox
  172. name_channel_box = Gtk.VBox()
  173. the_packing_box.pack_start(name_channel_box, False, False, False)
  174. # Channel
  175. if "signing_channel" in out:
  176. chbox = Gtk.HBox()
  177. name_channel_box.pack_start(chbox, False, False, 0)
  178. chbox.pack_start(ui.go_to_channel(win, out["signing_channel"]),True,True,False)
  179. fbutton = follow.button(win, out["signing_channel"]["permanent_url"])
  180. chbox.pack_start(fbutton, False, False, 0 )
  181. elif is_channel:
  182. fbutton = follow.button(win, out["permanent_url"])
  183. name_channel_box.pack_start(fbutton, False, False, False)
  184. # name it self
  185. title = out["name"]
  186. try:
  187. title = out["value"]["title"]
  188. except:
  189. pass
  190. title_label = Gtk.Label()
  191. title_label.set_line_wrap_mode( Gtk.WrapMode.WORD )
  192. title_label.set_line_wrap(True)
  193. title_label.set_markup('<span size="x-large"> '+title+'</span> ')
  194. title_label.set_selectable(True)
  195. title_label.set_css_name("")
  196. name_channel_box.pack_start(title_label, False, False, False)
  197. ################# TOOL BAR ##################
  198. toolbox = Gtk.HBox()
  199. the_packing_box.pack_start(toolbox, False, False,False)
  200. if not is_channel:
  201. def download_action(w):
  202. start_downloading(url)
  203. download_button = Gtk.Button()
  204. download_button.connect("clicked", download_action)
  205. download_button.set_relief(Gtk.ReliefStyle.NONE)
  206. download_box = Gtk.HBox()
  207. download_button.add(download_box)
  208. download_icon = ui.icon(win, "go-down")
  209. download_box.pack_start(download_icon, False, False, False)
  210. #filesize
  211. labeltext = " Download"
  212. if price:
  213. labeltext = " Buy for "+str(price)+" "+currency
  214. try:
  215. filesize = out["value"]["source"]["size"]
  216. labeltext = labeltext + " ("+csize(filesize)+")"
  217. except:
  218. filesize = 0
  219. download_box.pack_start(Gtk.Label(labeltext), False, False, False)
  220. toolbox.pack_start(download_button, False,False,False)
  221. download_bar = Gtk.ProgressBar()
  222. the_packing_box.pack_start(download_bar, False, False,False)
  223. def delete_action(w):
  224. filename = get_downloaded_file(out["claim_id"])
  225. delete_file(out["claim_id"])
  226. try:
  227. os.remove(filename)
  228. except:
  229. pass
  230. delete_button = Gtk.Button()
  231. delete_button.connect("clicked", delete_action)
  232. delete_button.set_relief(Gtk.ReliefStyle.NONE)
  233. delete_box = Gtk.HBox()
  234. delete_button.add(delete_box)
  235. delete_icon = ui.icon(win,"edit-delete")
  236. delete_box.pack_start(delete_icon, False, False, False)
  237. delete_box.pack_start(Gtk.Label(" Delete "), False, False, False)
  238. toolbox.pack_start(delete_button, False,False,False)
  239. def launch_action(w):
  240. Popen(["xdg-open", get_downloaded_file(out["claim_id"])])
  241. launch_button = Gtk.Button()
  242. launch_button.connect("clicked", launch_action)
  243. launch_button.set_relief(Gtk.ReliefStyle.NONE)
  244. launch_box = Gtk.HBox()
  245. launch_button.add(launch_box)
  246. launch_icon = ui.icon(win, "media-playback-start")
  247. launch_box.pack_start(launch_icon, False, False, False)
  248. launch_box.pack_start(Gtk.Label(" Launch "), False, False, False)
  249. toolbox.pack_start(launch_button, False,False,False)
  250. win.download_buttons[out["claim_id"]] = True
  251. t = threading.Thread(target=downloading_check_thread, args=(win, out["claim_id"],download_button, delete_button, launch_button, download_bar))
  252. t.setDaemon(True)
  253. t.start()
  254. def kill_daemon(w):
  255. win.download_buttons[out["claim_id"]] = False
  256. download_button.connect("destroy", kill_daemon)
  257. #################### REPOST BUTTON #######################
  258. toolbox.pack_start(Gtk.HSeparator(), False,False,5)
  259. def repost_action(w):
  260. print("name", repost_name_entry.get_text())
  261. print("bid", repost_bid_entry.get_value())
  262. print("channel", win.channel["name"])
  263. print("channel_id", win.channel["claim_id"])
  264. repost_out = fetch.lbrynet("stream_repost",
  265. {"name":repost_name_entry.get_text(),
  266. "bid":str(float(repost_bid_entry.get_value())),
  267. "claim_id":out["claim_id"],
  268. "channel_id":win.channel["claim_id"]})
  269. print(repost_out)
  270. if "error" in repost_out:
  271. ui.notify(win, "Error while reposting", str(repost_out["error"]))
  272. else:
  273. ui.notify(win, "Reposted succesfully.", "lbry://"+win.channel["name"]+"/"+repost_name_entry.get_text())
  274. repost_menu = Gtk.Popover()
  275. repost_menu_box = Gtk.VBox()
  276. repost_menu.add(repost_menu_box)
  277. # Repost requires 3 entries of data:
  278. # Name:
  279. def on_url(w):
  280. w.set_text(publish.lbryname(w.get_text(), force=False))
  281. repost_name_box = Gtk.HBox()
  282. repost_menu_box.pack_start(repost_name_box, 0,0,0)
  283. channel_name = win.channel.get("name", "")
  284. repost_name_box.pack_start(Gtk.Label(" lbry://"), 0,0,0)
  285. repost_name_entry = Gtk.Entry()
  286. repost_name_entry.connect("changed", on_url)
  287. repost_name_box.pack_start(repost_name_entry, 1,1,0)
  288. # Bid:
  289. repost_bid_box = Gtk.HBox()
  290. repost_menu_box.pack_start(repost_bid_box, 0,0,0)
  291. bid_adjust = Gtk.Adjustment(0.01,
  292. lower=0.0001,
  293. upper=1000000000,
  294. step_increment=0.1)
  295. repost_bid_entry = Gtk.SpinButton(adjustment=bid_adjust,
  296. digits=4)
  297. repost_bid_box.pack_start(Gtk.Label(" Bid: "), False, False, 0)
  298. repost_bid_box.pack_end(repost_bid_entry, False, False, 0)
  299. # Repost button
  300. do_repost_button = Gtk.Button()
  301. do_repost_button.connect("clicked", repost_action)
  302. do_repost_button.set_relief(Gtk.ReliefStyle.NONE)
  303. do_repost_box = Gtk.HBox()
  304. do_repost_box.pack_start(ui.icon(win, "media-playlist-repeat"), 0,0,0)
  305. do_repost_box.pack_start(Gtk.Label(" Do Re-Post "), False, False, False)
  306. do_repost_button.add(do_repost_box)
  307. repost_menu_box.pack_start(do_repost_button, 0,0,0)
  308. repost_menu_box.show_all()
  309. repost_button = Gtk.MenuButton(popover=repost_menu)
  310. repost_button.set_relief(Gtk.ReliefStyle.NONE)
  311. repost_box = Gtk.HBox()
  312. repost_button.add(repost_box)
  313. repost_icon = ui.icon(win, "media-playlist-repeat")
  314. repost_box.pack_start(repost_icon, False, False, False)
  315. try:
  316. reposted_times = out["meta"]["reposted"]
  317. if not reposted_times:
  318. 1/0 # kill switch to go straig to except LOL. I'm hacking. What
  319. # do you want from me.
  320. repost_label = " Re-Post ( "+str(reposted_times)+" ) "
  321. except:
  322. repost_label = " Re-Post "
  323. repost_box.pack_start(Gtk.Label(repost_label), False, False, False)
  324. toolbox.pack_start(repost_button, False,False,False)
  325. ############# SUPPORT BUTTON ############
  326. support_menu = Gtk.Popover()
  327. support_menu_box = Gtk.VBox()
  328. support_menu.add(support_menu_box)
  329. # Bid:
  330. support_bid_box = Gtk.HBox()
  331. support_menu_box.pack_start(support_bid_box, 0,0,0)
  332. support_bid_adjust = Gtk.Adjustment(0.01,
  333. lower=0.0001,
  334. upper=1000000000,
  335. step_increment=0.1)
  336. support_bid_entry = Gtk.SpinButton(adjustment=support_bid_adjust,
  337. digits=4)
  338. support_bid_box.pack_start(Gtk.Label(" Amount: "), False, False, 0)
  339. support_bid_box.pack_end(support_bid_entry, False, False, 0)
  340. # Do button
  341. def support_action(w):
  342. print("support amount", support_bid_entry.get_value())
  343. print("channel", win.channel["name"])
  344. print("channel_id", win.channel["claim_id"])
  345. support_out = fetch.lbrynet("support_create",
  346. {"amount":str(float(support_bid_entry.get_value())),
  347. "claim_id":out["claim_id"],
  348. "channel_id":win.channel["claim_id"],
  349. "tip":True})
  350. print(support_out)
  351. if "error" in support_out:
  352. ui.notify(win, "Error while reposting", str(support_out["error"]))
  353. else:
  354. ui.notify(win, "Supported succesfully.")
  355. do_support_button = Gtk.Button()
  356. do_support_button.connect("clicked", support_action)
  357. do_support_button.set_relief(Gtk.ReliefStyle.NONE)
  358. do_support_box = Gtk.HBox()
  359. do_support_box.pack_start(ui.icon(win, "emblem-favorite"), 0,0,0)
  360. do_support_box.pack_start(Gtk.Label(" Do Support "), False, False, False)
  361. do_support_button.add(do_support_box)
  362. support_menu_box.pack_start(do_support_button, 0,0,0)
  363. support_menu_box.show_all()
  364. support_button = Gtk.MenuButton(popover=support_menu)
  365. support_button.set_relief(Gtk.ReliefStyle.NONE)
  366. support_box = Gtk.HBox()
  367. support_button.add(support_box)
  368. support_icon = ui.icon(win, "emblem-favorite")
  369. support_box.pack_start(support_icon, False, False, False)
  370. try:
  371. rounded = round(float(out["meta"]["effective_amount"]), 2)
  372. if not rounded:
  373. rounded = out["meta"]["effective_amount"]
  374. support_label = " Support ( "+str(rounded)+" ) "
  375. except Exception as e:
  376. print(e)
  377. support_label = " Support "
  378. support_box.pack_start(Gtk.Label(support_label), False, False, False)
  379. toolbox.pack_start(support_button, False,False,False)
  380. ########### BOTTOM NOTEBOOK ##############
  381. notebook = Gtk.Notebook()
  382. notebook.set_scrollable(True)
  383. outbox.pack_start(notebook, True, True,False)
  384. # If article read article
  385. try:
  386. if out["value"]["source"]["media_type"] == "text/markdown" and price == 0:
  387. # We download it first
  388. playout = fetch.lbrynet("get", {"uri":url, "save_file":True})
  389. # playout = check_output(["flbry/lbrynet",
  390. # "get", url])
  391. # # Parsing the Json
  392. # playout = json.loads(playout)
  393. md_text = open(playout['download_path'])
  394. md_text = md_text.read()
  395. # Markdown covenreted
  396. md_scrl = Gtk.ScrolledWindow()
  397. md_view = Gtk.TextView()
  398. md_view.set_wrap_mode(Gtk.WrapMode.WORD )
  399. md_buffer = md_view.get_buffer()
  400. md_view.set_editable(False)
  401. md_scrl.add(md_view)
  402. md_buffer.set_text(md_text)
  403. markdown.convert(win, md_view)
  404. detailsbox = Gtk.HBox()
  405. detailsbox.pack_start(ui.icon(win, "text-x-generic"), False, False, False)
  406. detailsbox.pack_start(Gtk.Label(" Read Article "), True, True, True)
  407. detailsbox.show_all()
  408. notebook.append_page(md_scrl, detailsbox)
  409. # Markdown source
  410. md_scrl = Gtk.ScrolledWindow()
  411. md_view = Gtk.TextView()
  412. #md_view.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(0.2,0.2,0.2, 1))
  413. #md_view.override_color(Gtk.StateType.NORMAL, Gdk.RGBA(0.9,0.9,0.9, 1))
  414. md_view.override_font(Pango.FontDescription("Monospace"))
  415. md_view.set_wrap_mode(Gtk.WrapMode.WORD )
  416. md_buffer = md_view.get_buffer()
  417. md_view.set_editable(False)
  418. md_scrl.add(md_view)
  419. md_buffer.set_text(md_text)
  420. detailsbox = Gtk.HBox()
  421. detailsbox.pack_start(ui.icon(win, "text-x-preview"), False, False, False)
  422. detailsbox.pack_start(Gtk.Label(" Source of Article "), True, True, True)
  423. detailsbox.show_all()
  424. notebook.append_page(md_scrl, detailsbox)
  425. except Exception as e:
  426. print("FUCKING ERROR")
  427. print(e)
  428. print()
  429. # Channel Uploads / Publications
  430. if is_channel:
  431. uploads_box = ui.load(win, claim_search.find, claim_search.render, win, "", [out["claim_id"]], )
  432. detailsbox = Gtk.HBox()
  433. detailsbox.pack_start(ui.icon(win, "folder-remote"), False, False, False)
  434. detailsbox.pack_start(Gtk.Label(" Publications "), True, True, True)
  435. detailsbox.show_all()
  436. notebook.append_page(uploads_box, detailsbox)
  437. ##### DESCRIPTION ####
  438. try:
  439. description_scrl = Gtk.ScrolledWindow()
  440. description_scrl.set_size_request(500,200)
  441. description_field = Gtk.TextView()
  442. description_field.set_wrap_mode(Gtk.WrapMode.WORD )
  443. description_field.set_editable(False)
  444. description_buffer = description_field.get_buffer()
  445. description_buffer.set_text(out["value"]["description"])
  446. markdown.convert(win, description_field)
  447. description_box = Gtk.VBox()
  448. detailsbox = Gtk.HBox()
  449. detailsbox.pack_start(ui.icon(win, "text-x-generic"), False, False, False)
  450. detailsbox.pack_start(Gtk.Label(" Description "), True, True, True)
  451. detailsbox.show_all()
  452. notebook.append_page(description_scrl, detailsbox)
  453. description_box.pack_start(description_scrl, False, False, False)
  454. description_scrl.add(description_field)
  455. except:
  456. pass
  457. ######## COMMENTS ########
  458. com_box = Gtk.VBox()
  459. com_scrl = Gtk.ScrolledWindow()
  460. com_scrl.set_vexpand(0)
  461. #com_scrl.set_hexpand(0)
  462. comments_widget = ui.load(win, comments.list_comments, comments.render_comments, win, out )
  463. com_scrl.add(comments_widget)
  464. detailsbox = Gtk.HBox()
  465. detailsbox.pack_start(ui.icon(win, "document-send"), False, False, False)
  466. detailsbox.pack_start(Gtk.Label(" Comments "), True, True, True)
  467. detailsbox.show_all()
  468. com_box.pack_start(comments.comment_input(win, out["claim_id"]), False, False, 0)
  469. com_box.pack_start(com_scrl, True, True, 0)
  470. notebook.append_page(com_box, detailsbox)
  471. ##### Details #######
  472. # Almost like Raw Data but shows only the important stuff
  473. details = {"LBRY URL: ":url,
  474. "Price: ":str(price)+" "+str(currency)}
  475. try:
  476. details["Claim ID: "] = out["claim_id"]
  477. except:
  478. pass
  479. try:
  480. details["Upload Bid: "] = out["amount"]+" LBC"
  481. except:
  482. pass
  483. try:
  484. details["Support: "] = out["meta"]["support_amount"]+" LBC"
  485. except:
  486. pass
  487. try:
  488. details["Filename: "] = out["value"]["source"]["name"]
  489. except:
  490. pass
  491. try:
  492. details["File Size:"] = csize(filesize)
  493. except:
  494. pass
  495. try:
  496. details["License: "] = out["value"]["license"]
  497. except:
  498. pass
  499. try:
  500. details["Released at: "] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(out["value"]["release_time"])))
  501. except:
  502. pass
  503. try:
  504. #print(out["value"]["tags"])
  505. details["Tags: "] = out["value"]["tags"]
  506. except:
  507. pass
  508. det_scrl = Gtk.ScrolledWindow()
  509. det_view = data_view.data_widget(details)
  510. det_scrl.add(det_view)
  511. detailsbox = Gtk.HBox()
  512. detailsbox.pack_start(ui.icon(win, "dialog-information"), False, False, False)
  513. detailsbox.pack_start(Gtk.Label(" Details "), True, True, True)
  514. detailsbox.show_all()
  515. notebook.append_page(det_scrl, detailsbox)
  516. ######### ANALYTICS GRAPH #######
  517. plot_chart = fetch.lbrynet("txo_plot", { "days_back":1000, # Fetch 100 days of txo
  518. "exclude_internal_transfers":True, # Without crap
  519. "is_not_my_input":True, # Not from me ( as in support only )
  520. "claim_id":out["claim_id"]
  521. })
  522. if plot_chart:
  523. chart_box = Gtk.VBox()
  524. detailsbox = Gtk.HBox()
  525. detailsbox.pack_start(ui.icon(win, "text-csv"), False, False, False)
  526. detailsbox.pack_start(Gtk.Label(" Analytics "), True, True, True)
  527. detailsbox.show_all()
  528. notebook.append_page(chart_box, detailsbox)
  529. graph_data = {"items":[],
  530. "zoom":[0,0],
  531. "allow_negative":False
  532. }
  533. for i in plot_chart:
  534. a = {}
  535. a["amount"] = i["total"]
  536. a["timestamp"] = int(time.mktime(time.strptime(i["day"],"%Y-%m-%d")))
  537. graph_data["items"].append(a)
  538. the_graph = analytics.graph(win, graph_data, "Analytics")
  539. chart_box.pack_start(the_graph,1,1,1)
  540. try:
  541. t = title
  542. if is_channel:
  543. t = ""
  544. uploads_box = ui.load(win, claim_search.find, claim_search.render, win, t, [], 1, {"any_tags":out["value"]["tags"] , "claim_type":out["value_type"]} )
  545. detailsbox = Gtk.HBox()
  546. detailsbox.pack_start(ui.icon(win, "folder-remote"), False, False, False)
  547. detailsbox.pack_start(Gtk.Label(" Similar "), True, True, True)
  548. detailsbox.show_all()
  549. notebook.append_page(uploads_box, detailsbox)
  550. except:
  551. pass
  552. ##### Raw Data #######
  553. raw_scrl = Gtk.ScrolledWindow()
  554. raw_view = data_view.data_widget(out)
  555. raw_scrl.add(raw_view)
  556. detailsbox = Gtk.HBox()
  557. detailsbox.pack_start(ui.icon(win, "dialog-warning"), False, False, False)
  558. detailsbox.pack_start(Gtk.Label(" Extra Details "), True, True, True)
  559. detailsbox.show_all()
  560. notebook.append_page(raw_scrl, detailsbox)
  561. #outbox.show_all()
  562. return outbox
  563. def downloaded(claim_id):
  564. # Returns a fraction ( from 0 to 1 ) of the download
  565. # percentage. If it's a 0, we can use it to display
  566. # the download button.
  567. #out = check_output(["flbry/lbrynet",
  568. # "file", "list", "--claim_id="+claim_id])
  569. out = fetch.lbrynet("file_list", {"claim_id":claim_id})
  570. #print(out, '\n\n')
  571. try:
  572. #out = json.loads(out)
  573. out = out["items"][0]
  574. if out["status"] == "finished":
  575. return 1
  576. else:
  577. return out["written_bytes"] / out["total_bytes"]
  578. except:
  579. return 0
  580. def get_downloaded_file(claim_id):
  581. #out = check_output(["flbry/lbrynet",
  582. # "file", "list", "--claim_id="+claim_id])
  583. out = fetch.lbrynet("file_list", {"claim_id":claim_id})
  584. try:
  585. #out = json.loads(out)
  586. out = out["items"][0]
  587. return out["download_path"]
  588. except:
  589. return ""
  590. def delete_file(claim_id):
  591. #check_output(["flbry/lbrynet",
  592. # "file", "delete", "--claim_id="+claim_id])
  593. fetch.lbrynet("file_delete", {"claim_id":claim_id})
  594. def start_downloading(url):
  595. out = fetch.lbrynet("get", {"uri":url, "save_file":True})
  596. def downloading_check_thread(win, claim_id,
  597. download_button,
  598. delete_button,
  599. launch_button,
  600. progress_bar):
  601. # This is a thread that will toggle buttons on/off
  602. # based on a curretly downloading file.
  603. def update(fraction):
  604. if not fraction: # if it's 0
  605. download_button.set_visible(True)
  606. delete_button.set_visible(False)
  607. launch_button.set_visible(False)
  608. progress_bar.set_visible(False)
  609. else:
  610. download_button.set_visible(False)
  611. delete_button.set_visible(True)
  612. launch_button.set_visible(True)
  613. progress_bar.set_visible(True)
  614. progress_bar.set_fraction(fraction)
  615. if fraction == 1:
  616. progress_bar.set_visible(False)
  617. while True:
  618. fraction = downloaded(claim_id)
  619. GLib.idle_add(update, fraction)
  620. time.sleep(2) # The new algorithm is too fast LOL
  621. if not win.download_buttons[claim_id]:
  622. return
  623. def csize(x):
  624. x = float(x)
  625. l = ["B","KB", "MB", "GB", "TB"]
  626. for i in range(5):
  627. if x > 1024:
  628. x = x / 1024
  629. else:
  630. return str(round(x, 2))+" "+l[i]
  631. return str(round(x, 2))+" "+l[i]