예제 #1
0
def add_media_case():
    if _addon.getSetting('role').decode('utf-8') == u'клиент':
        return

    path = filesystem.join(addon_data_path(), 'add_media')
    if filesystem.exists(path):
        try:
            with filesystem.fopen(path, 'r') as f:
                while True:
                    try:
                        title = f.readline().strip(' \n\t\r').decode('utf-8')
                        imdb = f.readline().strip(' \n\t\r')

                        log.debug('add_media_case: ' + imdb)
                        log.debug(title)

                        if title and imdb:
                            call_bg('add_media_process', {
                                'title': title,
                                'imdb': imdb
                            })
                        else:
                            break
                    except BaseException as e:
                        log.print_tb(e)
        finally:
            filesystem.remove(path)
	def __init__(self, settings, params, playable_item, torrent_info, torrent_path, info_hash):
		self.command = settings.script_params.split(u' ')
		self.settings = settings
		self.params = params
		self.torrent_info = torrent_info
		self.torrent_path = torrent_path
		self.playable_item = playable_item

		self.resume_file = filesystem.join(self.settings.torrents_path(), info_hash + '.resume')

		debug('-' * 30 + ' Runner ' + '-' * 30)
		debug('torrent: ' + self.torrent)
		debug('videofile: ' + self.videofile)
		debug('relativevideofile: ' + self.relativevideofile)
		debug('torrent_source: ' + self.torrent_source)
		debug('short_name: ' + self.short_name)
		debug('downloaded: ' + str(self.downloaded))
		debug('videotype: ' + self.videotype)

		if settings.run_script:
			self.process_params()
			self.run()

		if settings.remove_files:
			debug('Runner: remove_files')
			if filesystem.exists(self.videofile):
				filesystem.remove(self.videofile)

		if float(self.downloaded) > 99 and self.all_torrent_files_exists():

			if settings.move_video and settings.copy_video_path and filesystem.exists(settings.copy_video_path):
				self.move_video_files()

			if settings.copy_torrent and settings.copy_torrent_path and filesystem.exists(settings.copy_torrent_path):
				self.copy_torrent()
예제 #3
0
def main():
    import vsdbg
    vsdbg._attach(False)

    global _addon
    _addon = AddonRO()
    player._addon = _addon

    path = filesystem.join(addon_data_path(), 'update_library_next_start')
    if filesystem.exists(path):
        log.debug('User action!!! update_library_next_start')
        xbmc.executebuiltin('UpdateLibrary("video")')
        filesystem.remove(path)

    cnt = 0
    while not xbmc.abortRequested:

        try:
            scrape_case()
            update_case()
            add_media_case()

        finally:
            sleep(1)

        if cnt % 3600 == 0:
            log.debug("I'm alive at %s" % asctime())
        cnt += 1

    log.debug('service exit')
예제 #4
0
def main():
	global _addon
	_addon = AddonRO()
	player._addon = _addon

	path = filesystem.join(addon_data_path(), 'update_library_next_start')
	if filesystem.exists(path):
		log.debug('User action!!! update_library_next_start')
		xbmc.executebuiltin('UpdateLibrary("video")')
		filesystem.remove(path)


	cnt = 0
	while not xbmc.abortRequested:

		try:
			scrape_case()
			update_case()
			add_media_case()

		finally:
			sleep(1)

		if cnt % 3600 == 0:
			log.debug("I'm alive at %s" % asctime())
		cnt += 1

	log.debug('service exit')
 def remove(path):
     import filesystem
     if filesystem.exists(path):
         try:
             filesystem.remove(path)
             debug(u'remove: {}		[OK]'.format(path))
         except:
             debug(u'remove: {}		[Fail]'.format(path))
