Esempio n. 1
0
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)
Esempio n. 2
0
def action_add_media(params, settings):
	title = urllib.unquote_plus(params.get('title')).decode('utf-8')
	imdb = params.get('imdb')
	force = params.get('force') == 'true'
	
	if getSetting('role').decode('utf-8') == u'клиент' and params.get('norecursive'):
		force_library_update(settings, params)

	if force:
		from service import add_media
		add_media(title, imdb, settings)
		return
	
	import json
	found = None

	if imdb.startswith('sm') and title:
		req = {"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "originaltitle", "year", "file", "imdbnumber"]}, "id": "libTvShows"}
		result = json.loads(xbmc.executeJSONRPC(json.dumps(req)))
		try:
			for r in result['result']['tvshows']:
				if r['originaltitle'] == title:
					found = 'tvshow'
					break
		except KeyError:
			debug('KeyError: Animes not found')
	
	if not found:
		#req = {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "originaltitle", "year", "file", "imdbnumber"]}, "id": "libMovies"}
		#result = json.loads(xbmc.executeJSONRPC(json.dumps(req)))
		from complex_requests import get_movies_by_imdb
		result = get_movies_by_imdb(imdb)
		try:
			for r in result['result']['movies']:
				if r['imdbnumber'] == imdb:
					found = 'movie'
					break
		except KeyError:
			debug('KeyError: Movies not found')
	
	if not found:
		req = {"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "originaltitle", "year", "file", "imdbnumber"]}, "id": "libTvShows"}
		result = json.loads(xbmc.executeJSONRPC(json.dumps(req)))
		try:
			for r in result['result']['tvshows']:
				if r['imdbnumber'] == imdb:
					found = 'tvshow'
					break
		except KeyError:
			debug('KeyError: TVShows not found')
	
	dialog = xbmcgui.Dialog()
	if found == 'movie':
		if dialog.yesno(u'Кино найдено в библиотеке', u'Запустить?'):
			#with filesystem.fopen(r['file'], 'r') as strm:
			#	xbmc.executebuiltin('RunPlugin("%s")' % strm.read())
			xbmc.executebuiltin('PlayMedia("%s")' % r['file'].encode('utf-8'))
	elif found == 'tvshow':
		if dialog.yesno(u'Сериал найден в библиотеке', u'Перейти?'):
			xbmc.executebuiltin('ActivateWindow(Videos,%s,return)' % r['file'].encode('utf-8'))
	elif not params.get('norecursive'):
		if dialog.yesno(u'Кино/сериал не найден в библиотеке', u'Запустить поиск по трекерам?'):
			from service import add_media
			add_media(title, imdb, settings)
Esempio n. 3
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")
Esempio n. 4
0
def main():
	from service import create_mark_file
	create_mark_file()

	params = get_params()
	debug(params)
	settings = load_settings()

	debug(settings.base_path())
	if 'torrent' in params:
		# import rpdb2
		# rpdb2.start_embedded_debugger('pw')
		play_torrent(settings=settings, params=params)

	elif params.get('action') == 'anidub-add-favorites':
		debug('anidub-add-favorites')
		anidub_enable = _addon.getSetting('anidub_enable') == 'true'
		if anidub_enable:
			if settings.anime_save:
				debug('scan for anidub-add-favorites')
				anidub.write_favorites(settings.anime_tvshow_path(), settings)

	elif params.get('action') == 'settings':
		dialog_action(dialog_action_case.settings, settings)

	elif params.get('action') == 'search':
		dialog_action(dialog_action_case.search, settings)

	elif params.get('action') == 'search_context':
		s = params.get('s')
		show_list(MovieAPI.search(s.decode('utf-8')))

	elif params.get('action') == 'catalog':
		dialog_action(dialog_action_case.catalog, settings)

	elif params.get('action') == 'show_category':
		if params.get('category') == 'popular':
			show_list(MovieAPI.popular())
		if params.get('category') == 'top_rated':
			show_list(MovieAPI.top_rated())
		if params.get('category') == 'popular_tv':
			show_list(MovieAPI.popular_tv())
		if params.get('category') == 'top_rated_tv':
			show_list(MovieAPI.top_rated_tv())

	elif params.get('action') == 'show_similar':
		listing = MovieAPI.show_similar(params.get('tmdb'))
		log.debug(listing)
		show_list(listing)

	elif params.get('action') == 'add_media':
		title = urllib.unquote_plus(params.get('title')).decode('utf-8')
		imdb = params.get('imdb')

		import json
		found = None

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

		req = {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "originaltitle", "year", "file", "imdbnumber"]}, "id": "libMovies"}
		result = json.loads(xbmc.executeJSONRPC(json.dumps(req)))
		try:
			for r in result['result']['movies']:
				if r['imdbnumber'] == imdb:
					found = 'movie'
					break
		except KeyError:
			debug('KeyError: Movies not found')

		if not found:
			req = {"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "originaltitle", "year", "file", "imdbnumber"]}, "id": "libTvShows"}
			result = json.loads(xbmc.executeJSONRPC(json.dumps(req)))
			try:
				for r in result['result']['tvshows']:
					if r['imdbnumber'] == imdb:
						found = 'tvshow'
						break
			except KeyError:
				debug('KeyError: TVShows not found')

		dialog = xbmcgui.Dialog()
		if found == 'movie':
			if dialog.yesno(u'Кино найдено в библиотеке', u'Запустить?'):
				#with filesystem.fopen(r['file'], 'r') as strm:
				#	xbmc.executebuiltin('RunPlugin("%s")' % strm.read())
				xbmc.executebuiltin('PlayMedia("%s")' % r['file'].encode('utf-8'))
		elif found == 'tvshow':
			if dialog.yesno(u'Сериал найден в библиотеке', u'Перейти?'):
				xbmc.executebuiltin('ActivateWindow(Videos,%s,return)' % r['file'].encode('utf-8'))
		elif not params.get('norecursive'):
			if dialog.yesno(u'Кино/сериал не найден в библиотеке', u'Запустить поиск по трекерам?'):
				from service import add_media
				add_media(title, imdb)

	else:
		menu_items = [u'Генерировать .strm и .nfo файлы',
		              u'Создать источники',
		              u'Настройки',
		              u'Поиск',
		              u'Каталог'
		]
		menu_actions = ['generate',
		                'sources',
						'settings',
						'search',
						'catalog'
		]

		if params.get('menu') in menu_actions:
			dialog_action(menu_actions.index(params.get('menu')), settings)
		else:
			indx = 0
			addon_handle = int(sys.argv[1])
			for menu in menu_items:
				li = xbmcgui.ListItem(menu)
				url = 'plugin://script.media.aggregator/?menu=' + menu_actions[indx]
				xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=indx > dialog_action_case.settings)
				indx += 1

			xbmcplugin.endOfDirectory(addon_handle)

		'''