main.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # -*- coding: utf-8 -*-
  2. import xbmc, xbmcgui, xbmcaddon, xbmcplugin
  3. import sys
  4. if sys.version_info.major > 2: # Python 3
  5. from urllib.parse import urlencode, parse_qsl
  6. else: # Python 2
  7. from urllib import urlencode
  8. from urlparse import parse_qsl
  9. try:
  10. import simplejson as json
  11. except ImportError:
  12. import json
  13. from anime365 import PyAnime365
  14. BaseURL = sys.argv[0]
  15. AddonHandle = int(sys.argv[1])
  16. Addon = xbmcaddon.Addon("plugin.video.anime365")
  17. xbmcplugin.setContent(AddonHandle, "videos")
  18. def BuildURLDirection(**kwargs):
  19. return "{0}?{1}".format(BaseURL, urlencode(kwargs))
  20. def Message(title, message):
  21. xbmcgui.Dialog().ok(str(title), str(message))
  22. Anime365 = PyAnime365(Addon.getSetting("sa-login"), Addon.getSetting("sa-paswd"), "sub" if Addon.getSetting("local-type") == "Subtitles" else "voice")
  23. if not Anime365.SessionStatus:
  24. Message("Account", "Invalid E-Mail or Password")
  25. def AddFolder(label, action, **kwargs):
  26. Item = xbmcgui.ListItem(label)
  27. ItemURL = BuildURLDirection(label = label, action = action, **kwargs)
  28. if "icon" in kwargs:
  29. Item.setArt({"poster": kwargs["icon"], "banner": kwargs["icon"], "icon": kwargs["icon"]})
  30. if "animeData" in kwargs:
  31. Anime = kwargs["animeData"]
  32. Item.setArt({"poster": Anime["poster"], "banner": Anime["poster"], "icon": Anime["poster"]})
  33. Item.setInfo("video", {"title": label, "plot": Anime["description"]})
  34. xbmcplugin.addDirectoryItem(handle = AddonHandle, url = ItemURL, listitem = Item, isFolder = True)
  35. def PlayVideo(videoTitle, videoPath, subPath):
  36. Item = xbmcgui.ListItem(videoTitle, path = videoPath)
  37. Item.setProperty("IsPlayable", "true")
  38. if subPath:
  39. Item.setSubtitles([subPath])
  40. xbmc.Player().showSubtitles(True)
  41. xbmc.Player().play(item = videoPath, listitem = Item)
  42. def AnimeSearch():
  43. kb = xbmc.Keyboard()
  44. kb.setDefault("")
  45. kb.setHeading("Поиск")
  46. kb.doModal()
  47. if kb.isConfirmed():
  48. AnimeList = Anime365.GetAnimeListByQuery(kb.getText())
  49. for Anime in AnimeList:
  50. AddFolder(Anime["russian"].encode("utf-8"), "anime_title", animeData = Anime)
  51. xbmcplugin.endOfDirectory(AddonHandle)
  52. def LocalTeamList(animeID):
  53. TranslationList = Anime365.GetTranslationListByID(animeID)
  54. for Translation in TranslationList:
  55. if len(Translation["translation"]) == 1:
  56. AddFolder(Translation["author"].encode("utf-8"), "anime_episode", playerData = Anime365.ExtractVideoData(Translation["translation"][0]["episodeURL"]))
  57. continue
  58. AddFolder(Translation["author"].encode("utf-8"), "anime_transaltion", episodes = Translation["translation"])
  59. xbmcplugin.endOfDirectory(AddonHandle)
  60. def EpisodeList(episodes):
  61. for Episode in episodes:
  62. AddFolder("Серия {0}".format(Episode["episode"]), "anime_episode", playerData = Anime365.ExtractVideoData(Episode["episodeURL"]))
  63. xbmcplugin.endOfDirectory(AddonHandle)
  64. def MyList():
  65. AddFolder("Смотрю", "user_list", list_type = "watching")
  66. AddFolder("Просмотрено", "user_list", list_type = "completed")
  67. AddFolder("Отложено", "user_list", list_type = "onhold")
  68. AddFolder("Брошено", "user_list", list_type = "dropped")
  69. AddFolder("Запланировано", "user_list", list_type = "planned")
  70. xbmcplugin.endOfDirectory(AddonHandle)
  71. def UserList(listType):
  72. UserAnimeList = Anime365.GetUserList()
  73. for AnimeID in UserAnimeList[listType]:
  74. Anime = Anime365.GetAnimeByID(AnimeID)
  75. AddFolder(Anime["russian"].encode("utf-8"), "anime_title", animeData = Anime)
  76. xbmcplugin.endOfDirectory(AddonHandle)
  77. def AnimeOngoing():
  78. OngoingList = Anime365.GetOngoingList()
  79. for AnimeID in OngoingList:
  80. Anime = Anime365.GetAnimeByID(AnimeID)
  81. AddFolder(Anime["russian"].encode("utf-8"), "anime_title", animeData = Anime)
  82. xbmcplugin.endOfDirectory(AddonHandle)
  83. def RandomAnimes():
  84. RandomAnimeList = Anime365.GetRandomAnimeList()
  85. for AnimeID in RandomAnimeList:
  86. Anime = Anime365.GetAnimeByID(AnimeID)
  87. AddFolder(Anime["russian"].encode("utf-8"), "anime_title", animeData = Anime)
  88. xbmcplugin.endOfDirectory(AddonHandle)
  89. def MainMenu():
  90. AddFolder("Поиск", "anime_search", icon = "https://imageup.ru/img66/3615282/search.png")
  91. AddFolder("Онгоинги", "anime_ongoing", icon = "https://imageup.ru/img260/3660525/ongoing.jpg")
  92. AddFolder("Мой список", "my_list")
  93. AddFolder("Случайное", "anime_random")
  94. xbmcplugin.endOfDirectory(AddonHandle)
  95. def router(paramstring):
  96. params = dict(parse_qsl(paramstring))
  97. try:
  98. if params:
  99. if params["action"] == "anime_search":
  100. AnimeSearch()
  101. elif params["action"] == "anime_ongoing":
  102. AnimeOngoing()
  103. elif params["action"] == "anime_random":
  104. RandomAnimes()
  105. elif params["action"] == "my_list":
  106. MyList()
  107. elif params["action"] == "user_list":
  108. UserList(params["list_type"])
  109. elif params["action"] == "anime_title":
  110. Anime = eval(params["animeData"])
  111. LocalTeamList(Anime["id"])
  112. elif params["action"] == "anime_transaltion":
  113. Episodes = eval(params["episodes"])
  114. EpisodeList(Episodes)
  115. elif params["action"] == "anime_episode":
  116. PlayerData = eval(params["playerData"])
  117. PlayVideo(params["label"], PlayerData["video"], PlayerData["sub"])
  118. else:
  119. xbmc.log("Invalid Paramstring: " + str(paramstring), xbmc.LOGDEBUG)
  120. Message("Invalid Paramstring!", paramstring)
  121. else:
  122. MainMenu()
  123. except Exception as e:
  124. xbmc.log("Paramstring Error: " + str(e), xbmc.LOGDEBUG)
  125. Message("Paramstring Error!", e)
  126. if __name__ == "__main__":
  127. router(sys.argv[2][1:])