예제 #6
0
def update_case():
    # Init
    if not hasattr(update_case, 'first_start'):
        update_case.first_start = True
        update_case.first_start_time = time()
        update_case.prev_generate_time = update_case.first_start_time

    try:
        every = int(_addon.getSetting(
            'service_generate_persistent_every')) * 3600  # seconds
        delay_startup = int(_addon.getSetting('delay_startup')) * 60
    except ValueError:
        every = 8 * 3600
        delay_startup = 0

    # User action
    path = filesystem.join(addon_data_path(), 'start_generate')

    if filesystem.exists(
            path) and _addon.getSetting('role').decode('utf-8') != u'клиент':

        log.debug('User action!!!')

        filesystem.remove(path)
        call_bg('update_service', {'show_progress': True})

        update_case.first_start = False
        return

    # Startup
    if time(
    ) > update_case.first_start_time + delay_startup and update_case.first_start:
        if _addon.getSetting('service_startup') == 'true':
            try:
                log.debug("Persistent Update Service starting...")
                log.debug(_addon.getSetting('service_startup'))
                #update_service(show_progress=False)
                call_bg('update_service', {'show_progress': False})
            except BaseException as e:
                log.print_tb(e)
            finally:
                update_case.first_start = False

    # Persistent
    if time() >= update_case.prev_generate_time + every:  # verification
        if _addon.getSetting('service_generate_persistent') == 'true':
            try:
                update_case.prev_generate_time = time()
                #update_service(show_progress=False)
                call_bg('update_service', {'show_progress': False})
                log.debug('Update List at %s' %
                          asctime(localtime(update_case.prev_generate_time)))
                log.debug('Next Update in %s' %
                          strftime("%H:%M:%S", gmtime(every)))
            except BaseException as e:
                log.print_tb(e)
            finally:
                update_case.first_start = False
예제 #7
0
파일: mpqutil.py 프로젝트: h82258652/YDWE
def create(stormlib_path, from_path, to_path):
    module = stormlib.Open(str(stormlib_path))
    fs.remove(to_path)
    fs.create_directories(to_path.parent_path())
    mpq = module.Open(str(to_path).encode('ascii'))
    if mpq is None:
        raise Exception('Can\'t open mpq ' + str(to_path))
    add_directory(mpq, from_path)
    mpq.Compact()
    del mpq
예제 #8
0
def create(stormlib_path, from_path, to_path):
    module = stormlib.Open(str(stormlib_path))
    fs.remove(to_path)
    fs.create_directories(to_path.parent_path())
    mpq = module.Open(str(to_path).encode('ascii'))
    if mpq is None:
        raise Exception('Can\'t open mpq ' + str(to_path))
    add_directory(mpq, from_path)
    if not mpq.Compact():
        raise Exception('Mpq compact failed.')
        
    del mpq
예제 #9
0
def add_media(title, imdb):
	path = filesystem.join(addon_data_path(), 'add_media')
	log.debug(path)

	# if not filesystem.exists(path):
	# 	with filesystem.fopen(path, 'w'):
	# 		pass

	if filesystem.exists(path):
		with filesystem.fopen(path, 'r') as f:
			s = f.read()
			if imdb.encode('utf-8') in s:
				return

	with filesystem.fopen(path, 'a+') as f:
		log.debug('writing...')
		seq = [title.encode('utf-8') + '\n', imdb.encode('utf-8') + '\n']
		f.writelines(seq)

	ended_path = filesystem.join(addon_data_path(), imdb + '.ended')
	for cnt in range(300):

		if filesystem.exists(ended_path):
			with filesystem.fopen(ended_path, 'r') as f:
				dlg = xbmcgui.Dialog()

				count = f.read()

				try:
					count = int(count)
				except BaseException:
					count = 0

				if count:
					dlg.notification(u'Media Aggregator', u'"%s" добавлено в библиотеку, найдено %d источников.' % (title, count), time=10000)

					url = 'plugin://script.media.aggregator/?' + urllib.urlencode(
						{'action': 'add_media',
						 'title': title.encode('utf-8'),
						 'imdb': imdb,
						 'norecursive': True})

					xbmc.executebuiltin('RunPlugin("%s")' % url)
				else:
					dlg.notification(u'Media Aggregator',
					                 u'"%s" не добавлено в библиотеку, Источники не найдены.' % title,
					                 time=10000)
			filesystem.remove(ended_path)

			break

		sleep(1)
