Exemplo n.º 1
0
def snatchEpisode(result, endStatus=SNATCHED):
    """
    Contains the internal logic necessary to actually "snatch" a result that
    has been found.
    
    Returns a bool representing success.
    
    result: SearchResult instance to be snatched.
    endStatus: the episode status that should be used for the episode object once it's snatched.
    """

    # NZBs can be sent straight to SAB or saved to disk
    if result.resultType in ("nzb", "nzbdata"):
        if sickbeard.NZB_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        elif sickbeard.NZB_METHOD == "sabnzbd":
            dlResult = sab.sendNZB(result)
        elif sickbeard.NZB_METHOD == "nzbget":
            dlResult = nzbget.sendNZB(result)
        else:
            logger.log(
                u"Unknown NZB action specified in config: " +
                sickbeard.NZB_METHOD, logger.ERROR)
            dlResult = False

    elif result.resultType == "torrent":

        #this is required for providers that use torrent cache (more than one possibility)
        #like Torrentz. Maybe convert result.url to an array in the future.
        if result.url.count(";") > 0:
            allUrls = result.url.split(";", 3)
            for url in allUrls:
                try:
                    urllib2.urlopen(url)
                    result.url = url
                    break
                except Exception, e:
                    continue

        # torrents are always saved to disk
        if sickbeard.TORRENT_METHOD == "blackhole":
            dlResult = _downloadResult(result)
    # torrents are sending to torrent client
        elif sickbeard.TORRENT_METHOD == "utorrent":
            dlResult = utorrent.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "transmission":
            dlResult = transmission.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "downloadstation":
            dlResult = downloadstation.sendDownload(result)
        elif sickbeard.TORRENT_METHOD == "deluge":
            dlResult = deluge.sendTORRENT(result)
Exemplo n.º 2
0
def snatchEpisode(result, endStatus=SNATCHED):
    """
    Contains the internal logic necessary to actually "snatch" a result that
    has been found.
    
    Returns a bool representing success.
    
    result: SearchResult instance to be snatched.
    endStatus: the episode status that should be used for the episode object once it's snatched.
    """

    # NZBs can be sent straight to SAB or saved to disk
    if result.resultType in ("nzb", "nzbdata"):
        if sickbeard.NZB_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        elif sickbeard.NZB_METHOD == "sabnzbd":
            dlResult = sab.sendNZB(result)
        elif sickbeard.NZB_METHOD == "nzbget":
            dlResult = nzbget.sendNZB(result)
        else:
            logger.log(u"Unknown NZB action specified in config: " + sickbeard.NZB_METHOD, logger.ERROR)
            dlResult = False

    elif result.resultType == "torrent":
        
        #this is required for providers that use torrent cache (more than one possibility)
        #like Torrentz. Maybe convert result.url to an array in the future.
        if result.url.count(";") > 0:
            allUrls = result.url.split(";", 3)
            for url in allUrls:
                try:
                    urllib2.urlopen(url)
                    result.url = url
                    break
                except Exception:
                    continue 
            
        # torrents are always saved to disk
        if sickbeard.TORRENT_METHOD == "blackhole": 
            dlResult = _downloadResult(result)
        # torrents are sending to torrent client
        elif sickbeard.TORRENT_METHOD == "utorrent":
            dlResult = utorrent.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "transmission":
            dlResult = transmission.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "downloadstation":
            dlResult = downloadstation.sendDownload(result)
        elif sickbeard.TORRENT_METHOD == "deluge":
            dlResult = deluge.sendTORRENT(result)
    else:
        logger.log(u"Unknown result type, unable to download it", logger.ERROR)
        dlResult = False

    if dlResult == False:
        return False

    ui.notifications.message('Episode snatched', result.name)

    history.logSnatch(result)

    # don't notify when we re-download an episode
    for curEpObj in result.episodes:
        with curEpObj.lock:
            curEpObj.status = Quality.compositeStatus(endStatus, result.quality)
            curEpObj.saveToDB()

        if curEpObj.status not in Quality.DOWNLOADED:
            notifiers.notify_snatch(curEpObj.prettyName())

    return True
Exemplo n.º 3
0
def snatchEpisode(result, endStatus=SNATCHED):
    """
    Contains the internal logic necessary to actually "snatch" a result that
    has been found.

    Returns a bool representing success.

    result: SearchResult instance to be snatched.
    endStatus: the episode status that should be used for the episode object once it's snatched.
    """

    # NZBs can be sent straight to downloader or saved to disk
    if result.resultType in ("nzb", "nzbdata"):
        if sickbeard.NZB_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        elif sickbeard.NZB_METHOD == "sabnzbd":
            dlResult = sab.sendNZB(result)
        elif sickbeard.NZB_METHOD == "nzbget":
            dlResult = nzbget.sendNZB(result)
        else:
            logger.log(
                u"Unknown NZB action specified in config: " +
                sickbeard.NZB_METHOD, logger.ERROR)
            dlResult = False

    elif result.resultType == "torrent":

        #this is required for providers that use torrent cache (more than one possibility)
        #like Torrentz. Maybe convert result.url to an array in the future.
        if result.url.count(";") > 0:
            allUrls = result.url.split(";", 3)
            for url in allUrls:
                try:
                    urllib2.urlopen(url)
                    result.url = url
                    break
                except Exception:
                    continue

        # torrents are always saved to disk
        if sickbeard.TORRENT_METHOD == "blackhole":
            dlResult = _downloadResult(result)
        # torrents are sending to torrent client
        elif sickbeard.TORRENT_METHOD == "utorrent":
            dlResult = utorrent.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "transmission":
            dlResult = transmission.sendTORRENT(result)
        elif sickbeard.TORRENT_METHOD == "downloadstation":
            dlResult = downloadstation.sendDownload(result)
        elif sickbeard.TORRENT_METHOD == "deluge":
            dlResult = deluge.sendTORRENT(result)
    else:
        logger.log(u"Unknown result type, unable to download it", logger.ERROR)
        dlResult = False

    if dlResult == False:
        return False

    ui.notifications.message('Episode snatched', result.name)

    history.logSnatch(result)

    # don't notify when we re-download an episode
    for curEpObj in result.episodes:
        with curEpObj.lock:
            curEpObj.status = Quality.compositeStatus(endStatus,
                                                      result.quality)
            curEpObj.saveToDB()

        if not curEpObj.show.skip_notices and curEpObj.status not in Quality.DOWNLOADED:
            notifiers.notify_snatch(curEpObj.prettyName())

    return True