示例#1
0
    def download(self, url, filename, **kwargs):
        """
        Downloads a file specified

        :param url: Source URL
        :param filename: Target file on filesystem
        :return: True on success, False on failure
        """

        try:
            r = self.get(url, timeout=10, stream=True, **kwargs)
            if r.status_code >= 400:
                return False

            with io.open(filename, 'wb') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)

            chmodAsParent(filename)
        except Exception:
            remove_file_failed(filename)
            return False

        return True
示例#2
0
def get_subtitles_path(video_path):
    if os.path.isabs(sickrage.srCore.srConfig.SUBTITLES_DIR):
        new_subtitles_path = sickrage.srCore.srConfig.SUBTITLES_DIR
    elif sickrage.srCore.srConfig.SUBTITLES_DIR:
        new_subtitles_path = os.path.join(
            os.path.dirname(video_path),
            sickrage.srCore.srConfig.SUBTITLES_DIR)
        dir_exists = makeDir(new_subtitles_path)
        if not dir_exists:
            sickrage.srCore.srLogger.error(
                'Unable to create subtitles folder {}'.format(
                    new_subtitles_path))
        else:
            chmodAsParent(new_subtitles_path)
    else:
        new_subtitles_path = os.path.dirname(video_path)

    try:
        # Encode path to UTF-8 to ensure subliminal support.
        new_subtitles_path = new_subtitles_path.encode('utf-8')
    except UnicodeEncodeError:
        # Fallback to system encoding. This should never happen.
        new_subtitles_path = new_subtitles_path.encode(sickrage.SYS_ENCODING)

    return new_subtitles_path
示例#3
0
def get_subtitles_path(video_path):
    if os.path.isabs(sickrage.app.config.subtitles_dir):
        new_subtitles_path = sickrage.app.config.subtitles_dir
    elif sickrage.app.config.subtitles_dir:
        new_subtitles_path = os.path.join(os.path.dirname(video_path),
                                          sickrage.app.config.subtitles_dir)
        dir_exists = makeDir(new_subtitles_path)
        if not dir_exists:
            sickrage.app.log.error(
                'Unable to create subtitles folder {}'.format(
                    new_subtitles_path))
        else:
            chmodAsParent(new_subtitles_path)
    else:
        new_subtitles_path = os.path.dirname(video_path)

    try:
        # Encode path to UTF-8 to ensure subliminal support.
        new_subtitles_path = new_subtitles_path.encode('utf-8')
    except UnicodeEncodeError:
        # Fallback to system encoding. This should never happen.
        new_subtitles_path = new_subtitles_path.encode(
            sickrage.app.sys_encoding)

    return new_subtitles_path
示例#4
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.srCore.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srCore.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.srCore.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.srCore.srConfig.QUALITY_DEFAULT),
                                                  flatten_folders=int(sickrage.srCore.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                                  paused=sickrage.srCore.srConfig.TRAKT_START_PAUSED,
                                                  default_status_after=status,
                                                  archive=sickrage.srCore.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srCore.srLogger.warning(
                    "There was an error creating the show, no root directory setting found")
                return
示例#5
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.srCore.srLogger.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.srCore.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.srCore.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.srCore.srConfig.QUALITY_DEFAULT),
                                                  flatten_folders=int(sickrage.srCore.srConfig.FLATTEN_FOLDERS_DEFAULT),
                                                  paused=sickrage.srCore.srConfig.TRAKT_START_PAUSED,
                                                  default_status_after=status,
                                                  archive=sickrage.srCore.srConfig.ARCHIVE_DEFAULT)
            else:
                sickrage.srCore.srLogger.warning("There was an error creating the show, no root directory setting found")
                return
示例#6
0
    def update_show_indexer_metadata(self, show_obj):
        if self.show_metadata and show_obj and self._has_show_metadata(show_obj):
            sickrage.app.log.debug(
                "Metadata provider " + self.name + " updating show indexer info metadata file for " + show_obj.name)

            nfo_file_path = self.get_show_file_path(show_obj)

            try:
                with io.open(nfo_file_path, 'rb') as xmlFileObj:
                    showXML = ElementTree(file=xmlFileObj)

                indexerid = showXML.find('id')

                root = showXML.getroot()
                if indexerid is not None:
                    indexerid.text = str(show_obj.indexerid)
                else:
                    SubElement(root, "id").text = str(show_obj.indexerid)

                # Make it purdy
                indentXML(root)

                showXML.write(nfo_file_path, encoding='UTF-8')
                chmodAsParent(nfo_file_path)

                return True
            except IOError as e:
                sickrage.app.log.error(
                    "Unable to write file to " + nfo_file_path + " - are you sure the folder is writable? {}".format(
                        e.message))