예제 #10
0
def process_chunk(chunk, data_path, seeds_peers):
    import json

    for item in chunk:
        filename = filesystem.join(data_path, 'nnmclub', item[2])
        remove_file = False
        with filesystem.fopen(filename, 'w') as stat_file:
            try:
                json.dump(seeds_peers[item[1]], stat_file)
            except KeyError:
                remove_file = True
        if remove_file:
            filesystem.remove(filename)
예제 #11
0
    def move_file_to(self, path):
        src = self.get_filename()

        dirname = filesystem.dirname(path)
        if not filesystem.exists(dirname):
            filesystem.makedirs(dirname)

        filesystem.copyfile(src, path)
        filesystem.remove(src)

        self.saved_to = path

        self.log('{} was moved to {}'.format(src, path))
예제 #12
0
def process_chunk(chunk, data_path, seeds_peers):
	import json

	for item in chunk:
		filename = filesystem.join(data_path, 'nnmclub', item[2])
		remove_file = False
		with filesystem.fopen(filename, 'w') as stat_file:
			try:
				json.dump(seeds_peers[item[1]], stat_file)
			except KeyError:
				remove_file = True
		if remove_file:
			filesystem.remove(filename)
예제 #13
0
def update_case():
	# Init
	if not hasattr(update_case, 'first_start'):
		update_case.first_start = True
		update_case.first_start_time = time()
		update_case.prev_generate_time = update_case.first_start_time

	try:
		every = int(_addon.getSetting('service_generate_persistent_every')) * 3600 # seconds
		delay_startup = int(_addon.getSetting('delay_startup')) * 60
	except ValueError:
		every = 8 * 3600
		delay_startup = 0

	# User action
	path = filesystem.join(addon_data_path(), 'start_generate')

	if filesystem.exists(path) and _addon.getSetting('role').decode('utf-8') != u'клиент':

		log.debug('User action!!!')

		filesystem.remove(path)
		update_service(show_progress=True)
		update_case.first_start = False
		return

	# Startup
	if time() > update_case.first_start_time + delay_startup and update_case.first_start:
		if _addon.getSetting('service_startup') == 'true':
			try:
				log.debug("Persistent Update Service starting...")
				log.debug(_addon.getSetting('service_startup'))
				update_service(show_progress=False)
			except BaseException as e:
				log.print_tb(e)
			finally:
				update_case.first_start = False

	# Persistent
	if time() >= update_case.prev_generate_time + every:  # verification
		if _addon.getSetting('service_generate_persistent') == 'true':
			try:
				update_case.prev_generate_time = time()
				update_service(show_progress=False)
				log.debug('Update List at %s' % asctime(localtime(update_case.prev_generate_time)))
				log.debug('Next Update in %s' % strftime("%H:%M:%S", gmtime(every)))
			except BaseException as e:
				log.print_tb(e)
			finally:
				update_case.first_start = False
예제 #14
0
def save_dbs():
    path = filesystem.join(_addondir, 'dbversions')

    with filesystem.save_make_chdir_context(path):

        for fn in filesystem.listdir(path):
            filesystem.remove(fn)

        log_dir = xbmc.translatePath('special://logpath').decode('utf-8')
        log_path = filesystem.join(log_dir, 'kodi.log')
        log.debug(log_path)
        with filesystem.fopen(log_path, 'r') as lf:
            for line in lf.readlines():
                if 'Running database version' in line:
                    log.debug(line)
                    name = line.split(' ')[-1].strip('\r\n\t ').decode('utf-8')
                    with filesystem.fopen(name, 'w'):
                        pass
