Example #1
0
def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id, screen_session):  #standard input
    import urllib
    f = urllib.urlopen(subtitles_list[pos]["link"])
    language = subtitles_list[pos]["language_name"]

    local_tmp_file = os.path.join(tmp_sub_dir, "zipsubs.zip")
    log(__name__, "Saving subtitles to '%s'" % (local_tmp_file))

    local_file = open(zip_subs, "w" + "b")
    local_file.write(f.read())
    local_file.close()
    zipped_file = zip_extractor(zip_subs, destination_dir=tmp_sub_dir)
    subs_file = zipped_file.extract_zipped_file()
    os.remove(zip_subs)
    return True, language, subs_file #standard output
Example #2
0
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id, screen_session):  #standard input
    import urllib
    f = urllib.urlopen(subtitles_list[pos][ "link" ])
    language = subtitles_list[pos][ "language_name" ]
   
    local_tmp_file = os.path.join(tmp_sub_dir, "zipsubs.zip")
    log( __name__ ,"Saving subtitles to '%s'" % (local_tmp_file))
    
    local_file = open(zip_subs, "w" + "b")
    local_file.write(f.read())
    local_file.close()
    zipped_file = zip_extractor(zip_subs, destination_dir = tmp_sub_dir)
    subs_file = zipped_file.extract_zipped_file() 
    os.remove(zip_subs)   
    return True,language, subs_file #standard output
Example #3
0
def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder,
                       session_id, screen_session):  #standard input
    #username = __settings__.getSetting( "ITuser" )
    #password = __settings__.getSetting( "ITpass" )
    username = config.plugins.subsdownloader.ItasaUser.value
    password = config.plugins.subsdownloader.ItasaPassword.value

    if login(username, password):
        log(__name__, " Login successful")
        id = subtitles_list[pos]["id"]
        link = subtitles_list[pos]["link"]

        content = geturl(main_url + link)
        match = re.search(subtitle_download_pattern % id, content,
                          re.IGNORECASE | re.DOTALL)

        if match:
            language = subtitles_list[pos]["language_name"]
            log(
                __name__, " Fetching subtitles using url %s" %
                (main_url + match.group(1)))
            content = geturl(main_url + match.group(1))
            if content is not None:
                header = content[:4]
                if header == 'Rar!':
                    local_tmp_file = os.path.join(tmp_sub_dir,
                                                  "undertexter.rar")
                    packed = True
                elif header == 'PK':
                    local_tmp_file = os.path.join(tmp_sub_dir,
                                                  "undertexter.zip")
                    packed = True
                else:  # never found/downloaded an unpacked subtitles file, but just to be sure ...
                    local_tmp_file = os.path.join(
                        tmp_sub_dir, "undertexter.srt"
                    )  # assume unpacked subtitels file is an '.srt'
                    subs_file = local_tmp_file
                    packed = False
                log(__name__, " Saving subtitles to '%s'" % (local_tmp_file))

                try:
                    local_file_handle = open(local_tmp_file, "wb")
                    local_file_handle.write(content)
                    local_file_handle.close()
                except:
                    log(__name__,
                        " Failed to save subtitles to '%s'" % (local_tmp_file))
                if packed:
                    if header == 'PK':
                        zipped_file = zip_extractor(local_tmp_file,
                                                    tmp_sub_dir)
                        subs_file = zipped_file.extract_zipped_file()
                        os.remove(local_tmp_file)
                    if header == 'Rar!':
                        if os.path.exists("/usr/bin/unrar"):
                            files_before_unrar = list_directory_files(
                                tmp_sub_dir)
                            os.system('unrar -p- -y x %s %s' %
                                      (local_tmp_file, tmp_sub_dir))
                            files_after_unrar = list_directory_files(
                                tmp_sub_dir)
                            subs_file = new_file_in_directory(
                                files_before_unrar, files_after_unrar)
                            os.remove(local_tmp_file)
                        else:
                            from Components.Ipkg import IpkgComponent
                            from Screens.Ipkg import Ipkg
                            __cmdList = []
                            __cmdList.append((IpkgComponent.CMD_INSTALL, {
                                "package": 'unrar'
                            }))
                            screen_session.openWithCallback(__restartMessage__(
                                screen_session, callback=None),
                                                            Ipkg,
                                                            cmdList=__cmdList)

                return False, language, subs_file  #standard output
    #log( __name__ ," Login to Itasa failed. Check your username/password at the addon configuration.")
    screen_session.open(
        MessageBox,
        _(" Login to Itasa failed. Check your username/password at the configuration menu."
          ),
        MessageBox.TYPE_INFO,
        timeout=5)
    return False, "None", []
