def get_tmdb_api_key(): try: import filesystem import xbmc home_path = xbmc.translatePath('special://home').decode('utf-8') except ImportError: cur = filesystem.dirname(__file__) home_path = filesystem.join(cur, '../..') key = 'ecbc86c92da237cb9faff6d3ddc4be6d' host = 'api.tmdb.org' try: xml_path = filesystem.join( home_path, 'addons/metadata.common.themoviedb.org/tmdb.xml') with filesystem.fopen(xml_path, 'r') as xml: content = xml.read() match = re.search(r'api_key=(\w+)', content) if match: key = match.group(1) debug('get_tmdb_api_key: ok') m = re.search(r'://(.+)/3/', content) if m: host = m.group(1) except BaseException as e: debug('get_tmdb_api_key: ' + str(e)) return {'host': host, 'key': key}
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
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 move_file_to(self, path): import shutil src = self.get_filename() dirname = filesystem.dirname(path) if not filesystem.exists(dirname): filesystem.makedirs(dirname) shutil.copy2(src, path) os.remove(src)
def tvs_reader(self): is_episode = self.is_episode() if is_episode: path = filesystem.dirname(self.path) path = filesystem.abspath(filesystem.join(path, os.pardir)) path = filesystem.join(path, u'tvshow.nfo') if filesystem.exists(path): debug(u'tvs_reader: ' + path) return NFOReader(path, self.__temp_path) return None
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))
def make_fullpath(title, ext): if filesystem._is_abs_path(title): dir_path = filesystem.dirname(title) filename = filesystem.basename(title) pass else: dir_path = None filename = title if '/' in title: pass result = unicode( filename.replace(':', '').replace('/', '#').replace('?', '').replace( '"', "''") + ext) if dir_path: result = filesystem.join(dir_path, result) return result
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))
yield item process = Process(settings) for href, fulltitle in urls(): result = process.process(href, fulltitle) path_out.append(result) return count if __name__ == '__main__': from settings import Settings import filesystem test_dir = filesystem.join(filesystem.dirname(__file__), 'test') settings = Settings(filesystem.join(test_dir, 'Videos')) settings.addon_data_path = filesystem.join(test_dir, 'data') settings.torrent_path = filesystem.join(test_dir, 'torrents') settings.torrent_player = 'torrent2http' settings.kp_googlecache = False settings.kp_usezaborona = True settings.use_kinopoisk = True settings.use_worldart = True #settings.kinohd_4k = False #settings.kinohd_1080p = False #settings.kinohd_720p = False #settings.kinohd_3d = False