예제 #15
0
def save_dbs():
	path = filesystem.join(_addondir, 'dbversions')

	with filesystem.save_make_chdir_context(path):

		for fn in filesystem.listdir(path):
			filesystem.remove(fn)

		log_dir = xbmc.translatePath('special://logpath').decode('utf-8')
		log_path = filesystem.join(log_dir, 'kodi.log')
		log.debug(log_path)
		with filesystem.fopen(log_path, 'r') as lf:
			for line in lf.readlines():
				if 'Running database version' in line:
					log.debug(line)
					name = line.split(' ')[-1].strip('\r\n\t ').decode('utf-8')
					with filesystem.fopen(name, 'w'):
						pass
    def move_video_files(self):
        debug('Runner: move video')
        for file in self.get_relative_torrent_files_list():
            dest_path = filesystem.join(self.settings.copy_video_path, file)

            if not filesystem.exists(filesystem.dirname(dest_path)):
                filesystem.makedirs(filesystem.dirname(dest_path))

            src_path = filesystem.join(self.storage_path, file)
            if not filesystem.exists(src_path):
                continue

            if not filesystem.exists(dest_path):
                # Move file if no exists
                filesystem.movefile(src_path, dest_path)
            else:
                filesystem.remove(src_path)

            self.change_resume_file(self.settings.copy_video_path)
예제 #17
0
	def move_video_files(self):
		debug('Runner: move video')
		for file in self.get_relative_torrent_files_list():
			dest_path = filesystem.join(self.settings.copy_video_path, file)

			if not filesystem.exists(filesystem.dirname(dest_path)):
				filesystem.makedirs(filesystem.dirname(dest_path))

			src_path = filesystem.join(self.storage_path, file)
			if not filesystem.exists(src_path):
				continue

			if not filesystem.exists(dest_path):
				# Move file if no exists
				filesystem.movefile(src_path, dest_path)
			else:
				filesystem.remove(src_path)

			self.change_resume_file(self.settings.copy_video_path)
    def __init__(self, settings, params, playable_item, torrent_info,
                 torrent_path, info_hash):
        self.command = settings.script_params.split(u' ')
        self.settings = settings
        self.params = params
        self.torrent_info = torrent_info
        self.torrent_path = torrent_path
        self.playable_item = playable_item

        self.resume_file = filesystem.join(self.settings.torrents_path(),
                                           info_hash + '.resume')

        debug('-' * 30 + ' Runner ' + '-' * 30)
        debug('torrent: ' + self.torrent)
        debug('videofile: ' + self.videofile)
        debug('relativevideofile: ' + self.relativevideofile)
        debug('torrent_source: ' + self.torrent_source)
        debug('short_name: ' + self.short_name)
        debug('downloaded: ' + str(self.downloaded))
        debug('videotype: ' + self.videotype)

        if settings.run_script:
            self.process_params()
            self.run()

        if settings.remove_files:
            debug('Runner: remove_files')
            if filesystem.exists(self.videofile):
                filesystem.remove(self.videofile)

        if float(self.downloaded) > 99 and self.all_torrent_files_exists():

            if settings.move_video and settings.copy_video_path and filesystem.exists(
                    settings.copy_video_path):
                self.move_video_files()

            if settings.copy_torrent and settings.copy_torrent_path and filesystem.exists(
                    settings.copy_torrent_path):
                self.copy_torrent()
예제 #19
0
def add_media_case():
	if _addon.getSetting('role').decode('utf-8') == u'клиент':
		return

	path = filesystem.join(addon_data_path(), 'add_media')
	if filesystem.exists(path):
		with filesystem.fopen(path, 'r') as f:
			while True:
				try:
					title = f.readline().strip(' \n\t\r').decode('utf-8')
					imdb = f.readline().strip(' \n\t\r')

					log.debug('add_media_case: ' + imdb)
					log.debug(title)

					if title and imdb:
						add_media_process(title, imdb, player.load_settings())
					else:
						break
				except BaseException as e:
					log.print_tb(e)

		filesystem.remove(path)
