follow.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 ui
  42. from flbry import fetch
  43. ###################################################################
  44. # This file deals with one thing. A little swich of whther you are
  45. # following a channel or not.
  46. ###################################################################
  47. def button(win, name):
  48. # This is a button for following channels:
  49. vbox = Gtk.VBox()
  50. hbox = Gtk.HBox()
  51. vbox.pack_start(hbox, False, False, 0)
  52. hbox.pack_start(ui.icon(win, "emblem-favorite"), False, False, 0)
  53. hbox.pack_start(Gtk.Label(" Follow: "), False, False, 0)
  54. switch = Gtk.Switch()
  55. hbox.pack_start(switch, False, False, 0)
  56. if name in win.subs:
  57. switch.set_active(True)
  58. def on_follow(w, e):
  59. if switch.get_active():
  60. if name not in win.subs:
  61. win.subs.append(name)
  62. else:
  63. if name in win.subs:
  64. win.subs.remove(name)
  65. save(win)
  66. switch.connect("notify::active", on_follow)
  67. return vbox
  68. def save(win):
  69. # Saving the state of following
  70. out = fetch.lbrynet("preference_get")
  71. out["shared"]["value"]["subscriptions"] = win.subs
  72. fetch.lbrynet("preference_set", {"key":"shared", "value":out["shared"]})