Exemple #1
0
 /**
  * Returns the next operation that must be ran
  * @return mm\Daemon\Operation
  */
 public function next()
 {
     // maintain count of how many operations of each type are currently running
     // depending on the priority (#1 = downloads, #2 = merge), return the next operation
     // when an operation finishes, the slot is cleaned up, and one more of the same type can resume
     return Queue::getNextItem();
 }
Exemple #2
0
    /**
     * Returns the queue contents with status $status, possibly filtered on $type
     *
     * @param string $status
     * @param string $type
     *
     * @return ezcMvcResult
     */
    public function doQueueContents()
    {
        switch( $this->status )
        {
            case 'archived': $status = QueueItem::STATUS_ARCHIVED; break;
            case 'done':     $status = QueueItem::STATUS_DONE; break;
            case 'error':    $status = QueueItem::STATUS_ERROR; break;
            case 'pending':  $status = QueueItem::STATUS_PENDING; break;
            case 'running':  $status = QueueItem::STATUS_RUNNING; break;
            default: $status = null;
        }

        if ( isset( $this->type ) )
        {
            $type = $this->type;
        }
        else
        {
            $type = null;
        }

        $items = array();
        foreach( Queue::fetchItems( $status, $type ) as $queueItem )
        {
            $item = new stdClass;
            $item->hash = $queueItem->hash;
            $item->title = $queueItem->title;
            $item->progress = $queueItem->progress();
            $items[] = $item;
        }

        $result = new ezcMvcResult;
        $result->variables['status'] = 'ok';
        if ( !count( $items ) )
            $result->variables['message'] = 'no-operation';
        else
            $result->variables['queue'] = $items;
        return $result;
    }
Exemple #3
0
    /**
     * Saves a NFO
     *
     * @param string $this->folder
     * @param string $this->info
     *
     * @return ezcMvcResult
     */
    public function doNfoSave()
    {
        $result = new \ezcMvcResult();

        $result->variables['page_title'] = "{$this->folder} :: Save NFO :: MKV Manager";
        $result->variables['movie'] = $this->folder;

        $basepath =
            ezcConfigurationManager::getInstance()->getSetting( 'movies', 'GeneralSettings', 'SourcePath' ) .
            DIRECTORY_SEPARATOR .
            $this->folder . DIRECTORY_SEPARATOR;
        $nfoFilePath = "{$basepath}{$this->folder}.nfo";
        $posterFilepath = "{$basepath}{$this->folder}.tbn";
        $fanartFilepath = "{$basepath}{$this->folder}-fanart.jpg";
        $trailerFilepath = "{$basepath}{$this->folder}-trailer.flv";

        $nfoWriter = new NfoWriter( $this->info );

        $result->variables['operations'] = array();

        // write NFO to disk
        $nfoWriter->write( $nfoFilePath );
        $operation = Daemon\Queue::add(
            new Operations\NfoWriter( $this->info, $nfoFilePath )
        );
        $result->variables['operations'][] = (object)array(
            'title' => $operation->title,
            'hash' => $operation->hash,
        );

        // trailer
        $operation = Daemon\Queue::add(
            new Operations\HttpDownload( $nfoWriter->getMainPoster(), $posterFilepath )
        );
        $result->variables['operations'][] = (object)array(
            'title' => $operation->title,
            'hash' => $operation->hash,
        );

        // trailer
        $operation = Daemon\Queue::add(
            new Operations\HttpDownload( $nfoWriter->getMainFanart(), $fanartFilepath )
        );
        $result->variables['operations'][] = (object)array(
            'title' => $operation->title,
            'hash' => $operation->hash,
        );

        // trailer
        $operation = Daemon\Queue::add(
            new Operations\HttpDownload( $nfoWriter->getTrailer(), $trailerFilepath )
        );
        $result->variables['operations'][] = (object)array(
            'title' => $operation->title,
            'hash' => $operation->hash,
        );

        return $result;
    }