modified: configure.ac
[enigma2-plugins.git] / subsdownloader2 / src / SourceCode / xbmc_subtitles / XBMC_search.py
1 #from XBMC.utilities import *\r
2 #from periscope.plugins.SubtitleDatabase import SubtitleDB\r
3 #from Plugins.Extensions.SubsDownloader2.SourceCode.periscope.SubtitleDatabase import SubtitleDB, tvshowRegex, tvshowRegex2, movieRegex\r
4 import os\r
5 #from XBMC.archives_extractor import zip_extractor\r
6 #from Plugins.Extensions.SubsDownloader2.SourceCode.archives_extractor import zip_extractor\r
7 \r
8 def list_XBMC_Periscope_plugins(XBMC_periscope_plugin_path):\r
9     plugin_list = []\r
10     for x in os.listdir(XBMC_periscope_plugin_path):\r
11         if os.path.isdir(XBMC_periscope_plugin_path+x) == True:\r
12             plugin_list.append(x)    \r
13     return plugin_list\r
14 \r
15 \r
16 def list_directory_files(dir_path):\r
17     file_list = []\r
18     for x in os.listdir(dir_path):\r
19         if os.path.isdir(dir_path+x) == False:\r
20             file_list.append(dir_path+x)    \r
21     return file_list\r
22 \r
23 def new_file_in_directory(files_before, files_after):\r
24     new_file = []\r
25     for x in files_after:\r
26         if x in files_before:\r
27             pass\r
28         else:\r
29             new_file.append(x)\r
30     return new_file\r
31 \r
32 \r
33 """\r
34             \r
35 #XBMCSubtitle code for PC not USED in Enigma2\r
36 #from XBMC.services.Itasa import service as SERVICE\r
37 from periscope.plugins.SubtitleDatabase import SubtitleDB\r
38 from periscope.plugins.SubtitleDatabase import *\r
39 \r
40 \r
41 class XBMCSubtitle(SubtitleDB):\r
42     def __init__(self,service):\r
43         self.tvshowRegex = tvshowRegex\r
44         self.tvshowRegex2 = tvshowRegex2\r
45         self.movieRegex = movieRegex\r
46         \r
47         exec ('from XBMC.services.%s import *' % service)\r
48         exec ('from XBMC.services.%s import service as Service' % service)        \r
49         self.service = Service\r
50 \r
51     \r
52     def XBMC_search_subtitles(self, file_path, lang1, lang2,lang3, year = None, set_temp = False, rar = False, stock = True):\r
53         self.file_path = file_path\r
54         self.__subtitle_list = []\r
55         self.__session_id = None\r
56         self.__msg = None        \r
57         fileData = self.guessFileData(self.file_path)\r
58         #===============================================================================\r
59         # Public interface functions\r
60         #===============================================================================\r
61         \r
62         # This function is called when the service is selected through the subtitles\r
63         # addon OSD.\r
64         # file_original_path -> Original system path of the file playing\r
65         # title -> Title of the movie or episode name\r
66         # tvshow -> Name of a tv show. Empty if video isn't a tv show (as are season and\r
67         #           episode)\r
68         # year -> Year\r
69         # season -> Season number\r
70         # episode -> Episode number\r
71         # set_temp -> True iff video is http:// stream\r
72         # rar -> True iff video is inside a rar archive\r
73         # lang1, lang2, lang3 -> Languages selected by the user\r
74         #return self..search_subtitles(self.file_path,fileData['name'],fileData['type'], year, fileData['season'],fileData['episode'],set_temp,rar, lang1, lang2, lang3, 1)\r
75         if fileData['type'] == 'tvshow':\r
76             tvShow = fileData['name']\r
77             season = fileData['season']\r
78             episode = fileData['episode']\r
79             #print fileData\r
80         elif fileData['type'] =='movie' or fileData['type'] =='unknown':\r
81             tvShow = []\r
82             season = []\r
83             episode = []  \r
84             #print fileData\r
85         self.__subtitles_list, self.__session_id, self.__msg = self.service.search_subtitles(file_path, fileData['name'], tvShow, year, season, episode, set_temp, rar, lang1, lang2, lang3, stock)\r
86         return self.__subtitles_list\r
87     \r
88     def XBMC_download_subtitles(self, pos):\r
89         tmp_sub_dir = sub_folder = self.file_path.rsplit("/",1)[0]\r
90         zipped_subs_path = self.file_path.rsplit(".",1)[0]+".zip"\r
91         session_id = self.__session_id\r
92         subtitles_list = self.__subtitles_list\r
93         return self.service.download_subtitles (subtitles_list, pos, zipped_subs_path, tmp_sub_dir, sub_folder, session_id) #ZWRAA False, language, subs_file #standard output\r
94 \r
95     \r
96 file_path = "C:/!Roboczy/How.I.Met.Your.Mother.S07E12.HDTV.XviD-LOL.[VTV].avi"\r
97 SERVICE = XBMCSubtitle("Itasa") \r
98 a, b, c = SERVICE.XBMC_search_subtitles(file_path, "all", "All","All")\r
99 """\r