Example #4
0
def download_subtitles (subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, session_id, screen_session): #standard input
    #username = __settings__.getSetting( "ITuser" )
    #password = __settings__.getSetting( "ITpass" )
    username = config.plugins.subsdownloader.ItasaUser.value
    password = config.plugins.subsdownloader.ItasaPassword.value
    
    if login(username, password):
        log( __name__ , " Login successful")
        id = subtitles_list[pos][ "id" ]
        link = subtitles_list[pos][ "link" ] 
        
        content= geturl(main_url + link)        
        match = re.search(subtitle_download_pattern % id, content, re.IGNORECASE | re.DOTALL)

        if match:
            language = subtitles_list[pos][ "language_name" ]
            log( __name__ ," Fetching subtitles using url %s" % (main_url + match.group(1)))
            content = geturl(main_url + match.group(1))
            if content is not None:
                header = content[:4]
                if header == 'Rar!':
                    local_tmp_file = os.path.join(tmp_sub_dir, "undertexter.rar")
                    packed = True
                elif header == 'PK':
                    local_tmp_file = os.path.join(tmp_sub_dir, "undertexter.zip")
                    packed = True
                else: # never found/downloaded an unpacked subtitles file, but just to be sure ...
                    local_tmp_file = os.path.join(tmp_sub_dir, "undertexter.srt") # assume unpacked subtitels file is an '.srt'
                    subs_file = local_tmp_file
                    packed = False
                log( __name__ ," Saving subtitles to '%s'" % (local_tmp_file))
                                
                try:
                    local_file_handle = open(local_tmp_file, "wb")
                    local_file_handle.write(content)
                    local_file_handle.close()
                except:
                    log( __name__ ," Failed to save subtitles to '%s'" % (local_tmp_file))
                if packed:
                    if header == 'PK':
                        zipped_file = zip_extractor(local_tmp_file, tmp_sub_dir)
                        subs_file = zipped_file.extract_zipped_file()
                        os.remove(local_tmp_file)
                    if header == 'Rar!':
                        if os.path.exists("/usr/bin/unrar"): 
                            files_before_unrar = list_directory_files(tmp_sub_dir)
                            os.system('unrar -p- -y x %s %s' % (local_tmp_file,tmp_sub_dir))
                            files_after_unrar = list_directory_files(tmp_sub_dir)
                            subs_file = new_file_in_directory(files_before_unrar,files_after_unrar)
                            os.remove(local_tmp_file)
                        else:
                            from Components.Ipkg import IpkgComponent
                            from Screens.Ipkg import Ipkg
                            __cmdList = []
                            __cmdList.append((IpkgComponent.CMD_INSTALL, { "package": 'unrar' }))
                            screen_session.openWithCallback(__restartMessage__(screen_session, callback = None), Ipkg, cmdList = __cmdList)
                    
                return False, language, subs_file #standard output
    #log( __name__ ," Login to Itasa failed. Check your username/password at the addon configuration.")
    screen_session.open(MessageBox,_(" Login to Itasa failed. Check your username/password at the configuration menu."), MessageBox.TYPE_INFO, timeout = 5)
    return False, "None", []
Example #5
0
 def extract_zip_file(self):
     extractor = zip_extractor(self.ZipFilePath, None,
                               ("txt", "sub", "srt"))
     # return false if nothing extracted
     return extractor.extract_zipped_file()
    def extract_zip_file(self):
	extractor = zip_extractor(self.ZipFilePath,None,("txt","sub","srt"))
	# return false if nothing extracted
	return extractor.extract_zipped_file()