From 44cea7e84d7c67e820dc6d7b3152ab5007668f55 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Sat, 21 Jan 2023 15:30:13 -0500
Subject: linhes-system: add gen_lib_xml.py and plex_lib.conf to add Plex to
 frontend menu

---
 linhes/linhes-system/PKGBUILD           |  13 ++--
 linhes/linhes-system/gen_lib_xml.py     | 119 ++++++++++++++++++++++++++++++++
 linhes/linhes-system/lh_system_start.sh |   3 +-
 linhes/linhes-system/plex_lib.conf      |   9 +++
 4 files changed, 139 insertions(+), 5 deletions(-)
 create mode 100755 linhes/linhes-system/gen_lib_xml.py
 create mode 100644 linhes/linhes-system/plex_lib.conf

diff --git a/linhes/linhes-system/PKGBUILD b/linhes/linhes-system/PKGBUILD
index efa028f..8c5d6fd 100755
--- a/linhes/linhes-system/PKGBUILD
+++ b/linhes/linhes-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=linhes-system
 pkgver=9.0.0
-pkgrel=26
+pkgrel=27
 arch=('x86_64')
 #install=$pkgname.install
 pkgdesc="Everything that makes LinHES a system"
@@ -9,7 +9,7 @@ depends=('cronie' 'dbus-python' 'kdialog' 'libnotify' 'linhes-templates' 'linhes
          'openssh' 'ttf-overlock')
 binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remove_storage.py
           checkXFSfrag.sh enableIRWake.sh idle.py lh_system_start.sh lh_notify-send
-          lh_home_check.sh jobqueue_helper.py
+          lh_home_check.sh jobqueue_helper.py gen_lib_xml.py
           diskspace.sh find_orphans.py optimize_mythdb.py
           misc_recent_recordings.pl misc_status_config.py misc_status_info.sh
           misc_upcoming_recordings.pl misc_which_recorder.pl
@@ -18,7 +18,7 @@ binfiles="add_storage.py balance_storage_groups.py empty_storage_groups.py remov
 source=($binfiles
     'myth_mtc.cron' 'paccache.cron' 'xfs_defrag.cron'
     'readme_is_xml' 'add_storage.readme' 'LinHES-release'
-    '79-cronie.hook' 'fstrim.hook' 'openssh.hook'
+    '79-cronie.hook' 'fstrim.hook' 'openssh.hook' 'plex_lib.conf'
     '10-monitor.conf' 'x11vnc.override.conf' 'lh_lighttpd.conf' 'lh_php.ini'
     'system-sudo.rules' 'linhes-profile.sh' 'lh_sqlserver.cnf'
     'lh_system_start.sh.desktop' 'rc6_mce.toml')
