Example #1
0
    def _makeURL(self, result):
        urls = []
        filename = ""
        if result.url.startswith("magnet"):
            try:
                torrent_hash = re.findall(r"urn:btih:([\w]{32,40})", result.url)[0].upper()

                try:
                    torrent_name = re.findall("dn=([^&]+)", result.url)[0]
                except Exception:
                    torrent_name = "NO_DOWNLOAD_NAME"

                if len(torrent_hash) == 32:
                    torrent_hash = b16encode(b32decode(torrent_hash)).upper()

                if not torrent_hash:
                    sickrage.srLogger.error("Unable to extract torrent hash from magnet: " + result.url)
                    return urls, filename

                urls = random.shuffle(
                    [x.format(torrent_hash=torrent_hash, torrent_name=torrent_name) for x in self.btCacheURLS]
                )
            except Exception:
                sickrage.srLogger.error("Unable to extract torrent hash or name from magnet: " + result.url)
                return urls, filename
        else:
            urls = [result.url]

        if self.type == self.TORRENT:
            filename = os.path.join(sickrage.srConfig.TORRENT_DIR, sanitizeFileName(result.name) + "." + self.type)

        elif self.type == self.NZB:
            filename = os.path.join(sickrage.srConfig.NZB_DIR, sanitizeFileName(result.name) + "." + self.type)

        return urls, filename
Example #2
0
    def addDefaultShow(indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)):
            sickrage.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srConfig.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except Exception:
                location = None

            if location:
                showPath = os.path.join(location, sanitizeFileName(name))
                dir_exists = makeDir(showPath)

                if not dir_exists:
                    sickrage.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath)
                    return
                else:
                    chmodAsParent(showPath)

                sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath,
                                              default_status=status,
                                              quality=int(sickrage.srConfig.QUALITY_DEFAULT),
                                              flatten_folders=int(sickrage.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                              paused=sickrage.srConfig.TRAKT_START_PAUSED,
                                              default_status_after=status,
                                              archive=sickrage.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srLogger.warning("There was an error creating the show, no root directory setting found")
                return
Example #3
0
    def addDefaultShow(indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not findCertainShow(sickrage.srCore.SHOWLIST, int(indexer_id)):
            sickrage.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srConfig.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except Exception:
                location = None

            if location:
                showPath = os.path.join(location, sanitizeFileName(name))
                dir_exists = makeDir(showPath)

                if not dir_exists:
                    sickrage.srLogger.warning("Unable to create the folder %s , can't add the show" % showPath)
                    return
                else:
                    chmodAsParent(showPath)

                sickrage.srCore.SHOWQUEUE.addShow(int(indexer), int(indexer_id), showPath,
                                              default_status=status,
                                              quality=int(sickrage.srConfig.QUALITY_DEFAULT),
                                              flatten_folders=int(sickrage.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                              paused=sickrage.srConfig.TRAKT_START_PAUSED,
                                              default_status_after=status,
                                              archive=sickrage.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srLogger.warning("There was an error creating the show, no root directory setting found")
                return
Example #4
0
    def test_encoding(self):
        rootDir = 'C:\\Temp\\TV'
        strings = ['Les Enfants De La T\xe9l\xe9', 'RT� One']

        sickrage.srCore.SYS_ENCODING = None

        try:
            locale.setlocale(locale.LC_ALL, "")
            sickrage.srCore.SYS_ENCODING = locale.getpreferredencoding()
        except (locale.Error, IOError):
            pass

        # For OSes that are poorly configured I'll just randomly force UTF-8
        if not sickrage.srCore.SYS_ENCODING or sickrage.srCore.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
            sickrage.srCore.SYS_ENCODING = 'UTF-8'

        for s in strings:
            show_dir = os.path.join(rootDir, sanitizeFileName(s))
            self.assertIsInstance(show_dir, unicode)
Example #5
0
    def test_encoding(self):
        rootDir = 'C:\\Temp\\TV'
        strings = ['Les Enfants De La T\xe9l\xe9', 'RT� One']

        sickrage.srCore.SYS_ENCODING = None

        try:
            locale.setlocale(locale.LC_ALL, "")
            sickrage.srCore.SYS_ENCODING = locale.getpreferredencoding()
        except (locale.Error, IOError):
            pass

        # For OSes that are poorly configured I'll just randomly force UTF-8
        if not sickrage.srCore.SYS_ENCODING or sickrage.srCore.SYS_ENCODING in (
                'ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
            sickrage.srCore.SYS_ENCODING = 'UTF-8'

        for s in strings:
            show_dir = os.path.join(rootDir, sanitizeFileName(s))
            self.assertIsInstance(show_dir, unicode)