예제 #20
0
 def close(self):
     try:
         filesystem.remove(self.progress_file_path)
     except:
         pass
예제 #21
0
def add_media(title, imdb, settings):
    ended_path = filesystem.join(addon_data_path(), imdb + '.ended')
    if filesystem.exists(ended_path):
        try:
            filesystem.remove(ended_path)
        except:
            pass

    path = filesystem.join(addon_data_path(), 'add_media')
    log.debug(path)

    # if not filesystem.exists(path):
    # 	with filesystem.fopen(path, 'w'):
    # 		pass

    if filesystem.exists(path):
        with filesystem.fopen(path, 'r') as f:
            s = f.read()
            if imdb.encode('utf-8') in s:
                return

    with filesystem.fopen(path, 'a+') as f:
        log.debug('writing...')
        seq = [title.encode('utf-8') + '\n', imdb.encode('utf-8') + '\n']
        f.writelines(seq)

    import xbmcgui
    from settings import _addon_name

    class RemoteDialogProgress(xbmcgui.DialogProgressBG):
        def __init__(self, *args, **kwargs):
            self.progress_file_path = filesystem.join(
                addon_data_path(), '.'.join([imdb, 'progress']))
            return super(RemoteDialogProgress, self).__init__(*args, **kwargs)

        def Refresh(self):
            if filesystem.exists(self.progress_file_path):
                try:
                    try:
                        with filesystem.fopen(self.progress_file_path,
                                              'r') as progress_file:
                            args = progress_file.read().split('\n')
                    except:
                        args = [0]

                    args[0] = int(args[0])
                    self.update(*args)
                except:
                    pass

    info_dialog = RemoteDialogProgress()
    info_dialog.create(_addon_name)

    strm_path = filesystem.join(addon_data_path(), imdb + '.strm_path')
    for cnt in range(300):
        info_dialog.Refresh()
        #---------------------------------
        """
		if filesystem.exists(strm_path):
			with filesystem.fopen(strm_path, 'r') as f:
				source = f.read()	# utf-8
				if source and source.endswith('.strm'):
					strm_path = filesystem.join(settings.base_path(), source)
					if filesystem.exists(strm_path):
						with filesystem.fopen(strm_path, 'r') as strm:
							url = strm.read()
							xbmc.executebuiltin('RunPlugin("%s")' % url)
		"""
        #---------------------------------
        if filesystem.exists(ended_path):
            with filesystem.fopen(ended_path, 'r') as f:
                dlg = xbmcgui.Dialog()

                count = f.read()
                try:
                    count = int(count)
                except ValueError:
                    count = 0

                if not xbmc.Player().isPlaying():
                    if count:
                        dlg.notification(
                            _addon_name,
                            u'"%s" добавлено в библиотеку, найдено %d источников.'
                            % (title, count),
                            time=10000)

                        xbmc.executebuiltin('Container.Refresh')

                        url = 'plugin://script.media.aggregator/?' + urllib.urlencode(
                            {
                                'action': 'add_media',
                                'title': title.encode('utf-8'),
                                'imdb': imdb,
                                'strm': strm_path.encode('utf-8'),
                                'norecursive': True
                            })

                        xbmc.executebuiltin('RunPlugin("%s")' % url)
                    else:
                        dlg.notification(
                            _addon_name,
                            u'"%s" не добавлено в библиотеку, Источники не найдены.'
                            % title,
                            time=10000)
            try:
                filesystem.remove(ended_path)
            except:
                pass

            break

        sleep(1)

    info_dialog.close()
예제 #22
0
 def cancel_choice(self, choice_path):
     filesystem.remove(choice_path)
     self.list.reset()
     self.fill_list()