Ejemplo n.º 1
0
def scrape_nnm():
	settings = player.load_settings()
	data_path = settings.torrents_path()

	hashes = []
	for torr in filesystem.listdir(filesystem.join(data_path, 'nnmclub')):
		if torr.endswith('.torrent'):
			try:
				from base import TorrentPlayer
				tp = TorrentPlayer()
				tp.AddTorrent(filesystem.join(data_path, 'nnmclub', torr))
				data = tp.GetLastTorrentData()
				if data:
					hashes.append((data['announce'], data['info_hash'], torr.replace('.torrent', '.stat')))
			except BaseException as e:
				log.print_tb(e)

	for chunk in chunks(hashes, 32):
		import scraper
		try:
			seeds_peers = scraper.scrape(chunk[0][0], [i[1] for i in chunk])
		except RuntimeError as RunE:
			if '414 status code returned' in RunE.message:
				for c in chunks(chunk, 16):
					try:
						seeds_peers = scraper.scrape(c[0][0], [i[1] for i in c])
						process_chunk(c, data_path, seeds_peers)
					except BaseException as e:
						log.print_tb(e)
			continue
		except BaseException as e:
			log.print_tb(e)
			continue

		process_chunk(chunk, data_path, seeds_peers)
Ejemplo n.º 2
0
def seeds_peers(item):
	import player
	res = {}
	try:
		link = urllib.unquote(item['link'])
		settings = player.load_settings()
		if 'nnm-club' in link:
			debug('seeds_peers: ' + link)
			t_id = re.search(r't=(\d+)', link).group(1)
			fn = filesystem.join(settings.torrents_path(), 'nnmclub', t_id + '.stat')
			debug(fn)
			with filesystem.fopen(fn, 'r') as stat_file:
				import json
				res = json.load(stat_file)
				debug(str(res))
		elif 'hdclub' in link:
			t_id = re.search(r'\.php.+?id=(\d+)', link).group(1)
			fn = filesystem.join(settings.torrents_path(), 'hdclub', t_id + '.torrent')
			return scrape_now(fn)
		elif 'rutor' in link:
			t_id = re.search(r'/torrent/(\d+)', link).group(1)
			fn = filesystem.join(settings.torrents_path(), 'rutor', t_id + '.torrent')
			return scrape_now(fn)

	except BaseException as e:
		debug(str(e))
	return res
Ejemplo n.º 3
0
def clean_movies():
    from kodidb import MoreRequests
    ll = MoreRequests().get_movie_duplicates()

    try:
        from player import load_settings
        settings = load_settings()
    except:
        from settings import Settings
        settings = Settings(
            filesystem.join(filesystem.dirname(__file__), 'test', 'Videos'))

    import movieapi
    from base import make_fullpath

    def clean_movie_by_imdbid(imdbid):
        api = movieapi.MovieAPI(imdbid)
        genre = api['genres']
        if u'мультфильм' in genre:
            base_path = settings.animation_path()
        elif u'документальный' in genre:
            base_path = settings.documentary_path()
        else:
            base_path = settings.movies_path()

        mm = MoreRequests().get_movies_by_imdb(imdbid)

        from base import STRMWriterBase
        from base import Informer

        title = Informer().filename_with(api['title'], api['originaltitle'],
                                         api['year'])

        strm_path = filesystem.join(base_path, make_fullpath(title, '.strm'))
        #alt_path = strm_path + '.alternative'
        nfo_path = filesystem.join(base_path, make_fullpath(title, '.nfo'))

        strm_data = filesystem.fopen(mm[0][3], 'r').read()
        alt_data = []
        for m in mm:
            links_with_ranks = STRMWriterBase.get_links_with_ranks(
                mm[0][3], settings, use_scrape_info=False)
            alt_data.extend(links_with_ranks)

        alt_data = [
            dict(t) for t in set([tuple(d.iteritems()) for d in alt_data])
        ]
        #alt_data = list(set(alt_data))
        #alt_data.sort(key=operator.itemgetter('rank'))
        with filesystem.save_make_chdir_context(
                base_path, 'STRMWriterBase.write_alternative'):
            STRMWriterBase.write_alternative(strm_path, alt_data)
        pass

    for m in ll:
        try:
            clean_movie_by_imdbid(m[4])
        except:
            pass
