def write_episode(info, parser, fulltitle, description, link, settings): path = parser.full_tvshow_path season_path = 'Season ' + str(info['season']) with filesystem.save_make_chdir_context(filesystem.join(path, season_path)): from nfowriter import NFOWriter filename = '%02d. episode_s%02de%02d' % (info['episode'], info['season'], info['episode']) episode = parser.tvshow_api.Episode(info['season'], info['episode']) if not episode: episode = { 'title': info['episode_name'], 'seasonNumber': info['season'], 'episodeNumber': info['episode'], 'image': '', 'airDate': '' } NFOWriter(parser, tvshow_api=parser.tvshow_api, movie_api=parser.movie_api()).write_episode(episode, filename) from strmwriter import STRMWriter import re link = re.sub(r'/dl/[\d\w]+/', '/dl/', link) from downloader import TorrentDownloader dl = TorrentDownloader(link, settings.torrents_path(), settings) dl.download() path = filesystem.join(settings.torrents_path(), dl.get_subdir_name(), dl.get_post_index() + '.torrent') STRMWriter(link).write(filename, settings=settings, parser=EpParser(parser, info, path, episode))
def get_path_or_url_and_episode(settings, params, torrent_source): tempPath = xbmc.translatePath('special://temp').decode('utf-8') torr_downloader = TorrentDownloader(urllib.unquote(torrent_source), tempPath, settings) path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.torrent') if not filesystem.exists(path): torr_downloader.download() torr_downloader.move_file_to(path) torr_downloader = None return {'path_or_url': path, 'episode': params.get('episodeNumber', None), 'downloader': torr_downloader}
def is_torrent_remembed(parser, settings): from downloader import TorrentDownloader import urllib link = parser.get('link').split('torrent=')[-1] if link: torr_downloader = TorrentDownloader(urllib.unquote(link), None, settings) path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.choice') return filesystem.exists(path) return False
def show_files(self): if self.files: return self.files = pyxbmct.List("font14") self.placeControl(self.files, 0, 0) cursel = self.list.getSelectedItem() debug(cursel.getLabel()) link = cursel.getProperty("link") match = re.search("torrent=(.+)&", str(link)) if not match: pattern2 = "torrent=(.+)" match = re.search(pattern2, str(link)) if match: link = match.group(1) self.list.setVisible(False) tempPath = xbmc.translatePath("special://temp").decode("utf-8") from downloader import TorrentDownloader import player settings = self.settings import urllib torr_downloader = TorrentDownloader(urllib.unquote(link), tempPath, settings) path = filesystem.join( settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + ".torrent" ) if not filesystem.exists(path): torr_downloader.download() path = torr_downloader.get_filename() debug(path) if filesystem.exists(path): import base player = base.TorrentPlayer() player.AddTorrent(path) data = player.GetLastTorrentData() if data: for f in data["files"]: li = xbmcgui.ListItem(f["name"]) li.setProperty("index", str(f["index"])) self.files.addItem(li) self.setFocus(self.files) self.connect(self.files, self.select_file)
def get_path_or_url_and_episode(settings, params, torrent_source): tempPath = xbmc.translatePath('special://temp').decode('utf-8') from downloader import TorrentDownloader torr_downloader = TorrentDownloader(urllib.unquote(torrent_source), tempPath, settings) path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.torrent') if not filesystem.exists(path): if not torr_downloader.start(): return None torr_downloader.move_file_to(path) torr_downloader = None return {'path_or_url': path, 'episode': params.get('episodeNumber', None), 'downloader': torr_downloader}
def show_menu(self): if self.left_menu: return self.left_menu = pyxbmct.List('font14') self.placeControl(self.left_menu, 0, 0) link = self.cursel_link() self.list.setVisible(False) #path = self.download_torrent(link) #choice_path = path.replace('.torrent', '.choice') from downloader import TorrentDownloader import urllib torr_downloader = TorrentDownloader(urllib.unquote(link), None, self.settings) choice_path = filesystem.join( self.settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.choice') # +++ if self.settings.copy_torrent_path: li = xbmcgui.ListItem(u'Копировать торрент') li.setProperty('link', link) #li.setProperty('path', path) li.setProperty('action', 'copy_torrent') self.left_menu.addItem(li) if filesystem.exists(choice_path): li = xbmcgui.ListItem(u'Отменить выбор') li.setProperty('link', link) li.setProperty('path', choice_path) li.setProperty('action', 'cancel_choice') else: li = xbmcgui.ListItem(u'Запомнить выбор') li.setProperty('link', link) li.setProperty('path', choice_path) li.setProperty('action', 'remember_choice') self.left_menu.addItem(li) # +++ self.setFocus(self.left_menu) self.connect(self.left_menu, self.select_menu_item)
def download_torrent(self, link): tempPath = xbmc.translatePath('special://temp').decode('utf-8') from downloader import TorrentDownloader import player settings = self.settings import urllib torr_downloader = TorrentDownloader(urllib.unquote(link), tempPath, settings) path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.torrent') if not filesystem.exists(path): torr_downloader.download() path = torr_downloader.get_filename() debug(path) return path