]> git.leonardobizzoni.com Git - holonotify/commitdiff
initial windows support
authorLeonardoBizzoni <leo2002714@gmail.com>
Thu, 11 Nov 2021 12:53:03 +0000 (13:53 +0100)
committerLeonardoBizzoni <leo2002714@gmail.com>
Thu, 11 Nov 2021 12:53:03 +0000 (13:53 +0100)
holonotify.py
utils.py

index cfb6dd6f0fa369c984b1e80074cfd16281b090a7..dd8590db0075ec65a43acfdcebd66edbabfaf3cd 100755 (executable)
@@ -1,9 +1,8 @@
 #!/usr/bin/env python
 
 import os
-import threading
 import time
-import psutil
+import platform
 
 import urllib.request
 import json
@@ -14,6 +13,9 @@ liveAnnouced = list()
 live = list()
 ended = list()
 blacklist = list()
+running = True
+checkedPs = False
+psCount = 0
 
 def updateValues():
     global live, ended, blacklist
@@ -30,41 +32,55 @@ def main():
         notBlacklist = True
         chName = ch["channel"]["name"].lower()
 
+        # check if the vtuber is in the blacklist
         for name in blacklist:
             if (name in chName):
                 notBlacklist = False
                 break
-        
+        # check if the live has already been announces and its not blacklisted
         if(chName not in liveAnnouced and notBlacklist):
             chIcon = utils.getIcon(chName)
-            os.system(f'''notify-send -i {chIcon} "{chName} is live!" "{ch["title"]}"''')
-            liveAnnouced.append(chName)
 
+            if(platform.system() == "Windows"):
+                from plyer import notification
+                notification.notify(title=chName + " is live!", message=ch["title"])
+            else:
+                os.system(f'''notify-send -i {chIcon} "{chName} is live!" "{ch["title"]}"''')
+
+            liveAnnouced.append(chName)
+        # check if the live has ended and remove it from the live already announced
         if(ch["yt_video_key"] in ended):
             liveAnnouced.remove(ch["channel"]["name"])
 
-if __name__ == "__main__":
-    running = True
-    checkedPs = False
-    psCount = 0
+def linuxCheckProc():
+    global checkedPs, psCount, running
 
+    if checkedPs == False and platform.system() == "Linux":
+        import psutil
+        for pid in psutil.pids():
+            try:
+                p = psutil.Process(pid)
+                if p.name() == "python":
+                    if psCount >= 1:
+                        running = False
+                        break
+                    if "holonotify" in p.cmdline()[1]:
+                        psCount +=  1
+            except:
+                continue
+        checkedPs = True
+
+def windowsCheckProc():
+    # TODO
+    pass
+
+if __name__ == "__main__":
     while running:
         main()
 
         # If there's another instance running, show who's live and quit
-        if checkedPs == False:
-            for pid in psutil.pids():
-                    try:
-                        p = psutil.Process(pid)
-                        if p.name() == "python":
-                            if psCount >= 1:
-                                running = False
-                                break
-                            if "holonotify" in p.cmdline()[1]:
-                                psCount +=  1
-                    except:
-                        continue
-            checkedPs = True
-
+        linuxCheckProc()
+        windowsCheckProc()
+        
         if running:
             time.sleep(60*5)
index e76621b177992744789daf9900eea9837b4084f1..c61ead15f95d62092e21d1a9dd19c4f2764e12f6 100644 (file)
--- a/utils.py
+++ b/utils.py
@@ -1,7 +1,9 @@
 import os
+import platform
 
 def getBlacklist():
     blacklist = list()
+    # TODO: path to blacklist on windows
     blacklistFile = os.path.expanduser("~") + "/.config/holoBlacklist"
 
     if (os.path.isfile(blacklistFile)):
@@ -9,17 +11,17 @@ def getBlacklist():
             for x in f.read().splitlines():
                 if(x == "fubuki" or x == "shirakami"):
                     blacklist.append("フブキ")
-                elif(x == "mel"):
-                    blacklist.append("夜空メルチャンネル")
                 elif (x == "akirose" or x == "aki" or x == "rosenthal"):
                     blacklist.append("アキロゼ")
                 else:
                     blacklist.append(x)
-
     return blacklist
 
 def getIcon(name):
-    abspath = os.path.dirname(os.path.abspath(__file__)) + "/Icons/"
+    if(platform.system() == "Windows"):
+        abspath = os.path.dirname(os.path.abspath(__file__)) + "\\Icons\\"
+    else:
+        abspath = os.path.dirname(os.path.abspath(__file__)) + "/Icons/"
 
     # JP
     if ("フブキ" in name):
@@ -85,7 +87,7 @@ def getIcon(name):
     elif ("botan" in name):
         return abspath + "botan.jpg"
 
-    # JP col cazzo
+    # JP males
     elif ("shien" in name):
         return abspath + "shien.jpg"
     elif ("oga" in name):
@@ -120,7 +122,7 @@ def getIcon(name):
         return abspath + "amelia.jpg"
     elif ("irys" in name):
         return abspath + "irys.jpg"
-    elif ("sana" in name):
+    elif ("tsukumoto" in name):
         return abspath + "sana.jpg"
     elif ("fauna" in name):
         return abspath + "fauna.jpg"