123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- import os
- from subprocess import *
- from gi.repository import Gtk
- from gi.repository import Gdk
- from gi.repository import Pango
- from flbry import ui
- from flbry import parse
- from flbry import fetch
- EMOJIS ={
- ":alien:" :"",
- ":angry_1:" :"",
- ":angry_2:" :"",
- ":angry_3:" :"",
- ":angry_4:" :"",
- ":blind:" :"",
- ":block:" :"",
- ":bomb:" :"",
- ":brain_chip:":"",
- ":confirm:":"",
- ":confused_1:":"",
- ":confused_2:":"",
- ":cooking_something_nice:":"",
- ":cry_1:":"",
- ":cry_2:":"",
- ":cry_3:":"",
- ":cry_4:":"",
- ":cry_5:":"",
- ":donut:":"",
- ":eggplant_with_condom:":"",
- ":eggplant:":"",
- ":fire_up:":"",
- ":flat_earth:":"",
- ":flying_saucer:":"",
- ":heart_chopper:":"",
- ":hyper_troll:":"",
- ":ice_cream:":"",
- ":idk:":"",
- ":illuminati_1:":"",
- ":illuminati_2:":"",
- ":kiss_1:":"",
- ":kiss_2:":"",
- ":laser_gun:":"",
- ":laughing_1:":"",
- ":laughing_2:":"",
- ":lollipop:":"",
- ":love_1:":"",
- ":love_2:":"",
- ":monster:":"",
- ":mushroom:":"",
- ":nail_it:":"",
- ":no:":"",
- ":ouch:":"",
- ":peace:":"",
- ":pizza:":"",
- ":rabbit_hole:":"",
- ":rainbow_puke_1:":"",
- ":rainbow_puke_2:":"",
- ":rock:":"",
- ":sad:":"",
- ":salty:":"",
- ":scary:":"",
- ":sleep:":"",
- ":slime_down:":"",
- ":smelly_socks:":"",
- ":smile_1:":"",
- ":smile_2:":"",
- ":space_chad:":"",
- ":space_doge:":"",
- ":space_green_wojak:":"",
- ":space_julian:":"",
- ":space_red_wojak:":"",
- ":space_resitas:":"",
- ":space_tom:":"",
- ":spock:":"",
- ":star:":"",
- ":sunny_day:":"",
- ":surprised:":"",
- ":sweet:":"",
- ":thinking_1:":"",
- ":thinking_2:":"",
- ":thumb_down:":"",
- ":thumb_up_1:":"",
- ":thumb_up_2:":"",
- ":tinfoil_hat:":"",
- ":troll_king:":"",
- ":ufo:":"",
- ":waiting:":"",
- ":what:":"",
- ":woodoo_doll:":""
- }
- STICKERS = {
-
-
- "<stkr>:CAT:<stkr>":"",
- "<stkr>:FAIL:<stkr>":"",
- "<stkr>:HYPE:<stkr>":"",
- "<stkr>:PANTS_1:<stkr>":"",
- "<stkr>:FIRE:<stkr>":"",
- "<stkr>:SLIME:<stkr>":"",
- "<stkr>:PISS:<stkr>":"",
- "<stkr>:BULL_RIDE:<stkr>":"",
- "<stkr>:ELIMINATED:<stkr>":"",
- "<stkr>:EGG_CARTON:<stkr>":"",
- "<stkr>:BAN:<stkr>":"",
- "<stkr>:MONEY_PRINTER:<stkr>":"",
- "<stkr>:MOUNT_RUSHMORE:<stkr>":"",
- "<stkr>:EGIRL:<stkr>":"",
- "<stkr>:KANYE_WEST:<stkr>":"",
- "<stkr>:TAYLOR_SWIFT:<stkr>":"",
- "<stkr>:DONALD_TRUMP:<stkr>":"",
- "<stkr>:BILL_CLINTON:<stkr>":"",
- "<stkr>:EPSTEIN_ISLAND:<stkr>":"",
- "<stkr>:KURT_COBAIN:<stkr>":"",
- "<stkr>:BILL_COSBY:<stkr>":"",
- "<stkr>:CHE_GUEVARA:<stkr>":"",
- "<stkr>:CHRIS_CHAN:<stkr>":"",
- "<stkr>:PREGNANT_MAN_BLONDE:<stkr>":"",
- "<stkr>:PREGNANT_WOMAN_BROWN_HAIR:<stkr>":"",
- "<stkr>:ROCKET_SPACEMAN:<stkr>":"",
- "<stkr>:SALTY:<stkr>":"",
- "<stkr>:SICK_FLAME:<stkr>":"",
- "<stkr>:SICK_SKULL:<stkr>":"",
- "<stkr>:SPHAGETTI_BATH:<stkr>":"",
- "<stkr>:THUG_LIFE:<stkr>":"",
- "<stkr>:TRAP:<stkr>":"",
- "<stkr>:TRASH:<stkr>":"",
- "<stkr>:WHUUT:<stkr>":"",
-
- "<stkr>:TIP_HAND_FLIP:<stkr>":"",
- "<stkr>:TIP_HAND_FLIP_COIN:<stkr>":"",
- "<stkr>:TIP_HAND_FILP_LBC:<stkr>":"",
- "<stkr>:COMET_TIP:<stkr>":"",
- "<stkr>:SILVER_ODYSEE_COIN:<stkr>":"",
- "<stkr>:LBC_COMET_TIP:<stkr>":"",
- "<stkr>:SMALL_TIP:<stkr>":"",
- "<stkr>:SMALL_LBC_TIP:<stkr>":"",
- "<stkr>:BITE_TIP:<stkr>":"",
- "<stkr>:BITE_TIP_CLOSEUP:<stkr>":"",
- "<stkr>:BITE_LBC_CLOSEUP:<stkr>":"",
- "<stkr>:MEDIUM_TIP:<stkr>":"",
- "<stkr>:MEDIUM_LBC_TIP:<stkr>":"",
- "<stkr>:LARGE_TIP:<stkr>":"",
- "<stkr>:LARGE_LBC_TIP:<stkr>":"",
- "<stkr>:BIG_TIP:<stkr>":"",
- "<stkr>:BIG_LBC_TIP:<stkr>":"",
- "<stkr>:FORTUNE_CHEST:<stkr>":"",
- "<stkr>:FORTUNE_CHEST_LBC:<stkr>":"",
-
- }
- def Open(md):
-
-
- for emoji in EMOJIS:
- md = md.replace(emoji, EMOJIS[emoji])
-
-
-
- for sticker in STICKERS:
- if md == sticker:
- md = STICKERS[sticker]
- break
-
- md = "\n\n"+md
- md = md.split("\n")
-
-
-
-
- tree = []
- indent = 1
- c = []
- skip = 0
-
- for n,line in enumerate(md):
- if skip > n:
- continue
-
- ty = "text"
- te = line
-
-
-
-
- if line.startswith("```"):
-
-
-
- code = ""
- for l in md[n+1:]:
- if not l.startswith("```"):
- code = code + l + "\n"
-
- else:
- skip = n + code.count("\n") + 2
- break
-
- tree.append(["text_cm", code+"\n"])
- te = ""
-
- elif line.startswith("#"):
-
-
-
-
-
-
-
-
- ty = line.count("#")
-
- elif line.startswith(">"):
-
-
-
- ty = "text_q"
- te = te[1:]
-
- tree.append([ty, te+"\n"])
-
-
-
-
-
-
-
-
- newtree = []
-
- for block in tree:
- if block[0] == "text_cm":
- newtree.append(block)
- continue
-
- part = ""
- skip = 0
-
- for n, l in enumerate(block[-1]):
-
- if skip > n:
- continue
-
- part = part + l
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if part.endswith("[!["):
-
-
- newtree.append([block[0], part[:-3]])
- tooltip = ""
- imageurl = ""
- url = ""
- t = False
- iu = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t and not iu:
- iu = True
- elif le == ")" and t and iu:
- break
- elif not t:
- tooltip = tooltip +le
- elif t and not iu:
- imageurl = imageurl + le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- imageurl = imageurl[imageurl.find("(")+1:]
- url = url[url.find("(")+1:]
-
- apnd = ["image_link", imageurl, url]
-
- newtree.append(apnd)
- part = ""
-
-
- elif part.endswith("!["):
-
-
- newtree.append([block[0], part[:-2]])
-
- tooltip = ""
- url = ""
- t = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t:
- break
- elif not t:
- tooltip = tooltip +le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- url = url[url.find("(")+1:]
- apnd = ["image", tooltip, url]
- newtree.append(apnd)
-
- part = ""
-
-
- elif part.endswith("[") and not block[-1][n:].startswith('[!['):
-
-
- newtree.append([block[0], part[:-1]])
-
-
- tooltip = ""
- url = ""
- t = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t:
- break
- elif not t:
- tooltip = tooltip +le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- url = url[url.find("(")+1:]
-
- apnd = ["link", tooltip, url]
- newtree.append(apnd)
-
- part = ""
-
-
-
-
-
-
-
-
-
-
-
-
-
- elif part.endswith("**") and not block[-1][n+2:].startswith('*'):
-
-
-
- newtree.append([block[0], part[:-2]])
- if block[0] == "text":
- block[0] = "text_b"
- else:
- block[0] = "text"
- part = ""
-
- elif part.endswith("*") and not block[-1][n+1:].startswith('*'):
-
-
-
- newtree.append([block[0], part[:-1]])
- if block[0] == "text":
- block[0] = "text_i"
- else:
- block[0] = "text"
- part = ""
- elif part.endswith("`"):
-
-
-
- newtree.append([block[0], part[:-1]])
- tmpart = block[-1][n+1:]
- tmpart = tmpart[:tmpart.find("`")]
- newtree.append(["text_c", tmpart])
- skip = n+len(tmpart)+2
-
- block[0] = "text"
- part = ""
-
- newtree.append([block[0], part])
-
-
-
- tree = newtree
-
- return(tree)
- def search_convert(s):
-
-
-
-
-
-
-
- l = " ./\|[]{}()?!@#$%^&*`~:;'\"=,<>"
- s = s.lower().replace(" ","-")
- r = ""
- for i in s:
- if i not in l:
- r = r + i
- return r
- def convert(win, text_view, imwidth=800):
- text_buffer = text_view.get_buffer()
- st = text_buffer.get_start_iter()
- en = text_buffer.get_end_iter()
- text = text_buffer.get_text(st, en, True)
- text_buffer.set_text("")
- try:
- text_buffer.create_tag("text", justification=Gtk.Justification.FILL, left_margin=64, right_margin=64)
- text_buffer.create_tag("text_c", background="#eeeeee", foreground="#000000", font="Monospace", left_margin=64, right_margin=64, justification=Gtk.Justification.LEFT)
- text_buffer.create_tag("text_b", font="Bold", justification=Gtk.Justification.FILL, left_margin=64, right_margin=64)
- text_buffer.create_tag("text_i", font="Italic", justification=Gtk.Justification.FILL, left_margin=64, right_margin=64)
- text_buffer.create_tag("text_q", justification=Gtk.Justification.FILL, left_margin=200, right_margin=200)
- text_buffer.create_tag("header", size_points=30, justification=Gtk.Justification.CENTER, left_margin=64, right_margin=64)
- except:
- pass
- text_view.set_justification(Gtk.Justification.CENTER)
-
- md = Open(text)
- markup = ""
-
- for i in md:
-
- en = text_buffer.get_end_iter()
-
-
- if type(i[0]) == str and i[0].startswith("text") and not i[0] == "text_cm":
- if i[-1].startswith("___") or i[-1].startswith("---"):
-
-
- text_buffer.insert(en, "\n---")
-
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- def Expand(Widget, Discard):
- Width = text_view.get_allocated_width()
- Widget.set_size_request(Width, -1)
-
-
- B = Gtk.Box()
- Separator = Gtk.HSeparator()
- B.pack_start(Separator, 1,1,1)
- B.connect("draw", Expand)
- text_view.add_child_at_anchor(B , anchor)
- text_buffer.insert(en, "\n\n")
- continue
- elif (i[-1].startswith("lbry://") or i[-1].startswith("https://") or i[-1].startswith("http://")) and "youtu" not in i[-1] and i[0] != "text_c":
-
- def try_resolve(url):
- out = fetch.lbrynet("resolve", {"urls":parse.bar(url)})
-
- try:
- out = out[parse.bar(url)]
- is_channel = "value_type" in out and out["value_type"] == "channel"
- return ["lbry", url, out]
-
- except:
- return ["text", url, out]
-
- def render_resolved(data):
- t, url, out = data
- if t == "text":
- return Gtk.Label(url)
- elif t == "lbry":
- try:
- return ui.search_item(win, out, True)
- except:
- return Gtk.Label(url)
-
-
-
- w = ui.load(win, try_resolve, render_resolved, i[-1])
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- text_view.add_child_at_anchor(w , anchor)
-
- continue
-
- try:
- text_buffer.insert_with_tags_by_name(en, i[-1], i[0])
- except:
- text_buffer.insert(en, i[-1])
- elif i[0] == "text_cm":
- codeview = Gtk.TextView()
-
-
- codeview.override_font(Pango.FontDescription("Monospace"))
- codescrl = Gtk.ScrolledWindow()
- codeframe = Gtk.Frame()
- codeframe.add(codescrl)
- codescrl.set_size_request(imwidth, min(i[-1].count("\n")*20, 500 ))
- codeview.set_editable(True)
- codescrl.add(codeview)
- codebuffer = codeview.get_buffer()
- codebuffer.set_text(i[-1])
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- text_view.add_child_at_anchor(codeframe , anchor)
-
- elif type(i[0]) == int:
- text_buffer.insert_with_tags_by_name(en, i[-1].replace("#", ""), "header")
- elif i[0] == "image_link":
- image = ui.load(win, ui.net_image_calculation, ui.net_image_render, i[1], imwidth, "", True)
-
- def link_launch(w, link):
- os.system("xdg-open "+link)
- def link_resolve(w, link):
- win.url.set_text(link)
- win.url.activate()
- optionsthing = Gtk.Popover()
- optbox = Gtk.VBox()
- optionsthing.add(optbox)
- optbox.pack_start(Gtk.Label("Link"), False, False, 5)
- opt_link = Gtk.Entry()
- opt_link.set_editable(False)
- opt_link.set_text(i[-1])
- optbox.pack_start(opt_link, False, False, False)
- opt_launch = Gtk.Button("Launch")
- optbox.pack_start(opt_launch, False, False, False)
- opt_resolve = Gtk.Button("Resolve")
- optbox.pack_start(opt_resolve, False, False, False)
- opt_launch.connect("clicked", link_launch, i[-1])
- opt_resolve.connect("clicked", link_resolve, i[-1])
- optbox.pack_start(Gtk.HSeparator(), False, False, 5)
- optbox.pack_start(Gtk.Label("Image"), False, False, 5)
- opt_link = Gtk.Entry()
- opt_link.set_editable(False)
- opt_link.set_text(i[1])
- optbox.pack_start(opt_link, False, False, False)
- opt2_open = Gtk.Button("Open")
- optbox.pack_start(opt2_open, False, False, False)
- opt2_launch = Gtk.Button("Launch")
- optbox.pack_start(opt2_launch, False, False, False)
- opt2_resolve = Gtk.Button("Resolve")
- optbox.pack_start(opt2_resolve, False, False, False)
- opt2_open.connect("clicked", link_launch, ui.image_save_name(i[1]))
- opt2_launch.connect("clicked", link_launch, i[1])
- opt2_resolve.connect("clicked", link_resolve, i[1])
-
- optbox.show_all()
-
- link = Gtk.MenuButton(popover=optionsthing)
- link.add(image)
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- text_view.add_child_at_anchor(link, anchor)
-
- elif i[0] == "image":
- try:
- loadw = int(i[1])
- except:
- loadw = imwidth
-
- image = ui.load(win, ui.net_image_calculation, ui.net_image_render, i[-1], loadw, "", True)
-
- def link_launch(w, link):
- os.system("xdg-open "+link)
- def link_resolve(w, link):
- win.url.set_text(link)
- win.url.activate()
- optionsthing = Gtk.Popover()
- optbox = Gtk.VBox()
- optionsthing.add(optbox)
- opt_link = Gtk.Entry()
- opt_link.set_editable(False)
- opt_link.set_text(i[-1])
- optbox.pack_start(opt_link, False, False, False)
- opt_open = Gtk.Button("Open")
- optbox.pack_start(opt_open, False, False, False)
- opt_launch = Gtk.Button("Launch")
- optbox.pack_start(opt_launch, False, False, False)
- opt_resolve = Gtk.Button("Resolve")
- optbox.pack_start(opt_resolve, False, False, False)
- opt_open.connect("clicked", link_launch, ui.image_save_name(i[-1]))
- opt_launch.connect("clicked", link_launch, i[-1])
- opt_resolve.connect("clicked", link_resolve, i[-1])
- optbox.show_all()
-
- link = Gtk.MenuButton(popover=optionsthing)
- link.set_relief(Gtk.ReliefStyle.NONE)
- link.add(image)
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- text_view.add_child_at_anchor(link, anchor)
- elif i[0] == "link":
-
-
-
- def link_launch(w, link):
- os.system("xdg-open "+link)
- def link_resolve(w, link):
- win.url.set_text(link)
- win.url.activate()
- optionsthing = Gtk.Popover()
- optbox = Gtk.VBox()
- optionsthing.add(optbox)
- opt_link = Gtk.Entry()
- opt_link.set_editable(False)
- opt_link.set_text(i[-1])
- optbox.pack_start(opt_link, False, False, False)
- opt_launch = Gtk.Button("Launch")
- optbox.pack_start(opt_launch, False, False, False)
- opt_resolve = Gtk.Button("Resolve")
- optbox.pack_start(opt_resolve, False, False, False)
- opt_launch.connect("clicked", link_launch, i[-1])
- opt_resolve.connect("clicked", link_resolve, i[-1])
- optbox.show_all()
- link = Gtk.MenuButton(label=i[1], popover=optionsthing)
-
- link.set_tooltip_text(i[-1])
- anchor = Gtk.TextChildAnchor()
- text_buffer.insert_child_anchor(en, anchor)
- text_view.add_child_at_anchor(link, anchor)
|