Ejemplo n.º 4
0
def seeds_peers(item):
    res = {}
    try:
        link = urllib.unquote(item['link'])
        try:
            import player
            settings = player.load_settings()
        except:
            settings = Settings.current_settings
        if 'nnm-club' in link:
            debug('seeds_peers: ' + link)
            t_id = re.search(r't=(\d+)', link).group(1)
            fn = filesystem.join(settings.torrents_path(), 'nnmclub',
                                 t_id + '.stat')
            debug(fn)
            with filesystem.fopen(fn, 'r') as stat_file:
                import json
                res = json.load(stat_file)
                debug(str(res))
        elif 'hdclub' in link:
            t_id = re.search(r'\.php.+?id=(\d+)', link).group(1)
            fn = filesystem.join(settings.torrents_path(), 'elitehd',
                                 t_id + '.torrent')
            return scrape_now(fn)
        elif 'bluebird' in link:
            t_id = re.search(r'\.php.+?id=(\d+)', link).group(1)
            fn = filesystem.join(settings.torrents_path(), 'bluebird',
                                 t_id + '.torrent')
            if not filesystem.exists(fn):
                import bluebird
                bluebird.download_torrent(link, fn, settings)
            return scrape_now(fn)
        elif 'rutor' in link:
            t_id = re.search(r'/torrent/(\d+)', link).group(1)
            fn = filesystem.join(settings.torrents_path(), 'rutor',
                                 t_id + '.torrent')
            return scrape_now(fn)
        '''
		elif 'kinohd'  in link:
			part = self.url.split('/')[-1]
			t_id = re.search(r'^(\d+)', part).group(1)
			fn = filesystem.join(settings.torrents_path(), 'kinohd', t_id + '.torrent')
			return scrape_now(fn)
		'''

    except BaseException as e:
        debug(str(e))
    return res
Ejemplo n.º 5
0
def update_service(show_progress=False):

	anidub_enable		= _addon.getSetting('anidub_enable') == 'true'
	hdclub_enable		= _addon.getSetting('hdclub_enable') == 'true'
	nnmclub_enable		= _addon.getSetting('nnmclub_enable') == 'true'
	rutor_enable		= _addon.getSetting('rutor_enable') == 'true'
	settings			= player.load_settings()

	if show_progress:
		info_dialog = xbmcgui.DialogProgressBG()
		info_dialog.create('Media Aggregator')
		settings.progress_dialog = info_dialog
	
	if anidub_enable:
		anidub.run(settings)

	if hdclub_enable:
		hdclub.run(settings)

	if nnmclub_enable:
		addon = Addon('settings2.xml')

		try:
			settings.nnmclub_hours = int(math.ceil((time() - float(addon.getSetting('nnm_last_generate'))) / 3600.0))
		except BaseException as e:
			settings.nnmclub_hours = 168
			log.print_tb(e)

		if settings.nnmclub_hours > 168:
			settings.nnmclub_hours = 168

		log.debug('NNM hours: ' + str(settings.nnmclub_hours))

		addon.setSetting('nnm_last_generate', str(time()))
		nnmclub.run(settings)

	if rutor_enable:
		import rutor
		rutor.run(settings)

	if show_progress:
		info_dialog.update(0, '', '')
		info_dialog.close()

	if anidub_enable or hdclub_enable or nnmclub_enable or rutor_enable:
		if not xbmc.getCondVisibility('Library.IsScanningVideo'):
			xbmc.executebuiltin('UpdateLibrary("video")')