示例#7
0
    def addDefaultShow(indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not findCertainShow(int(indexer_id)):
            sickrage.app.log.info("Adding show " + str(indexer_id))
            root_dirs = sickrage.app.config.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.app.log.warning("Unable to create the folder %s , can't add the show" % showPath)
                    return
                else:
                    chmodAsParent(showPath)

                sickrage.app.show_queue.addShow(int(indexer), int(indexer_id), showPath,
                                                default_status=status,
                                                quality=int(sickrage.app.config.quality_default),
                                                flatten_folders=int(sickrage.app.config.flatten_folders_default),
                                                paused=sickrage.app.config.trakt_start_paused,
                                                default_status_after=status,
                                                archive=sickrage.app.config.archive_default)
            else:
                sickrage.app.log.warning(
                    "There was an error creating the show, no root directory setting found")
                return
示例#8
0
    def dumpHTML(data):
        dumpName = os.path.join(sickrage.srCore.srConfig.CACHE_DIR, 'custom_torrent.html')

        try:
            with io.open(dumpName, 'wb') as fileOut:
                fileOut.write(data)
            chmodAsParent(dumpName)
        except IOError as e:
            sickrage.srCore.srLogger.error("Unable to save the file: %s " % repr(e))
            return False
        sickrage.srCore.srLogger.info("Saved custom_torrent html dump %s " % dumpName)
        return True
示例#9
0
    def dumpHTML(data):
        dumpName = os.path.join(sickrage.srCore.srConfig.CACHE_DIR, 'custom_torrent.html')

        try:
            with io.open(dumpName, 'wb') as fileOut:
                fileOut.write(data)
            chmodAsParent(dumpName)
        except IOError as e:
            sickrage.srCore.srLogger.error("Unable to save the file: %s " % repr(e))
            return False
        sickrage.srCore.srLogger.info("Saved custom_torrent html dump %s " % dumpName)
        return True
示例#10
0
def getSubtitlesPath(video_path):
    if os.path.isabs(sickrage.SUBTITLES_DIR):
        new_subtitles_path = sickrage.SUBTITLES_DIR
    elif sickrage.SUBTITLES_DIR:
        new_subtitles_path = os.path.join(os.path.dirname(video_path), sickrage.SUBTITLES_DIR)
        dir_exists = makeDir(new_subtitles_path)
        if not dir_exists:
            sickrage.LOGGER.error('Unable to create subtitles folder ' + new_subtitles_path)
        else:
            chmodAsParent(new_subtitles_path)
    else:
        new_subtitles_path = os.path.join(os.path.dirname(video_path))

    return new_subtitles_path
示例#11
0
def get_subtitles_path(video_path):
    if os.path.isabs(sickrage.app.config.subtitles_dir):
        new_subtitles_path = sickrage.app.config.subtitles_dir
    elif sickrage.app.config.subtitles_dir:
        new_subtitles_path = os.path.join(os.path.dirname(video_path), sickrage.app.config.subtitles_dir)
        dir_exists = makeDir(new_subtitles_path)
        if not dir_exists:
            sickrage.app.log.error('Unable to create subtitles folder {}'.format(new_subtitles_path))
        else:
            chmodAsParent(new_subtitles_path)
    else:
        new_subtitles_path = os.path.dirname(video_path)

    return new_subtitles_path
示例#12
0
    def write_ep_file(self, ep_obj):
        """
        Generates and writes ep_obj's metadata under the given path with the
        given filename root. Uses the episode's name with the extension in
        _ep_nfo_extension.

        ep_obj: TVEpisode object for which to create the metadata

        file_name_path: The file name to use for this metadata. Note that the extension
                will be automatically added based on _ep_nfo_extension. This should
                include an absolute path.

        Note that this method expects that _ep_data will return an ElementTree
        object. If your _ep_data returns data in another format yo'll need to
        override this method.
        """

        data = self._ep_data(ep_obj)

        if not data:
            return False

        nfo_file_path = self.get_episode_file_path(ep_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.srCore.srLogger.debug(
                    "Metadata dir didn't exist, creating it at " +
                    nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.srCore.srLogger.debug("Writing episode nfo file to " +
                                           nfo_file_path)

            nfo_file = io.open(nfo_file_path, 'wb')

            data.write(nfo_file)
            nfo_file.close()
            chmodAsParent(nfo_file_path)
        except IOError as e:
            sickrage.srCore.srLogger.error(
                "Unable to write file to " + nfo_file_path +
                " - are you sure the folder is writable? {}".format(e.message))
            return False

        return True
示例#13
0
def _downloadResult(result):
    """
    Downloads a result to the appropriate black hole folder.

    :param result: SearchResult instance to download.
    :return: boolean, True on success
    """

    resProvider = result.provider
    if resProvider is None:
        sickrage.srCore.srLogger.error(
            "Invalid provider name - this is a coding error, report it please")
        return False

    # nzbs with an URL can just be downloaded from the provider
    if result.resultType == "nzb":
        newResult = resProvider.downloadResult(result)
    # if it's an nzb data result
    elif result.resultType == "nzbdata":

        # get the final file path to the nzb
        fileName = os.path.join(sickrage.srCore.srConfig.NZB_DIR,
                                result.name + ".nzb")

        sickrage.srCore.srLogger.info("Saving NZB to " + fileName)

        newResult = True

        # save the data to disk
        try:
            with io.open(fileName, 'w') as fileOut:
                fileOut.write(result.extraInfo[0])

            chmodAsParent(fileName)

        except EnvironmentError as e:
            sickrage.srCore.srLogger.error(
                "Error trying to save NZB to black hole: {}".format(e.message))
            newResult = False
    elif resProvider.type == "torrent":
        newResult = resProvider.downloadResult(result)
    else:
        sickrage.srCore.srLogger.error(
            "Invalid provider type - this is a coding error, report it please")
        newResult = False

    return newResult
示例#14
0
    def write_show_file(self, show_obj):
        """
        Generates and writes show_obj's metadata under the given path to the
        filename given by get_show_file_path()

        show_obj: TVShow object for which to create the metadata

        path: An absolute or relative path where we should put the file. Note that
                the file name will be the default show_file_name.

        Note that this method expects that _show_data will return an ElementTree
        object. If your _show_data returns data in another format yo'll need to
        override this method.
        """

        data = self._show_data(show_obj)

        if not data:
            return False

        nfo_file_path = self.get_show_file_path(show_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.srCore.srLogger.debug(
                    "Metadata dir didn't exist, creating it at " +
                    nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.srCore.srLogger.debug("Writing show nfo file to " +
                                           nfo_file_path)

            nfo_file = io.open(nfo_file_path, 'wb')

            data.write(nfo_file)
            nfo_file.close()
            chmodAsParent(nfo_file_path)
        except IOError as e:
            sickrage.srCore.srLogger.error(
                "Unable to write file to " + nfo_file_path +
                " - are you sure the folder is writable? {}".format(e.message))
            return False

        return True
示例#15
0
    def write_ep_file(self, ep_obj):
        """
        Generates and writes ep_obj's metadata under the given path with the
        given filename root. Uses the episode's name with the extension in
        _ep_nfo_extension.

        ep_obj: TVEpisode object for which to create the metadata

        file_name_path: The file name to use for this metadata. Note that the extension
                will be automatically added based on _ep_nfo_extension. This should
                include an absolute path.

        Note that this method expects that _ep_data will return an ElementTree
        object. If your _ep_data returns data in another format yo'll need to
        override this method.
        """

        data = self._ep_data(ep_obj)

        if not data:
            return False

        nfo_file_path = self.get_episode_file_path(ep_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.app.log.debug("Metadata dir didn't exist, creating it at " + nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.app.log.debug("Writing episode nfo file to " + nfo_file_path)

            nfo_file = io.open(nfo_file_path, 'wb')

            data.write(nfo_file)
            nfo_file.close()
            chmodAsParent(nfo_file_path)
        except IOError as e:
            sickrage.app.log.error(
                "Unable to write file to " + nfo_file_path + " - are you sure the folder is writable? {}".format(
                    e.message))
            return False

        return True
示例#16
0
    def download(self, url, filename, **kwargs):
        try:
            r = self.get(url, timeout=10, stream=True, **kwargs)
            if r.status_code >= 400:
                return False

            with io.open(filename, 'wb') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)

            chmodAsParent(filename)
        except Exception as e:
            sickrage.app.log.debug("Failed to download file from {} - ERROR: {}".format(url, e.message))
            remove_file_failed(filename)
            return False

        return True
示例#17
0
    def download(self, url, filename, **kwargs):
        try:
            r = self.get(url, timeout=10, stream=True, **kwargs)
            if r.status_code >= 400:
                return False

            with io.open(filename, 'wb') as f:
                for chunk in r.iter_content(chunk_size=1024):
                    if chunk:
                        f.write(chunk)

            chmodAsParent(filename)
        except Exception as e:
            sickrage.app.log.debug("Failed to download file from {} - ERROR: {}".format(url, e.message))
            remove_file_failed(filename)
            return False

        return True
示例#18
0
文件: tivo.py 项目: Creone33/SiCKRAGE
    def write_ep_file(self, ep_obj):
        """
        Generates and writes ep_obj's metadata under the given path with the
        given filename root. Uses the episode's name with the extension in
        _ep_nfo_extension.

        ep_obj: TVEpisode object for which to create the metadata

        file_name_path: The file name to use for this metadata. Note that the extension
                will be automatically added based on _ep_nfo_extension. This should
                include an absolute path.
        """
        data = self._ep_data(ep_obj)

        if not data:
            return False

        nfo_file_path = self.get_episode_file_path(ep_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.app.log.debug(
                    "Metadata dir didn't exist, creating it at " +
                    nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.app.log.debug("Writing episode nfo file to " +
                                   nfo_file_path)

            with io.open(nfo_file_path, 'w') as nfo_file:
                # Calling encode directly, b/c often descriptions have wonky characters.
                nfo_file.write(data.encode("utf-8"))

            chmodAsParent(nfo_file_path)

        except EnvironmentError as e:
            sickrage.app.log.error(
                "Unable to write file to " + nfo_file_path +
                " - are you sure the folder is writable? {}".format(e.message))
            return False

        return True
示例#19
0
    def write_show_file(self, show_obj):
        """
        Generates and writes show_obj's metadata under the given path to the
        filename given by get_show_file_path()

        show_obj: TVShow object for which to create the metadata

        path: An absolute or relative path where we should put the file. Note that
                the file name will be the default show_file_name.

        Note that this method expects that _show_data will return an ElementTree
        object. If your _show_data returns data in another format yo'll need to
        override this method.
        """

        data = self._show_data(show_obj)

        if not data:
            return False

        nfo_file_path = self.get_show_file_path(show_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.app.log.debug("Metadata dir didn't exist, creating it at " + nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.app.log.debug("Writing show nfo file to " + nfo_file_path)

            nfo_file = io.open(nfo_file_path, 'wb')

            data.write(nfo_file)
            nfo_file.close()
            chmodAsParent(nfo_file_path)
        except IOError as e:
            sickrage.app.log.error(
                "Unable to write file to " + nfo_file_path + " - are you sure the folder is writable? {}".format(
                    e.message))
            return False

        return True
示例#20
0
文件: search.py 项目: afctim/SiCKRAGE
def _downloadResult(result):
    """
    Downloads a result to the appropriate black hole folder.

    :param result: SearchResult instance to download.
    :return: boolean, True on success
    """

    resProvider = result.provider
    if resProvider is None:
        sickrage.srCore.srLogger.error("Invalid provider name - this is a coding error, report it please")
        return False

    # nzbs with an URL can just be downloaded from the provider
    if result.resultType == "nzb":
        newResult = resProvider.downloadResult(result)
    # if it's an nzb data result
    elif result.resultType == "nzbdata":

        # get the final file path to the nzb
        fileName = os.path.join(sickrage.srCore.srConfig.NZB_DIR, result.name + ".nzb")

        sickrage.srCore.srLogger.info("Saving NZB to " + fileName)

        newResult = True

        # save the data to disk
        try:
            with io.open(fileName, 'w') as fileOut:
                fileOut.write(result.extraInfo[0])

            chmodAsParent(fileName)

        except EnvironmentError as e:
            sickrage.srCore.srLogger.error("Error trying to save NZB to black hole: {}".format(e.message))
            newResult = False
    elif resProvider.type == "torrent":
        newResult = resProvider.downloadResult(result)
    else:
        sickrage.srCore.srLogger.error("Invalid provider type - this is a coding error, report it please")
        newResult = False

    return newResult
示例#21
0
    def _write_image(self, image_data, image_path, obj=None):
        """
        Saves the data in image_data to the location image_path. Returns True/False
        to represent success or failure.

        image_data: binary image data to write to file
        image_path: file location to save the image to
        """

        # don't bother overwriting it
        if os.path.isfile(image_path):
            sickrage.srCore.srLogger.debug(
                "Image already exists, not downloading")
            return False

        image_dir = os.path.dirname(image_path)

        if not image_data:
            sickrage.srCore.srLogger.debug(
                "Unable to retrieve image to save in %s, skipping" %
                image_path)
            return False

        try:
            if not os.path.isdir(image_dir):
                sickrage.srCore.srLogger.debug(
                    "Metadata dir didn't exist, creating it at " + image_dir)
                os.makedirs(image_dir)
                chmodAsParent(image_dir)

            outFile = io.open(image_path, 'wb')
            outFile.write(image_data)
            outFile.close()
            chmodAsParent(image_path)
        except IOError as e:
            sickrage.srCore.srLogger.error(
                "Unable to write image to " + image_path +
                " - are you sure the show folder is writable? {}".format(
                    e.message))
            return False

        return True
示例#22
0
def save_subtitles(video, subtitles, single=False, directory=None):
    saved_subtitles = []
    for subtitle in subtitles:
        # check content
        if subtitle.content is None:
            sickrage.app.log.debug("Skipping subtitle for %s: no content" %
                                   video.name)
            continue

        # check language
        if subtitle.language in set(s.language for s in saved_subtitles):
            sickrage.app.log.debug(
                "Skipping subtitle for %s: language already saved" %
                video.name)
            continue

        # create subtitle path
        subtitle_path = subliminal.subtitle.get_subtitle_path(
            video.name, None if single else subtitle.language)
        if directory is not None:
            subtitle_path = os.path.join(directory,
                                         os.path.split(subtitle_path)[1])

        # save content as is or in the specified encoding
        sickrage.app.log.debug("Saving subtitle for %s to %s" %
                               (video.name, subtitle_path))
        if subtitle.encoding:
            with io.open(subtitle_path, 'w', encoding=subtitle.encoding) as f:
                f.write(subtitle.text)
        else:
            with io.open(subtitle_path, 'wb') as f:
                f.write(subtitle.content)

        # chmod and set group for the saved subtitle
        chmodAsParent(subtitle_path)
        fixSetGroupID(subtitle_path)

        # check single
        if single:
            break

    return saved_subtitles
示例#23
0
文件: tivo.py 项目: gborri/SiCKRAGE
    def write_ep_file(self, ep_obj):
        """
        Generates and writes ep_obj's metadata under the given path with the
        given filename root. Uses the episode's name with the extension in
        _ep_nfo_extension.

        ep_obj: TVEpisode object for which to create the metadata

        file_name_path: The file name to use for this metadata. Note that the extension
                will be automatically added based on _ep_nfo_extension. This should
                include an absolute path.
        """
        data = self._ep_data(ep_obj)

        if not data:
            return False

        nfo_file_path = self.get_episode_file_path(ep_obj)
        nfo_file_dir = os.path.dirname(nfo_file_path)

        try:
            if not os.path.isdir(nfo_file_dir):
                sickrage.app.log.debug("Metadata dir didn't exist, creating it at " + nfo_file_dir)
                os.makedirs(nfo_file_dir)
                chmodAsParent(nfo_file_dir)

            sickrage.app.log.debug("Writing episode nfo file to " + nfo_file_path)

            with io.open(nfo_file_path, 'w') as nfo_file:
                # Calling encode directly, b/c often descriptions have wonky characters.
                nfo_file.write(data.encode("utf-8"))

            chmodAsParent(nfo_file_path)

        except EnvironmentError as e:
            sickrage.app.log.error(
                "Unable to write file to " + nfo_file_path + " - are you sure the folder is writable? {}".format(
                    e.message))
            return False

        return True
示例#24
0
def get_subtitles_path(video_path):
    if os.path.isabs(sickrage.app.config.subtitles_dir):
        new_subtitles_path = sickrage.app.config.subtitles_dir
    elif sickrage.app.config.subtitles_dir:
        new_subtitles_path = os.path.join(os.path.dirname(video_path), sickrage.app.config.subtitles_dir)
        dir_exists = makeDir(new_subtitles_path)
        if not dir_exists:
            sickrage.app.log.error('Unable to create subtitles folder {}'.format(new_subtitles_path))
        else:
            chmodAsParent(new_subtitles_path)
    else:
        new_subtitles_path = os.path.dirname(video_path)

    try:
        # Encode path to UTF-8 to ensure subliminal support.
        new_subtitles_path = new_subtitles_path.encode('utf-8')
    except UnicodeEncodeError:
        # Fallback to system encoding. This should never happen.
        new_subtitles_path = new_subtitles_path.encode(sickrage.app.sys_encoding)

    return new_subtitles_path
示例#25
0
    def download(self, url, filename, **kwargs):
        """
        Downloads a file specified

        :param url: Source URL
        :param filename: Target file on filesystem
        :return: True on success, False on failure
        """

        try:
            with io.open(filename, 'wb') as fp:
                for chunk in self.get(url, stream=True, **kwargs).iter_content(chunk_size=1024):
                    if chunk:
                        fp.write(chunk)
                        fp.flush()

            chmodAsParent(filename)
        except Exception:
            remove_file_failed(filename)
            return False

        return True
示例#26
0
    def download(self, url, filename, **kwargs):
        """
        Downloads a file specified

        :param url: Source URL
        :param filename: Target file on filesystem
        :return: True on success, False on failure
        """

        try:
            with io.open(filename, 'wb') as fp:
                for chunk in self.get(url, stream=True, **kwargs).iter_content(chunk_size=1024):
                    if chunk:
                        fp.write(chunk)
                        fp.flush()

            chmodAsParent(filename)
        except Exception:
            remove_file_failed(filename)
            return False

        return True
示例#27
0
    def _write_image(self, image_data, image_path, force=False):
        """
        Saves the data in image_data to the location image_path. Returns True/False
        to represent success or failure.

        image_data: binary image data to write to file
        image_path: file location to save the image to
        """

        # don't bother overwriting it
        if os.path.isfile(image_path) and not force:
            sickrage.app.log.debug("Image already exists, not downloading")
            return False

        image_dir = os.path.dirname(image_path)

        if not image_data:
            sickrage.app.log.debug("Unable to retrieve image to save in %s, skipping" % image_path)
            return False

        try:
            if not os.path.isdir(image_dir):
                sickrage.app.log.debug("Metadata dir didn't exist, creating it at " + image_dir)
                os.makedirs(image_dir)
                chmodAsParent(image_dir)

            outFile = io.open(image_path, 'wb')
            outFile.write(image_data)
            outFile.close()
            chmodAsParent(image_path)
        except IOError as e:
            sickrage.app.log.error(
                "Unable to write image to " + image_path + " - are you sure the show folder is writable? {}".format(
                    e.message))
            return False

        return True
示例#28
0
def save_subtitles(video, subtitles, single=False, directory=None):
    saved_subtitles = []
    for subtitle in subtitles:
        # check content
        if subtitle.content is None:
            sickrage.LOGGER.debug("Skipping subtitle for %s: no content" % video.name)
            continue

        # check language
        if subtitle.language in set(s.language for s in saved_subtitles):
            sickrage.LOGGER.debug("Skipping subtitle for %s: language already saved" % video.name)
            continue

        # create subtitle path
        subtitle_path = subliminal.subtitle.get_subtitle_path(video.name, None if single else subtitle.language)
        if directory is not None:
            subtitle_path = os.path.join(directory, os.path.split(subtitle_path)[1])

        # save content as is or in the specified encoding
        sickrage.LOGGER.debug("Saving subtitle for %s to %s" % (video.name, subtitle_path))
        if subtitle.encoding:
            with io.open(subtitle_path, 'w', encoding=subtitle.encoding) as f:
                f.write(subtitle.text)
        else:
            with io.open(subtitle_path, 'wb') as f:
                f.write(subtitle.content)

        # chmod and set group for the saved subtitle
        chmodAsParent(subtitle_path)
        fixSetGroupID(subtitle_path)

        # check single
        if single:
            break

    return saved_subtitles
示例#29
0
文件: search.py 项目: gborri/SiCKRAGE
def _download_result(result):
    """
    Downloads a result to the appropriate black hole folder.

    :param result: SearchResult instance to download.
    :return: boolean, True on success
    """
    downloaded = False

    resProvider = result.provider
    if resProvider is None:
        sickrage.app.log.error("Invalid provider name - this is a coding error, report it please")
        return False

    filename = resProvider.make_filename(result.name)

    # Support for Jackett/TorzNab
    if result.url.endswith('torrent') and filename.endswith('nzb'):
        filename = filename.rsplit('.', 1)[0] + '.' + 'torrent'

    # nzbs with an URL can just be downloaded from the provider
    if result.resultType == "nzb":
        result = _verify_result(result)
        if result.content:
            sickrage.app.log.info("Saving NZB to " + filename)

            # write content to torrent file
            with io.open(filename, 'wb') as f:
                f.write(result.content)

            downloaded = True
    # if it's an nzb data result
    elif result.resultType == "nzbdata":
        # get the final file path to the nzb
        filename = os.path.join(sickrage.app.config.nzb_dir, result.name + ".nzb")

        sickrage.app.log.info("Saving NZB to " + filename)

        # save the data to disk
        try:
            with io.open(filename, 'w') as fileOut:
                fileOut.write(result.extraInfo[0])

            chmodAsParent(filename)

            downloaded = True
        except EnvironmentError as e:
            sickrage.app.log.error("Error trying to save NZB to black hole: {}".format(e.message))
    elif result.resultType == "torrent":
        result = _verify_result(result)
        if result.content:
            sickrage.app.log.info("Saving TORRENT to " + filename)

            # write content to torrent file
            with io.open(filename, 'wb') as f:
                f.write(result.content)

            downloaded = True
    else:
        sickrage.app.log.error("Invalid provider type - this is a coding error, report it please")

    return downloaded
示例#30
0
def _download_result(result):
    """
    Downloads a result to the appropriate black hole folder.

    :param result: SearchResult instance to download.
    :return: boolean, True on success
    """
    downloaded = False

    resProvider = result.provider
    if resProvider is None:
        sickrage.app.log.error(
            "Invalid provider name - this is a coding error, report it please")
        return False

    filename = resProvider.make_filename(result.name)

    # Support for Jackett/TorzNab
    if result.url.endswith('torrent') and filename.endswith('nzb'):
        filename = filename.rsplit('.', 1)[0] + '.' + 'torrent'

    # nzbs with an URL can just be downloaded from the provider
    if result.resultType == "nzb":
        result = _verify_result(result)
        if result.content:
            sickrage.app.log.info("Saving NZB to " + filename)

            # write content to torrent file
            with io.open(filename, 'wb') as f:
                f.write(result.content)

            downloaded = True
    # if it's an nzb data result
    elif result.resultType == "nzbdata":
        # get the final file path to the nzb
        filename = os.path.join(sickrage.app.config.nzb_dir,
                                result.name + ".nzb")

        sickrage.app.log.info("Saving NZB to " + filename)

        # save the data to disk
        try:
            with io.open(filename, 'w') as fileOut:
                fileOut.write(result.extraInfo[0])

            chmodAsParent(filename)

            downloaded = True
        except EnvironmentError as e:
            sickrage.app.log.error(
                "Error trying to save NZB to black hole: {}".format(e.message))
    elif result.resultType == "torrent":
        result = _verify_result(result)
        if result.content:
            sickrage.app.log.info("Saving TORRENT to " + filename)

            # write content to torrent file
            with io.open(filename, 'wb') as f:
                f.write(result.content)

            downloaded = True
    else:
        sickrage.app.log.error(
            "Invalid provider type - this is a coding error, report it please")

    return downloaded