base_java_loader.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : base_java_loader.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Author's Blog: https://blog.csdn.net/qq_32394351
  6. # Date : 2024/1/11
  7. import os
  8. import sys
  9. sys.path.append('..')
  10. try:
  11. # from base.spider import Spider as BaseSpider
  12. from base.spider import BaseSpider
  13. from com.github.tvbox.osc.util import PyUtil
  14. from java import jbyte, jarray
  15. # https://chaquo.com/chaquopy/doc/current/python.html#java.jbyte
  16. except ImportError:
  17. from t4.base.spider import BaseSpider
  18. # 全局变量
  19. gParam = {
  20. # JVM已经启用过某个jar文件
  21. "JVM": {'xx.jar': False},
  22. }
  23. class Spider(BaseSpider): # 元类 默认的元类 type
  24. jar_path: str = ''
  25. jClass = None
  26. def _prepare_env(self, jpype):
  27. global gParam
  28. if gParam['JVM'].get(self.jar_path):
  29. return
  30. try:
  31. jpype.startJVM(classpath=[self.jar_path], convertStrings=False)
  32. gParam['JVM'][self.jar_path] = True
  33. except Exception as e:
  34. self.log(f'jpype.startJVM发生了错误:{e}')
  35. def init_jar(self, jar_path="./bdys.jar"):
  36. self.log(f'base_java_loader 初始化jar文件:{jar_path}')
  37. if not os.path.exists(jar_path):
  38. raise FileNotFoundError
  39. self.jar_path = jar_path
  40. if self.ENV.lower() == 't4':
  41. import jpype
  42. self._prepare_env(jpype)
  43. self.jClass = jpype.JClass
  44. elif self.ENV.lower() == 't3':
  45. PyUtil.load(jar_path)
  46. self.jClass = None
  47. def call_java(self, class_name, method_name, *args):
  48. if self.ENV.lower() == 't4':
  49. class1 = self.jClass(class_name)
  50. method = getattr(class1, method_name)
  51. # method = eval(f'class1.{method_name}', {'class1': class1})
  52. # print(method)
  53. return method(*args)
  54. elif self.ENV.lower() == 't3':
  55. return PyUtil.call(class_name, method_name, *args)
  56. @staticmethod
  57. def jarBytes(some_bytes: bytes):
  58. return jarray(jbyte)(some_bytes)
  59. def init(self, extend=""):
  60. pass
  61. def homeContent(self, filter):
  62. pass
  63. def homeVideoContent(self):
  64. pass
  65. def categoryContent(self, tid, pg, filter, extend):
  66. pass
  67. def detailContent(self, ids):
  68. pass
  69. def searchContent(self, key, quick, pg=1):
  70. pass
  71. def playerContent(self, flag, id, vipFlags):
  72. pass
  73. def localProxy(self, param):
  74. pass
  75. def isVideoFormat(self, url):
  76. pass
  77. def manualVideoCheck(self):
  78. pass
  79. def getName(self):
  80. pass