Ejemplo n.º 6
0
def scrape_nnm():
    from player import load_settings
    settings = load_settings()

    data_path = settings.torrents_path()

    if not filesystem.exists(filesystem.join(data_path, 'nnmclub')):
        return

    hashes = []
    for torr in filesystem.listdir(filesystem.join(data_path, 'nnmclub')):
        if torr.endswith('.torrent'):
            try:
                from base import TorrentPlayer
                tp = TorrentPlayer()
                tp.AddTorrent(filesystem.join(data_path, 'nnmclub', torr))
                data = tp.GetLastTorrentData()
                if data:
                    hashes.append((data['announce'], data['info_hash'],
                                   torr.replace('.torrent', '.stat')))
            except BaseException as e:
                log.print_tb(e)

    for chunk in chunks(hashes, 32):
        import scraper
        try:
            seeds_peers = scraper.scrape(chunk[0][0], [i[1] for i in chunk],
                                         10)
        except RuntimeError as RunE:
            if '414 status code returned' in RunE.message:
                for c in chunks(chunk, 16):
                    try:
                        seeds_peers = scraper.scrape(c[0][0],
                                                     [i[1] for i in c], 10)
                        process_chunk(c, data_path, seeds_peers)
                    except BaseException as e:
                        log.print_tb(e)
            continue
        except BaseException as e:
            log.print_tb(e)
            continue

        process_chunk(chunk, data_path, seeds_peers)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def update_service(show_progress=False):

    import anidub, hdclub, nnmclub, rutor, soap4me, bluebird, kinohd

    from player import _addon

    anidub_enable = _addon.getSetting('anidub_enable') == 'true'
    hdclub_enable = False
    bluebird_enable = _addon.getSetting('bluebird_enable') == 'true'
    nnmclub_enable = _addon.getSetting('nnmclub_enable') == 'true'
    rutor_enable = _addon.getSetting('rutor_enable') == 'true'
    soap4me_enable = _addon.getSetting('soap4me_enable') == 'true'
    kinohd_enable = _addon.getSetting('kinohd_enable') == 'true'

    from player import load_settings
    settings = load_settings()

    import time
    from_time = time.time()

    if show_progress:
        import xbmcgui
        info_dialog = xbmcgui.DialogProgressBG()
        info_dialog.create(settings.addon_name)
        settings.progress_dialog = info_dialog

    from log import dump_context

    if anidub_enable:
        with dump_context('anidub.run'):
            anidub.run(settings)

    #if hdclub_enable:
    #	hdclub.run(settings)

    if bluebird_enable:
        with dump_context('bluebird.run'):
            bluebird.run(settings)

    if rutor_enable:
        with dump_context('rutor.run'):
            rutor.run(settings)

    if kinohd_enable:
        with dump_context('kinohd.run'):
            kinohd.run(settings)

    if nnmclub_enable:
        from service import Addon
        addon = Addon('settings3.xml')

        try:
            import math
            from time import time
            settings.nnmclub_hours = int(
                math.ceil(
                    (time() - float(addon.getSetting('nnm_last_generate'))) /
                    3600.0))
        except BaseException as e:
            settings.nnmclub_hours = 168
            log.print_tb(e)

        if settings.nnmclub_hours > 168:
            settings.nnmclub_hours = 168

        if settings.nnmclub_hours < 8:
            settings.nnmclub_hours = 8

        log.debug('NNM hours: ' + str(settings.nnmclub_hours))

        addon.setSetting('nnm_last_generate', str(time()))

        with dump_context('nnmclub.run'):
            nnmclub.run(settings)

    #if soap4me_enable:
    #	import soap4me
    #	soap4me.run(settings)

    if show_progress:
        info_dialog.update(0, '', '')
        info_dialog.close()

    if anidub_enable or nnmclub_enable or rutor_enable or soap4me_enable or bluebird_enable or kinohd_enable:
        import xbmc
        if not xbmc.getCondVisibility('Library.IsScanningVideo'):
            xbmc.executebuiltin('UpdateLibrary("video")')

    recheck_torrent_if_need(from_time, settings)
