Ejemplo n.º 1
0
 def magnet_filename(self, chosen_show=None):
     se_ep = tu.sxxexx(self.season, self.episode)
     if se_ep:
         fullname = '%s %s.magnet' % (self.show_name, se_ep)
         fullname = fullname.replace(' ', '_')
     else:
         show_fname = self.show_name
         for f in self.episodes:
             if chosen_show == f[5]:
                 show_fname = tu.clean_filename(f[0], strict=True)
         fullname = '%s.magnet' % (show_fname)
     return fullname
Ejemplo n.º 2
0
 def magnet_filename(self, chosen_show=None):
     se_ep = tu.sxxexx(self.season, self.episode)
     if se_ep:
         fullname = '%s %s.magnet' % (self.show_name, se_ep)
         fullname = fullname.replace(' ', '_')
     else:
         show_fname = self.show_name
         for f in self.episodes:
             if chosen_show == f[5]:
                 show_fname = tu.clean_filename(f[0], strict=True)
         fullname = '%s.magnet' % (show_fname)
     return fullname
Ejemplo n.º 3
0
    def download(self, chosen_show, destination, search_type='torrent'):
        """
        Pass the chosen show's data and destination to the providers
        download method and return the name of the file downloaded
        back to get-nzb.v2.py
        """
        downloaded_filename = ''
        if chosen_show.startswith("magnet:"):

            # write magnet links to a file
            if Config.magnet_dir:
                Config.magnet_dir = os.path.expanduser(Config.magnet_dir)
                fn = self.magnet_filename(chosen_show)
                if os.path.isdir(Config.magnet_dir):
                    full = os.path.join(Config.magnet_dir, fn)
                    with open(full, 'w') as f:
                        f.write(chosen_show)
                else:
                    sys.exit('\n"%s" does not exist' % Config.magnet_dir)

            # use a command specified in config.ini
            elif Config.client:
                args = self.config_command(chosen_show)
                try:
                    subprocess.Popen(args)
                except FileNotFoundError:
                    sys.exit('\n"%s" not found.' % args[0])

            elif platform.system() == 'Linux':
                err_msg = tu.format_paragraphs('''
                    You do not have a default handler for magnet
                    links.  Either install a bittorent client or
                    configure the "magnet folder" or "client"
                    settings in config.ini.''')

                isX = True if os.environ.get('DISPLAY') else False
                if isX:
                    app = 'xdg-open'
                else:
                    click.echo()
                    sys.exit(err_msg)

                try:
                    subprocess.Popen([app, chosen_show],
                                     stderr=subprocess.DEVNULL,
                                     stdout=subprocess.DEVNULL)
                except OSError:
                    click.echo()
                    sys.exit(err_msg)

            elif platform.system() == 'Darwin':
                subprocess.Popen(["open", "--background", chosen_show])

            elif platform.system() == 'Windows':
                os.startfile(chosen_show)

            else:
                unknown_system = platform.platform()
                sys.exit('\nUnknown system:', unknown_system)

        else:  # is a nzb file
            final_name = ''

            show_fname = 'unknown'
            for f in self.episodes:
                if chosen_show == f[4]:
                    show_fname = tu.clean_filename(f[0], strict=True)
            final_name = '%s.nzb' % (show_fname)

            idx, guid = chosen_show.split('|')
            downloader = self.newsgroup_engines[int(idx)]
            downloaded_filename = downloader.download(guid, destination,
                                                      final_name)

        return downloaded_filename
Ejemplo n.º 4
0
    def download(self, chosen_show, destination, search_type='torrent'):
        """
        Pass the chosen show's data and destination to the providers
        download method and return the name of the file downloaded
        back to get-nzb.v2.py
        """
        downloaded_filename = ''
        if chosen_show.startswith("magnet:"):

            # write magnet links to a file
            if Config.magnet_dir:
                Config.magnet_dir = os.path.expanduser(Config.magnet_dir)
                fn = self.magnet_filename(chosen_show)
                if os.path.isdir(Config.magnet_dir):
                    full = os.path.join(Config.magnet_dir, fn)
                    with open(full, 'w') as f:
                        f.write(chosen_show)
                else:
                    sys.exit('\n"%s" does not exist' % Config.magnet_dir)

            # use a command specified in config.ini
            elif Config.client:
                args = self.config_command(chosen_show)
                try:
                    subprocess.Popen(args)
                except FileNotFoundError:
                    sys.exit('\n"%s" not found.' % args[0])

            elif platform.system() == 'Linux':
                err_msg = tu.format_paragraphs('''
                    You do not have a default handler for magnet
                    links.  Either install a bittorent client or
                    configure the "magnet folder" or "client"
                    settings in config.ini.''')

                isX = True if os.environ.get('DISPLAY') else False
                if isX:
                    app = 'xdg-open'
                else:
                    click.echo()
                    sys.exit(err_msg)

                try:
                    subprocess.Popen([app, chosen_show],
                                     stderr=subprocess.DEVNULL,
                                     stdout=subprocess.DEVNULL)
                except OSError:
                    click.echo()
                    sys.exit(err_msg)

            elif platform.system() == 'Darwin':
                subprocess.Popen(["open", "--background", chosen_show])

            elif platform.system() == 'Windows':
                os.startfile(chosen_show)

            else:
                unknown_system = platform.platform()
                sys.exit('\nUnknown system:', unknown_system)

        else:  # is a nzb file
            final_name = ''

            show_fname = 'unknown'
            for f in self.episodes:
                if chosen_show == f[4]:
                    show_fname = tu.clean_filename(f[0], strict=True)
            final_name = '%s.nzb' % (show_fname)

            idx, guid = chosen_show.split('|')
            downloader = self.newsgroup_engines[int(idx)]
            downloaded_filename = downloader.download(
                guid, destination, final_name)

        return downloaded_filename