publish.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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 json
  32. import random
  33. import threading
  34. import mimetypes
  35. import urllib.request
  36. from gi.repository import Gtk
  37. from gi.repository import Gdk
  38. from gi.repository import GLib
  39. from gi.repository import Pango
  40. from gi.repository import GdkPixbuf
  41. from flbry import markdown
  42. from flbry import ui
  43. from flbry import fetch
  44. from flbry import settings
  45. ##################################################################
  46. # This file touches publication to LBRY network. #
  47. ##################################################################
  48. def lbryname(name="", force=True):
  49. # This creates a random string of characters.
  50. good = "qwertyuiopasdfghjklzxcvbnm-_QWERTYUIOPASDFGHJKLZXCVBNM1234567890"
  51. if not name and force:
  52. for i in range(70):
  53. name = name + random.choice(good)
  54. return name
  55. # This removes all non-good characters from the name
  56. new_name = ""
  57. for i in name:
  58. if i in good:
  59. new_name = new_name + i
  60. else:
  61. new_name = new_name + "_"
  62. return new_name
  63. DEFAULT_DATA = {"name":"",
  64. "bid":0.001,
  65. "file_path":"",
  66. "title":"",
  67. "license":"",
  68. "license_url":"",
  69. "thumbnail_url":"",
  70. "channel_id":"",
  71. "channel_name":"",
  72. "description":"",
  73. "fee_amount":0,
  74. "tags":[]
  75. }
  76. LICENSES = [
  77. # NAME , URL , COMMENT
  78. ["GNU General Public License Version 3 (or later)",
  79. "https://www.gnu.org/licenses/gpl-3.0.html",
  80. "Strong Copyleft. Recommended for Software."],
  81. ["GNU General Public License Version 3 (only)",
  82. "https://www.gnu.org/licenses/gpl-3.0.html",
  83. "Strong Copyleft."],
  84. ["GNU Free Documentation License",
  85. "https://www.gnu.org/licenses/fdl-1.3.html",
  86. "Strong Copyleft. Recommended for books."],
  87. ["Creative Commons Attribution-ShareAlike 4.0 International",
  88. "https://creativecommons.org/licenses/by-sa/4.0/",
  89. "Copylefted, Recommended for Art."],
  90. ["Creative Commons Attribution 4.0 International",
  91. "https://creativecommons.org/licenses/by/4.0/",
  92. "Non Copylefted, Free License."],
  93. ["Creative Commons Zero 1.0 International",
  94. "https://creativecommons.org/publicdomain/zero/1.0/",
  95. "Public Domain"],
  96. ["Creative Commons Attribution-NoDerivatives 4.0 International",
  97. "https://creativecommons.org/licenses/by-nd/4.0/",
  98. "Does not allow changes. Recommended for opinion pieces."]
  99. ]
  100. def window(win, data=DEFAULT_DATA):
  101. # First, the data recieved could be not full.
  102. for i in DEFAULT_DATA:
  103. if i not in data:
  104. data[i] = DEFAULT_DATA[i]
  105. # Upload window
  106. dialogWindow = Gtk.Dialog("Publish",
  107. buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
  108. Gtk.STOCK_OK, Gtk.ResponseType.OK),
  109. )
  110. box = dialogWindow.get_content_area()
  111. #######################################################################
  112. # #
  113. # PRESETS #
  114. # #
  115. #######################################################################
  116. presets_list = []
  117. for i in os.listdir(settings.get_settings_folder()+"presets"):
  118. if i.endswith(".json"):
  119. presets_list.append(i.replace(".json", ""))
  120. def on_set_preset(w):
  121. # This might be a little long one, but to hell with it.
  122. ######################################################
  123. pn = presets_list[presets.get_active()]
  124. # Opening the preset's json.
  125. with open(settings.get_settings_folder()+"presets/"+pn+'.json') as f:
  126. pdata = json.load(f)
  127. # The data should be very similar. It was saved ( hopefully ) from
  128. # the same data as what we use to publish.
  129. exclude = ["name", "file_path", "tags"]
  130. for d in pdata:
  131. if d in exclude:
  132. continue
  133. data[d] = pdata[d]
  134. # Now let's update the UI itself
  135. # THIS SHOULD NOT RUN BEFORE THE UI IS FULLY LOADED !!!
  136. # BID
  137. bid_entry.set_value(data["bid"])
  138. # TITLE
  139. title.set_text(data["title"])
  140. # LICENSE
  141. for n, ch in enumerate(LICENSES):
  142. if data["license"] == ch[0]:
  143. licenses.set_active(n)
  144. # THUMBNAIL_URL
  145. thumbentry.set_text(data["thumbnail_url"])
  146. refresh_thumb()
  147. # CHANNEL_NAME
  148. try:
  149. for n, ch in enumerate(win.my_channels["items"]):
  150. if data["channel_name"] == ch["name"] or \
  151. data["channel_id"] == ch["claim_id"]:
  152. select = n+1
  153. channels_select.set_active(select)
  154. except:
  155. pass
  156. # DESCRIPTION
  157. detext.get_buffer().set_text(data["description"])
  158. # FEE_AMOUNT
  159. price_entry.set_value(data["fee_amount"])
  160. # TAGS
  161. # Tags ( because of the tags editor ) is a special case
  162. # and we need to do this, so not to create a separate id()
  163. # for the tags list. ( Tags editor is a separate function
  164. # that accesses the same list and edit's it.
  165. # First we need to remove all of the data.
  166. tags = data["tags"].copy()
  167. for t in tags:
  168. data["tags"].remove(t)
  169. # And now we want to add all of the tags one by one.
  170. for t in pdata["tags"]:
  171. data["tags"].append(t)
  172. # And finally we want to give commands obtained from the tags
  173. # object to update it visually.
  174. for i in tagsbox.get_children():
  175. i.destroy()
  176. for tag in data["tags"]:
  177. add_tag(tag)
  178. presbox = Gtk.HBox()
  179. box.pack_start(presbox, False, False, 0)
  180. presbox.pack_start(Gtk.Label(" Presets: "), False, False, 0)
  181. presets = Gtk.ComboBoxText()
  182. presets.connect("changed", on_set_preset)
  183. for n, ch in enumerate(presets_list):
  184. presets.append_text(ch)
  185. presbox.pack_start(presets, True, True, 0)
  186. #####################################################################
  187. presetsave = Gtk.Popover()
  188. addb = Gtk.MenuButton(popover=presetsave)
  189. addb.set_relief(Gtk.ReliefStyle.NONE)
  190. addb.add(ui.icon(win, "list-add"))
  191. presbox.pack_start(addb, False, False, 0)
  192. psavebox = Gtk.VBox()
  193. presetsave.add(psavebox)
  194. pname = Gtk.Entry()
  195. pname.set_text("name")
  196. psavebox.pack_start(pname, False, False, False)
  197. def save_preset(w):
  198. update_data() # Making sure all data is in 'data'
  199. pn = pname.get_text()
  200. # Write the json file
  201. with open(settings.get_settings_folder()+"presets/"+pn+'.json', 'w') as f:
  202. json.dump(data, f, indent=4, sort_keys=True)
  203. # Add the preset into presets
  204. if pn not in presets_list:
  205. presets.append_text(pn)
  206. presets_list.append(pn)
  207. # Select the current preset
  208. for n, ch in enumerate(presets_list):
  209. if ch == pn:
  210. presets.set_active(n)
  211. presets.grab_focus() # Closing the menu
  212. pname.set_text("name")
  213. psave = Gtk.Button("Save")
  214. psave.connect("clicked", save_preset)
  215. pname.connect("activate", save_preset)
  216. psave.set_relief(Gtk.ReliefStyle.NONE)
  217. psavebox.pack_start(psave, False, False, False)
  218. psavebox.show_all()
  219. #######################################################################
  220. # #
  221. # LBRY URL PART #
  222. # #
  223. #######################################################################
  224. box.pack_start(Gtk.Label(" Channel | LBRY url "), False, True, 5)
  225. urlbox = Gtk.HBox()
  226. box.pack_start(urlbox, False, False, 0)
  227. urlbox.pack_start(Gtk.Label(" lbry:// "), False, False, 0)
  228. # This will work separately from the main channel selector, though it
  229. # will be influenced by the main channel selector a bit.
  230. def on_channel_changed(w):
  231. ch = channels_select.get_active() - 1
  232. if ch == -1:
  233. data["channel_name"] = ""
  234. data["channel_id"] = ""
  235. else:
  236. data["channel_name"] = win.my_channels["items"][ch]["name"]
  237. data["channel_id"] = win.my_channels["items"][ch]["claim_id"]
  238. channels_select = Gtk.ComboBoxText()
  239. channels_select.connect("changed", on_channel_changed)
  240. # Let's get a list of channels to show
  241. channels = ["[anonymous]"]
  242. select = 0
  243. try: # could be no channel. So publication only anonymous
  244. for n, ch in enumerate(win.my_channels["items"]):
  245. channels.append(ch["name"]+":"+ch["claim_id"][0])
  246. if data["channel_name"] == ch["name"] or \
  247. data["channel_id"] == ch["claim_id"] or \
  248. win.channel["claim_id"] == ch["claim_id"]:
  249. select = n+1
  250. except Exception as e:
  251. print("DAMN!", e)
  252. for ch in channels:
  253. channels_select.append_text(ch)
  254. channels_select.set_active(select)
  255. urlbox.pack_start(channels_select, False, False, 0)
  256. urlbox.pack_start(Gtk.Label(" / "), False, False, 0)
  257. def on_url(w):
  258. url_field.set_text(lbryname(url_field.get_text(), force=False))
  259. url_field = Gtk.Entry()
  260. url_field.connect("changed", on_url)
  261. url_field.set_text(data["name"])
  262. urlbox.pack_start(url_field, True, True, 0)
  263. #######################################################################
  264. # #
  265. # THUMBNAIL #
  266. # #
  267. #######################################################################
  268. box.pack_start(Gtk.HSeparator(), False, False, 5)
  269. thumb_file_box = Gtk.HBox()
  270. box.pack_start(thumb_file_box, False, False, 0)
  271. ######################################################################
  272. thumbvbox = Gtk.VBox()
  273. thumb_file_box.pack_start(thumbvbox, False, False, 0)
  274. def refresh_thumb():
  275. if thumbentry.get_text():
  276. t = ui.load(win, ui.net_image_calculation, ui.net_image_render, thumbentry.get_text(), 300, "FORCELOAD", True)
  277. for ch in thumbbox.get_children():
  278. ch.destroy()
  279. thumbbox.pack_start(t, True, True, 0)
  280. thumbbox.show_all()
  281. def on_thumb(w):
  282. ans = ui.select_file(data["thumbnail_url"], filter=["*jpg", "*png", "*webp", "*gif"])
  283. if ans:
  284. thumbentry.set_text(ans)
  285. refresh_thumb()
  286. thumb = Gtk.Button()
  287. thumb.connect("clicked", on_thumb)
  288. thumb.set_size_request(300,300)
  289. thumb.set_relief(Gtk.ReliefStyle.NONE)
  290. thumbbox = Gtk.HBox()
  291. thumbbox.pack_start(ui.icon(win, "image-x-generic"), False, True, 0)
  292. thumbbox.pack_start(Gtk.Label(" Thumbnail "), False, True, 0)
  293. thumb.add(thumbbox)
  294. thumbvbox.pack_start(thumb, False, False, 0)
  295. def on_toggle(w):
  296. thumbentry.set_visible(w.get_active())
  297. thumb.set_visible(not w.get_active())
  298. refresh_thumb()
  299. manually = Gtk.ToggleButton("Set thumbnail manually")
  300. manually.connect("clicked", on_toggle)
  301. manually.set_relief(Gtk.ReliefStyle.NONE)
  302. thumbvbox.pack_end(manually, False, False, 0)
  303. thumbentry = Gtk.Entry()
  304. thumbentry.set_text(data["thumbnail_url"])
  305. refresh_thumb()
  306. thumbvbox.pack_end(thumbentry, False, False, 0)
  307. thumb_file_box.pack_start(Gtk.VSeparator(), False, False, 5)
  308. #######################################################################
  309. # #
  310. # TITLE #
  311. # #
  312. #######################################################################
  313. filebox = Gtk.VBox()
  314. thumb_file_box.pack_start(filebox, True, True, 0)
  315. #######################################################################
  316. titlebox = Gtk.HBox()
  317. filebox.pack_start(titlebox, False, False, 5)
  318. titlebox.pack_start(Gtk.Label(" Title: "), False, False, False)
  319. def on_title(w):
  320. data["title"] = title.get_text()
  321. title = Gtk.Entry()
  322. title.set_text(data["title"])
  323. title.connect("changed", on_title)
  324. titlebox.pack_start(title, True, True, False)
  325. #######################################################################
  326. # #
  327. # FILE #
  328. # #
  329. #######################################################################
  330. def choose_file(filename=""):
  331. for ch in filebbox.get_children():
  332. ch.destroy()
  333. if filename:
  334. icon_is = mimetypes.guess_type(filename)[0].replace("/", "-")
  335. name_of_file = filename[filename.rfind("/")+1:]
  336. def clear_name(name):
  337. name = name[:name.rfind(".")]
  338. name = name.replace("_", " ")
  339. try:
  340. name = name[0].upper()+name[1:]
  341. except:
  342. pass
  343. return name
  344. ofilename = data["file_path"]
  345. if not title.get_text() or clear_name(ofilename[ofilename.rfind("/")+1:]) == title.get_text():
  346. title.set_text(clear_name(name_of_file))
  347. data["title"] = clear_name(name_of_file)
  348. if not url_field.get_text() or lbryname(clear_name(ofilename[ofilename.rfind("/")+1:])) == url_field.get_text():
  349. url_field.set_text(lbryname(title.get_text(), force=True))
  350. else:
  351. icon_is = "document-open"
  352. name_of_file = "Choose File"
  353. filebbox.pack_start(ui.icon(win, icon_is), False, True, 0)
  354. filebbox.pack_start(Gtk.Label(" "+name_of_file+" "), False, True, 0)
  355. filebbox.show_all()
  356. def on_filebutton(w):
  357. name = ui.select_file(data["file_path"])
  358. choose_file(name)
  359. data["file_path"] = name
  360. filebutton = Gtk.Button()
  361. filebutton.connect("clicked", on_filebutton)
  362. filebbox = Gtk.HBox()
  363. filebutton.add(filebbox)
  364. choose_file(data["file_path"])
  365. filebutton.set_relief(Gtk.ReliefStyle.NONE)
  366. filebox.pack_start(filebutton, False, False, 0)
  367. box.pack_start(Gtk.HSeparator(), False, False, 5)
  368. #######################################################################
  369. # #
  370. # BID #
  371. # #
  372. #######################################################################
  373. bid_adjust = Gtk.Adjustment(data["bid"],
  374. lower=0.0001,
  375. upper=1000000000,
  376. step_increment=0.1)
  377. bid_entry = Gtk.SpinButton(adjustment=bid_adjust,
  378. digits=4)
  379. bid_box = Gtk.HBox()
  380. filebox.pack_start(bid_box, False, False, 5)
  381. bid_box.pack_start(Gtk.Label(" Bid: "), False, False, 0)
  382. bid_box.pack_end(bid_entry, False, False, 0)
  383. #######################################################################
  384. # #
  385. # PRICE #
  386. # #
  387. #######################################################################
  388. price_adjust = Gtk.Adjustment(data["fee_amount"],
  389. lower=0,
  390. upper=1000000000,
  391. step_increment=0.1)
  392. price_entry = Gtk.SpinButton(adjustment=price_adjust,
  393. digits=4)
  394. price_box = Gtk.HBox()
  395. filebox.pack_start(price_box, False, False, 5)
  396. price_box.pack_start(Gtk.Label(" Price: "), False, False, 0)
  397. price_box.pack_end(price_entry, False, False, 0)
  398. #######################################################################
  399. # #
  400. # DESCRIPTION #
  401. # #
  402. #######################################################################
  403. filebox.pack_start(Gtk.Label(" Description: "), False, True, 5)
  404. descrl = Gtk.ScrolledWindow()
  405. detext = Gtk.TextView()
  406. detext.set_wrap_mode(Gtk.WrapMode.WORD)
  407. detext.get_buffer().set_text(data["description"])
  408. descrl.add(detext)
  409. filebox.pack_start(descrl, True, True, 0)
  410. #######################################################################
  411. # #
  412. # TAGS #
  413. # #
  414. #######################################################################
  415. box.pack_start(Gtk.Label(" Tags "), False, True, 5)
  416. tags_editor, tagsbox, add_tag = ui.tags_editor(win, data["tags"], return_edit_functions=True)
  417. box.pack_start(tags_editor, False, False, 0)
  418. #######################################################################
  419. # #
  420. # LICENSE #
  421. # #
  422. #######################################################################
  423. box.pack_start(Gtk.Label(" License "), False, True, 5)
  424. def on_license(w):
  425. l = licenses.get_active()
  426. data["license"] = LICENSES[l][0]
  427. data["license_url"] = LICENSES[l][1]
  428. licenses = Gtk.ComboBoxText()
  429. licenses.connect("changed", on_license)
  430. for n, ch in enumerate(LICENSES):
  431. licenses.append_text(ch[0])
  432. if data["license"] == ch[0]:
  433. licenses.set_active(n)
  434. box.pack_start(licenses, False, True, 0)
  435. #######################################################################
  436. # #
  437. # RUNING THE SETTINGS DIALOG #
  438. # #
  439. #######################################################################
  440. box.show_all()
  441. def update_data():
  442. # Not all widgets update data automatically. We need this function
  443. # whenever we want the up-to-date data.
  444. data["name"] = url_field.get_text()
  445. data["thumbnail_url"] = thumbentry.get_text()
  446. data["bid"] = bid_entry.get_value()
  447. data["fee_amount"] = price_entry.get_value()
  448. tb = detext.get_buffer()
  449. data["description"] = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True)
  450. # Hide all hidden
  451. thumbentry.set_visible(False)
  452. response = dialogWindow.run()
  453. if response == Gtk.ResponseType.OK:
  454. update_data()
  455. print("\n\n############## PUBLISH INPUT ###########\n\n{")
  456. for i in data:
  457. print(' "'+i+'" :', data[i])
  458. print("}\n")
  459. out = upload(data)
  460. print("\n\n############## PUBLISH OUTPUT ###########\n\n")
  461. print(out)
  462. try:
  463. ui.notify(win, "Published successfully to: ", out['outputs'][0]['permanent_url']+"\n\nConfirming...")
  464. except:
  465. try:
  466. ui.notify(win, "Error while publishing!!!", out["message"])
  467. except:
  468. ui.notify(win, "Error while publishing!!!", str(out))
  469. # It has to be DESTORYED
  470. dialogWindow.destroy()
  471. def upload(data):
  472. ###############################################################
  473. # PUBLISH ! PUBLISH ! PUBLISH ! PUBLISH ! PUBLISH ! PUBLISH ! #
  474. ###############################################################
  475. # The required datapoints
  476. fetch_data = {"name":data["name"],
  477. "bid":str(float(data["bid"])),
  478. "file_path":data["file_path"]}
  479. # Uploading the thumbnail maybe
  480. data["thumbnail_url"] = speech_upload(data["thumbnail_url"])
  481. for i in ["title", "license", "license_url", "thumbnail_url", "description", "channel_name", "fee_amount", "tags"]:
  482. if i in data:
  483. if data[i]:
  484. if type(data[i]) not in [float, int]:
  485. fetch_data[i] = data[i]
  486. else:
  487. fetch_data[i] = str(float(data[i]))
  488. if data["fee_amount"]:
  489. fetch_data["fee_currency"] = "LBC"
  490. out = fetch.lbrynet("publish", fetch_data)
  491. return out
  492. def speech_upload(file, name="", fee=0, speech=True):
  493. file = os.path.expanduser(file)
  494. if os.path.isfile(file):
  495. print("Uploading '"+file+"' to LBRY")
  496. if not name:
  497. rndname = ""
  498. else:
  499. rndname = name + "_"
  500. length = 70 - len(rndname)
  501. good = "qwertyuiopasdfghjklzxcvbnm-_QWERTYUIOPASDFGHJKLZXCVBNM1234567890"
  502. for i in range(length):
  503. rndname = rndname + random.choice(good)
  504. try:
  505. out = upload({"name":rndname,
  506. "bid":0.001,
  507. "file_path":file,
  508. "title":"",
  509. "license":"",
  510. "license_url":"",
  511. "thumbnail_url":"",
  512. "channel_id":"",
  513. "channel_name":"",
  514. "description":"",
  515. "fee_amount":fee,
  516. "tags":[]
  517. })
  518. if speech:
  519. return out['outputs'][0]['permanent_url'].replace("lbry://","https://spee.ch/")
  520. else:
  521. return out['outputs'][0]['permanent_url']
  522. except:
  523. return ""
  524. else:
  525. return file