Ejemplo n.º 9
0
def add_media_process(title, imdb):
    count = 0

    from player import getSetting, load_settings
    import anidub, hdclub, nnmclub, rutor, soap4me, bluebird, kinohd

    settings = load_settings()

    anidub_enable = getSetting('anidub_enable') == 'true'
    hdclub_enable = False
    bluebird_enable = getSetting('bluebird_enable') == 'true'
    nnmclub_enable = getSetting('nnmclub_enable') == 'true'
    rutor_enable = getSetting('rutor_enable') == 'true'
    soap4me_enable = getSetting('soap4me_enable') == 'true'
    kinohd_enable = getSetting('kinohd_enable') == 'true'

    class RemoteDialogProgress:
        progress_file_path = filesystem.join(addon_data_path(),
                                             '.'.join([imdb, 'progress']))

        def update(self, percent, *args, **kwargs):
            with filesystem.fopen(self.progress_file_path,
                                  'w') as progress_file:
                progress_file.write(str(percent) + '\n')
                progress_file.write('\n'.join(args).encode('utf-8'))

        def close(self):
            try:
                filesystem.remove(self.progress_file_path)
            except:
                pass

    settings.progress_dialog = RemoteDialogProgress()

    p = []

    from log import dump_context
    #try:
    if True:
        if anidub_enable and imdb.startswith('sm'):
            with dump_context('anidub.search_generate'):
                c = anidub.search_generate(title, settings, p)
                count += c

        if imdb.startswith('tt'):
            #if hdclub_enable:
            #	c = hdclub.search_generate(title, imdb, settings, p)
            #	count += c
            if bluebird_enable:
                with dump_context('bluebird.search_generate'):
                    c = bluebird.search_generate(title, imdb, settings, p)
                    count += c
            if rutor_enable:
                with dump_context('rutor.search_generate'):
                    c = rutor.search_generate(title, imdb, settings, p)
                    count += c
            if kinohd_enable:
                with dump_context('kinohd.search_generate'):
                    c = kinohd.search_generate(title, imdb, settings, p)
                    count += c

            if nnmclub_enable:
                with dump_context('nnmclub.search_generate'):
                    c = nnmclub.search_generate(title, imdb, settings, p)
                    count += c
            #if soap4me_enable:
            #	count += soap4me.search_generate(title, imdb, settings)
    #except BaseException as e:
    #	log.print_tb(e)

    if p:
        path = filesystem.join(addon_data_path(), imdb + '.strm_path')
        with filesystem.fopen(path, 'w') as f:
            f.write(p[0].encode('utf-8'))

    settings.progress_dialog.close()

    if count:
        import xbmc
        if not xbmc.getCondVisibility('Library.IsScanningVideo'):
            if p and p[0]:
                path = p[0]

                if path.endswith('.strm'):
                    type = 'movies'
                else:
                    type = 'tvshows'

                base_path = filesystem.dirname(p[0])

                from sources import Sources
                srcs = Sources()
                for src in srcs.get('video', normalize=False):
                    src_path_basename = filesystem.basename(
                        src.path.rstrip('\\/'))
                    if src_path_basename == base_path:  #base_path.lower().replace('\\', '/') in src.path.lower().replace('\\', '/'):
                        path_update = src.path
                        if type == 'tvshows':
                            if src.path.startswith('smb://'):
                                path_update = src.path
                                path_update = path_update.strip(
                                    '\\/') + '/' + filesystem.basename(path)
                            else:
                                path_update = filesystem.join(
                                    src.path, filesystem.basename(path))
                        log.debug(path_update)
                        xbmc.executebuiltin('UpdateLibrary("video","%s")' %
                                            path_update.encode('utf-8'))

                #xbmc.executebuiltin('UpdateLibrary("video")')
            else:
                xbmc.executebuiltin('UpdateLibrary("video")')

            xbmc.sleep(250)
            while xbmc.getCondVisibility('Library.IsScanningVideo'):
                xbmc.sleep(100)

    path = filesystem.join(addon_data_path(), imdb + '.ended')
    with filesystem.fopen(path, 'w') as f:
        f.write(str(count))