@@ -29,10 +29,11 @@ sha256sums=('7f91d2afcb76e8e9063c6bbe05f5c3d134a6f67541aead8894d342c32d34ad98'
             '11168c9cd3b117decaab6bc665c183b4aab917cf0a976bce4c1b5e4686a27bc9'
             'ae34515e144830f424d3bd3f6b1b446892d62beed20bca6f0fb19b0bbb779f27'
             '23358a7bff4968eccd469613b81b1415c2ae0ebe77f14f74426697333e4d88d7'
-            '19535aaeeb3e0118bddd9c0efb6b974145ee99a4ed8dc33ea888da5eb28e57fd'
+            '393fbc46acc839e0a1ba69e968fed8bdea078d061235289d7ef1b30fece14047'
             '6d4fb0ed1a5ed961b3a3884dce093118e50c2981a9cd5837d20abc5a6d4fd8aa'
             '87875d9e5f5ce18208f419698ce69b6bcbcd08955a57a4a13940e715af58b787'
             '91bdec992bb2c933e15625c181f2195c402060b879168ebf35944cb064c904b9'
+            'e1e77ef14f1a0a29adf29206972ae5d6a13c9f87d41252a253486104895cb97c'
             'ebdb3ee0212e0cc72526bb5e50a032573e1894acb7bf75617243b0b49aa1f8f2'
             '4d006f0fe3b13e67de1b961d611e81911905a30d140849dfdb8e5c0dc4da2f7c'
             'e371c6a289c68fe200d7da856c20a8c579efa23178f4d62235f7359d7f6e49a1'
@@ -54,6 +55,7 @@ sha256sums=('7f91d2afcb76e8e9063c6bbe05f5c3d134a6f67541aead8894d342c32d34ad98'
             '0fbc05f521aea83157c5e6f8bd29a422873093bb6cded965cb7ffe98ff776fa4'
             '4c29e0b71071ae9556cf2dbd75de560d028577fe5eb993113105112c4b445eac'
             '890482242434e333024c7819e8bf3c889dc16548d0a1745479c8523930fb32f7'
+            '71c564a12d9a8e2814a2bf67a1a3d70c1e9d3b50bc108f7043ed8c958c067b01'
             'dead17906b33a7f9d66ad13bb1c083a23438f45ece9bd5ec41ff86eda01c132a'
             '2c9152ed542bb9c3aa516c6009125a757065100a060e0fa597243d4cbd92844f'
             '73aae13c47223c4ebb45c5cb2aff19a72b6b32cc0d9e7c83de9f97ada593b411'
@@ -96,6 +98,9 @@ package() {
     #lighttpd files
     install -Dm644 $srcdir/lh_lighttpd.conf $pkgdir/etc/lighttpd/conf.d/lh_lighttpd.conf
 
+    #gen_lib_xml.py files
+    install -Dm644 ${srcdir}/plex_lib.conf ${pkgdir}/etc/gen_lib_xml.d/plex_lib.conf
+
     #remote files
     install -Dm644 $srcdir/rc6_mce.toml $pkgdir/etc/rc_keymaps/rc6_mce.toml
 
diff --git a/linhes/linhes-system/gen_lib_xml.py b/linhes/linhes-system/gen_lib_xml.py
new file mode 100755
index 0000000..31dcdc2
--- /dev/null
+++ b/linhes/linhes-system/gen_lib_xml.py
@@ -0,0 +1,119 @@
+#! /usr/bin/python
+#Helper program that generates library.xml thats custom to linhes.
+#Contents are read from /etc/gen_lib_xml.d
+#This script should be run everytime an entry is added or removed
+
+
+import os, sys
+import glob
+
+class Gen_lib_xml:
+    def __init__(self,snippit_dir,orig_theme_file):
+        self.snippit_dir = snippit_dir
+        self.orig_theme_file =  orig_theme_file
+        self.xml_snippets=[]
+        self.orig_theme_xml=[]
+        self.new_xml=[]
+
+    def get_new_xml(self):
+        return self.new_xml
+    def get_orig_xml(self):
+        return self.orig_theme_xml
+    def get_snippits(self):
+        return self.xml_snippets
+
+    def read_snippets(self):
+        xml_snippets=""
+        lines=[]
+        try:
+            os.chdir(self.snippit_dir)
+        except:
+            print("    gen_lib_xml: Couldn't change dir to %s" %self.snippit_dir)
+            print("    Exiting")
+            sys.exit(0)
+        file_list=glob.glob("*.conf")
+        for conf_file in file_list:
+            try:
+                print("    gen_lib_xml: reading in %s" %conf_file)
+                f=open(conf_file,'r')
+                line=f.readlines()
+                f.close()
+            except:
+                print("    gen_lib_xml: Couldn't open %s for reading" %conf_file)
+                print("    Exiting")
+                sys.exit(0)
+            lines.extend(line)
+
+        if len(file_list) == 0:
+            print("    gen_lib_xml:  no conf files found")
+            lines = []
+        self.xml_snippets = lines
+
+    def read_orig_xml(self):
+        try:
+            print("    gen_lib_xml:  reading in %s" %self.orig_theme_file)
+            f=open(self.orig_theme_file,'r')
+            lines=f.readlines()
+            f.close()
+
+        except:
+            print("    gen_lib_xml: Couldn't open %s for reading" %self.orig_theme_file)
+            print("    Exiting")
+            sys.exit(2)
+        #print lines
+        for i in lines:
+            if i.strip() == "</mythmenu>":
+                lines.remove(i)
+                print("    gen_lib_xml:  Removing /mythmenu tag ")
+                break
+        self.orig_theme_xml=lines
+
+    def make_new_xml(self):
+        self.new_xml = self.orig_theme_xml + self.xml_snippets
+        self.new_xml.append("</mythmenu>\n")
+        pass
+
+
+
+
+
+
+
+
+def write_xml(xml,filename):
+    try:
+        f=open(filename, 'w')
+    except:
+        print("    gen_lib_xml: Couldn't open %s" %(filename))
+        print("    Exiting")
+        sys.exit(2)
+    print("    gen_lib_xml:  Writing %s" %(filename))
+    for i in xml:
+        f.write(i)
+    f.close()
+
+def main():
+    sys.path.append('/usr/MythVantage/bin/')
+    config_file = "mv_config"
+    data_config = __import__(config_file,  globals(),  locals(),  [])
+
+    filename="%s/.mythtv/library.xml" %data_config.MYTHHOME
+    #filename="/tmp/library.xml"
+    orig_theme_file="/usr/share/mythtv/themes/defaultmenu/library.xml"
+    lib_xml_dir="/etc/gen_lib_xml.d/"
+
+    lib_xml = Gen_lib_xml(lib_xml_dir,orig_theme_file)
+    lib_xml.read_snippets()
+    lib_xml.read_orig_xml()
+    lib_xml.make_new_xml()
+    lib_xml.make_new_xml()
+    new_xml = lib_xml.get_new_xml()
+
+    #a = lib_xml.get_new_xml()
+    #b = lib_xml.get_orig_xml()
+    #c = lib_xml.get_snippits()
+
+    write_xml(new_xml,filename)
+
+if __name__ == "__main__":
+    main()
diff --git a/linhes/linhes-system/lh_system_start.sh b/linhes/linhes-system/lh_system_start.sh
index b993be8..b6133ee 100755
--- a/linhes/linhes-system/lh_system_start.sh
+++ b/linhes/linhes-system/lh_system_start.sh
@@ -69,7 +69,8 @@ function install_lh_apps(){
     sudo pacman -Syyy --noconfirm flatpak firefox glances mythtv mythplugins-mytharchive mythplugins-mythmusic mythplugins-mythweb ncdu x11vnc
     status=$?
     [ $status -eq 1 ] && msg "Could not install apps. Check internet connection. Cancelling Setup." && exit 1
-    flatpak install tv.plex.PlexHTPC
+    flatpak install tv.plex.PlexHTPC --noninteractive --assumeyes
+    gen_lib_xml.py
 }
 
 function sql_setup(){
diff --git a/linhes/linhes-system/plex_lib.conf b/linhes/linhes-system/plex_lib.conf
new file mode 100644
index 0000000..df4b3f3
--- /dev/null
+++ b/linhes/linhes-system/plex_lib.conf
@@ -0,0 +1,9 @@
+<!--#PLEX-->
+    <button>
+       <type>MENU_PLEX</type>
+       <text>Launch Plex</text>
+       <description>Open Plex Home Theater</description>
+       <action>EXEC /var/lib/flatpak/exports/bin/tv.plex.PlexHTPC</action>
+    </button>
+<!--#PLEX--> 
+
-- 
cgit v0.12