Ejemplo n.º 10
0
def main(settings=None, path=None, name=None, run=None):

    import time
    main.start_time = time.time()

    def stage(n):
        """
		now = time.time()
		debug('stage: {} ({} msec)'.format(n, (now - main.start_time)))
		main.start_time = now
		"""

    stage(0)

    if not path or not name:
        path, name = get_path_name()

    stage(1)

    if not settings:
        import player
        settings = player.load_settings()

    stage(2)

    import xbmcvfs, os
    tempPath = xbmc.translatePath('special://temp')
    if xbmcvfs.exists(path + '.alternative'):
        debug('path exists')
        xbmcvfs.copy(path, os.path.join(tempPath, name))
        xbmcvfs.copy(path + '.alternative',
                     os.path.join(tempPath, name + '.alternative'))
        path = os.path.join(tempPath, name)
    else:
        return False

    class Links():
        def __init__(self):
            self.reload = None
            self._links = result = STRMWriterBase.get_links_with_ranks(
                path.decode('utf-8'), settings, use_scrape_info=False)

        def __call__(self):
            return self._links

        def set_reload(self, reload):
            self.reload = reload
            import threading
            self.thread = threading.Thread(target=self.do_get_seeds_peers)
            self.thread.start()

        def do_get_seeds_peers(self):
            from base import seeds_peers
            for item in self._links:
                if self.reload:
                    sp = seeds_peers(item)
                    item = dict(item, **sp)
                    self.reload(item)

        def close(self):
            self.reload = None

    stage(3)

    links = Links()

    stage(4)

    window = MyWindow(settings.addon_name, settings=settings, links=links)

    stage(5)

    window.doModal()

    links.close()

    debug(window.has_choice)
    debug(window.has_select_file)

    if not window.has_choice and not window.has_select_file:
        del window
        return True

    cursel = window.list.getSelectedItem()
    debug(cursel.getLabel())
    link = cursel.getProperty('link')
    debug(link)

    if link == 'plugin://script.media.aggregator/?action=settings':
        xbmc.executebuiltin('Addon.OpenSettings(script.media.aggregator)')
        del window
        return True

    if link == 'plugin://script.media.aggregator/?action=show_similar':
        from context_show_similar import show_similar
        if show_similar():
            del window
            return True

    if link == 'plugin://script.media.aggregator/?action=add_media':
        from context_get_sources import get_sources
        get_sources(settings)
        return True

    if link == 'plugin://script.media.aggregator/?action=united_search':
        import context_united_search

    selected_file = None
    if window.has_select_file:
        #selected_file = window.files.getSelectedItem().getLabel()
        selected_file = window.files.getSelectedItem().getProperty('index')

    del window

    with filesystem.fopen(path.decode('utf-8'), 'r') as strm:
        src_link = strm.read()
        debug(src_link)
        pattern = 'torrent=(.+?)&'
        match = re.search(pattern, str(link))
        if not match:
            pattern2 = 'torrent=(.+)'
            match = re.search(pattern2, str(link))

        if match:
            torr = match.group(1)
            dst_link = re.sub(pattern, 'torrent=' + torr + '&',
                              str(src_link)) + '&onlythis=true'
            debug(dst_link)

            if selected_file:
                dst_link += '&index=' + str(selected_file)

            if run:
                if selected_file:
                    run(torr, int(selected_file))
                else:
                    run(torr)
            else:
                xbmc.executebuiltin('xbmc.PlayMedia(' + dst_link + ')')

    if tempPath in path:
        xbmcvfs.delete(path)
        xbmcvfs.delete(path + '.alternative')

    return True
Ejemplo n.º 11
0
def main():
    debug_info_label("ListItem.FileName")
    debug_info_label("ListItem.Path")
    debug_info_label("ListItem.FileExtension")
    debug_info_label("ListItem.FileNameAndPath")
    debug_info_label("ListItem.DBID")  # movie id)
    debug_info_label("ListItem.IMDBNumber")

    debug_info_label("Container.FolderPath")

    # import rpdb2
    # rpdb2.start_embedded_debugger('pw')

    import player

    settings = player.load_settings()

    path = xbmc.getInfoLabel("ListItem.FileNameAndPath")
    name = xbmc.getInfoLabel("ListItem.FileName")

    import xbmcvfs, os

    tempPath = xbmc.translatePath("special://temp")
    if xbmcvfs.exists(path + ".alternative"):
        debug("path exists")
        xbmcvfs.copy(path, os.path.join(tempPath, name))
        xbmcvfs.copy(path + ".alternative", os.path.join(tempPath, name + ".alternative"))
        path = os.path.join(tempPath, name)

    links = STRMWriterBase.get_links_with_ranks(path.decode("utf-8"), settings, use_scrape_info=True)

    window = MyWindow("Media Aggregator", settings=settings, links=links)
    window.doModal()

    debug(window.has_choice)
    debug(window.has_select_file)

    if not window.has_choice and not window.has_select_file:
        del window
        return

    cursel = window.list.getSelectedItem()
    debug(cursel.getLabel())
    link = cursel.getProperty("link")
    debug(link)

    if link == "plugin://script.media.aggregator/?action=settings":
        xbmc.executebuiltin("Addon.OpenSettings(script.media.aggregator)")
        del window
        return

    if link == "plugin://script.media.aggregator/?action=show_similar":
        imdb_id = xbmc.getInfoLabel("ListItem.IMDBNumber")
        type = "movie"

        if not imdb_id and xbmc.getInfoLabel("ListItem.DBTYPE") == "episode":
            from nforeader import NFOReader

            nfo_path = xbmc.getInfoLabel("ListItem.FileNameAndPath").replace(".strm", ".nfo").decode("utf-8")
            debug(nfo_path)
            rd = NFOReader(nfo_path, "")
            tvs_rd = rd.tvs_reader()
            imdb_id = tvs_rd.imdb_id()
            type = "tv"

        if imdb_id:
            from movieapi import MovieAPI

            res = MovieAPI.tmdb_by_imdb(imdb_id, type)
            debug(res)
            if res and len(res) > 0:
                tmdb_id = res[0].tmdb_id()
                xbmc.executebuiltin(
                    'Container.Update("plugin://script.media.aggregator/?action=show_similar&tmdb=%s")' % tmdb_id
                )
                del window
                return

    if link == "plugin://script.media.aggregator/?action=add_media":
        imdb_id = xbmc.getInfoLabel("ListItem.IMDBNumber")
        title = xbmc.getInfoLabel("ListItem.Title")

        debug(imdb_id)
        debug(title)

        from service import add_media

        add_media(title.decode("utf-8"), imdb_id)
        return

    selected_file = None
    if window.has_select_file:
        # selected_file = window.files.getSelectedItem().getLabel()
        selected_file = window.files.getSelectedItem().getProperty("index")

    del window

    with filesystem.fopen(path.decode("utf-8"), "r") as strm:
        src_link = strm.read()
        debug(src_link)
        pattern = "torrent=(.+?)&"
        match = re.search(pattern, str(link))
        if not match:
            pattern2 = "torrent=(.+)"
            match = re.search(pattern2, str(link))

        if match:
            dst_link = re.sub(pattern, "torrent=" + match.group(1) + "&", str(src_link)) + "&onlythis=true"
            debug(dst_link)

            if selected_file:
                # import urllib
                # from tvshowapi import cutStr
                # dst_link += '&cutName=' + urllib.quote(cutStr(selected_file))
                dst_link += "&index=" + str(selected_file)

            xbmc.executebuiltin("xbmc.PlayMedia(" + dst_link + ")")

    if tempPath in path:
        xbmcvfs.delete(path)
        xbmcvfs.delete(path + ".alternative")
Ejemplo n.º 12
0
from log import debug
import xbmc


def get_sources(settings):
    imdb_id = xbmc.getInfoLabel('ListItem.IMDBNumber')
    title = xbmc.getInfoLabel('ListItem.Title')

    debug(imdb_id)
    debug(title)

    from service import add_media
    add_media(title.decode('utf-8'), imdb_id, settings)


if __name__ == '__main__':
    from player import load_settings

    settings = load_settings()
    get_sources(settings)
Ejemplo n.º 13
0
def dispatch():
    from log import debug

    params = get_params()
    debug(params)

    from player import load_settings

    import vsdbg
    vsdbg._bp()

    if 'torrent' in params:
        from player import play_torrent

        settings = load_settings()
        if settings.show_sources and 'onlythis' not in params:
            import filesystem, urllib

            rel_path = urllib.unquote(params['path']).decode('utf-8')
            debug(rel_path)

            filename = urllib.unquote(params['nfo']).decode('utf-8').replace(
                u'.nfo', u'.strm')
            debug(filename)

            path = filesystem.join(settings.base_path(), rel_path, filename)
            debug(path)

            def run(torr, index=None):
                params['onlythis'] = 'true'
                params['torrent'] = torr
                if index is not None:
                    params['index'] = index
                play_torrent(settings=settings, params=params)

            import context
            res = context.main(settings, path.encode('utf-8'),
                               filename.encode('utf-8'), run)
            if not res:
                play_torrent(settings=settings, params=params)
        else:
            play_torrent(settings=settings, params=params)

    elif params.get('action') == 'anidub-add-favorites':
        from player import action_anidub_add_favorites
        action_anidub_add_favorites(load_settings())

    elif params.get('action') == 'settings':
        from player import dialog_action, dialog_action_case
        dialog_action(dialog_action_case.settings, load_settings())

    elif params.get('action') == 'search':
        from player import dialog_action, dialog_action_case
        dialog_action(dialog_action_case.search, load_settings(), params)

    elif params.get('action') == 'search_context':
        from player import action_search_context
        action_search_context(params)

    elif params.get('action') == 'catalog':
        from player import dialog_action, dialog_action_case
        dialog_action(dialog_action_case.catalog, load_settings())

    elif params.get('action') == 'show_category':
        from player import action_show_category
        action_show_category(params)

    elif params.get('action') == 'show_library':
        from player import action_show_library
        action_show_library(params)

    elif params.get('action') == 'show_similar':
        from player import action_show_similar
        action_show_similar(params)

    elif params.get('action') == 'add_media':
        vsdbg._bp()

        from player import action_add_media
        action_add_media(params, load_settings())

    elif params.get('action') == 'update_service':
        vsdbg._bp()
        from backgrounds import update_service
        update_service(show_progress=params.get('show_progress'))

    elif params.get('action') == 'scrape_nnm':
        from backgrounds import scrape_nnm
        scrape_nnm()

    elif params.get('action') == 'clean_movies':
        from backgrounds import clean_movies
        clean_movies()

    elif params.get('action') == 'select_source':
        from context import main
        vsdbg._bp()
        main()

    elif params.get('action') == 'add_media_process':
        #vsdbg._bp()

        from backgrounds import add_media_process
        title = params.get('title')
        import urllib
        title = urllib.unquote_plus(title)
        title = title.decode('utf-8')

        add_media_process(title, params.get('imdb'))

    else:
        from player import menu_actions, dialog_action, main_menu
        if params.get('menu') in menu_actions:
            dialog_action(menu_actions.index(params.get('menu')),
                          load_settings(), params)
        else:
            main_menu(menu_actions)