Search for a list of subtitles in opensubtitles.org

@param string $userToken
@param string $movieToken
@param int    $fileSize

@return array
973436
private function searchSubtitles($userToken, $movieToken, $fileSize)
    {
        $request  = xmlrpc_encode_request(
            "SearchSubtitles",
            array(
                $userToken,
                array(
                    array('sublanguageid' => $this->lang, 'moviehash' => $movieToken, 'moviebytesize' => $fileSize)
                )
            )
        );
        $response = $this->generateResponse($request);
        if (($response && xmlrpc_is_fault($response))) {
            trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
        } else {
            if ($this->isWrongStatus($response)) {
                trigger_error('no login');
            } else {
                return $response;
            }
        }

        return array();
    }
1023712
function(mediator, fileClient) {
    //If there is already a set of subscribers set up, then don't subscribe again.
    if (fileSubscribers) {
      return fileSubscribers;
    }

    fileSubscribers = new MediatorTopicUtility(mediator);
    fileSubscribers.prefix(CONSTANTS.TOPIC_PREFIX).entity(CONSTANTS.FILES_ENTITY_NAME);

    //Setting up subscribers to the file topics.
    _.each(CONSTANTS.TOPICS, function(topicName) {
      if (topicHandlers[topicName]) {
        fileSubscribers.on(topicName, topicHandlers[topicName](fileSubscribers, fileClient));
      }
    });
    return fileSubscribers;
  }
227972
private function handlePlatformBlock(Lexer $lexer, int $useragentPosition, int $childPosition) : int
    {
        $branchStart     = $this->getLocationCoordinates($lexer);
        $branchLocations = [];
        $branchCoverage  = [];

        do {
            $code = $lexer->lex();

            if (self::JSON_STRING === $code) {
                $branchLocations[] = [
                    'start' => $this->getLocationCoordinates($lexer, false, '"' . $lexer->yytext . '"'),
                    'end' => $this->getLocationCoordinates($lexer, true, '"' . $lexer->yytext . '"'),
                ];
                $branchCoverage[] = $this->getCoverageCount(
                    sprintf('u%d::c%d::d::p%s', $useragentPosition, $childPosition, $lexer->yytext),
                    $this->fileCoveredIds
                );
            }
        } while (self::JSON_ARRAY_END !== $code);

        $branchEnd = $this->getLocationCoordinates($lexer, true);

        $this->collectBranch($branchStart, $branchEnd, $branchLocations, $branchCoverage);

        return $lexer->lex();
    }
717763
public function readByUser(int $userId, int $expirationInSeconds, int $limit = null): array
    {
        try {
            /** @var TokenInterface[] $tokens */
            $tokens = parent::readByUser($userId, $expirationInSeconds, $limit);

            // select scope identifiers for tokens
            if (empty($tokens) === false) {
                $schema        = $this->getDatabaseSchema();
                $tokenIdColumn = $schema->getTokensScopesTokenIdentityColumn();
                $scopeIdColumn = $schema->getTokensScopesScopeIdentityColumn();

                $connection = $this->getConnection();
                $query      = $connection->createQueryBuilder();

                $tokenIds = array_keys($tokens);
                $query
                    ->select([$tokenIdColumn, $scopeIdColumn])
                    ->from($schema->getTokensScopesTable())
                    ->where($query->expr()->in($tokenIdColumn, $tokenIds))
                    ->orderBy($tokenIdColumn);

                $statement = $query->execute();
                $statement->setFetchMode(PDO::FETCH_ASSOC);
                $tokenScopePairs = $statement->fetchAll();

                $curTokenId = null;
                $curScopes  = null;
                // set selected scopes to tokens
                foreach ($tokenScopePairs as $pair) {
                    $tokenId = $pair[$tokenIdColumn];
                    $scopeId = $pair[$scopeIdColumn];

                    if ($curTokenId !== $tokenId) {
                        $assignScopes = $curTokenId !== null && empty($curScopes) === false;
                        $assignScopes ? $tokens[$curTokenId]->setScopeIdentifiers($curScopes) : null;
                        $curTokenId = $tokenId;
                        $curScopes  = [$scopeId];

                        continue;
                    }

                    $curScopes[] = $scopeId;
                }
                $curTokenId === null || empty($curScopes) === true ?:
                    $tokens[$curTokenId]->setScopeIdentifiers($curScopes);
            }

            return $tokens;
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (RepositoryException | DBALEx $exception) {
            $message = 'Token reading failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }
1033344
public function processMultiLineDeclaration(File $phpcsFile, $stackPtr, $tokens)
    {
        // We need to work out how far indented the function
        // declaration itself is, so we can work out how far to
        // indent parameters.
        $functionIndent = 0;
        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
            if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) {
                $i++;
                break;
            }
        }

        if ($tokens[$i]['code'] === T_WHITESPACE) {
            $functionIndent = strlen($tokens[$i]['content']);
        }

        // Each line between the parenthesis should be indented 4 spaces.
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
        $lastLine     = $tokens[$openBracket]['line'];
        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
            if ($tokens[$i]['line'] !== $lastLine) {
                if ($tokens[$i]['line'] === $tokens[$closeBracket]['line']) {
                    // Closing brace needs to be indented to the same level
                    // as the function.
                    $expectedIndent = $functionIndent;
                } else {
                    $expectedIndent = ($functionIndent + 4);
                }

                // We changed lines, so this should be a whitespace indent token.
                if ($tokens[$i]['code'] !== T_WHITESPACE) {
                    $foundIndent = 0;
                } else {
                    $foundIndent = strlen($tokens[$i]['content']);
                }

                if ($expectedIndent !== $foundIndent) {
                    $error = "Multi-line function declaration not indented correctly; expected $expectedIndent spaces but found $foundIndent";
                    $phpcsFile->addError($error, $i, 'MultiLineFuncIndent');
                }

                $lastLine = $tokens[$i]['line'];
            }
        }//end for

        if (isset($tokens[$stackPtr]['scope_opener']) === true) {
            // The openning brace needs to be one space away
            // from the closing parenthesis.
            $next = $tokens[($closeBracket + 1)];
            if ($next['code'] !== T_WHITESPACE) {
                $length = 0;
            } elseif ($next['content'] === $phpcsFile->eolChar) {
                $length = 1;
            } else {
                $length = strlen($next['content']);
            }

            if ($length !== 1) {
                $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found ';
                if ($length === -1) {
                    $error .= 'newline';
                } else {
                    $error .= "$length spaces";
                }

                $phpcsFile->addError($error, ($closeBracket + 1), 'MultiLineFuncSpace');

                return;
            }

            // And just in case they do something funny before the brace...
            $next = $phpcsFile->findNext(
                T_WHITESPACE,
                ($closeBracket + 1),
                null,
                true
            );

            if ($next !== false && $tokens[$next]['code'] !== T_OPEN_CURLY_BRACKET) {
                $error = 'There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration';
                $phpcsFile->addError($error, $next, 'MultiLineFuncSpace');
            }
        }//end if

        // The closing parenthesis must be on a new line, even
        // when checking abstract function definitions.
        $prev = $phpcsFile->findPrevious(
            T_WHITESPACE,
            ($closeBracket - 1),
            null,
            true
        );

        if ($tokens[$prev]['line'] === $tokens[$closeBracket]['line']) {
            $error = 'The closing parenthesis of a multi-line function declaration must be on a new line';
            $phpcsFile->addError($error, $closeBracket, 'MultiLineFuncParen');
        }
    }
324233
private static Optional<Token<?>> getTokenFromSeqFile(String authPath, String proxyUserName) throws IOException {
    try (Closer closer = Closer.create()) {
      FileSystem localFs = FileSystem.getLocal(new Configuration());
      SequenceFile.Reader tokenReader =
          closer.register(new SequenceFile.Reader(localFs, new Path(authPath), localFs.getConf()));
      Text key = new Text();
      Token<?> value = new Token<>();
      while (tokenReader.next(key, value)) {
        LOG.info("Found token for " + key);
        if (key.toString().equals(proxyUserName)) {
          return Optional.<Token<?>> of(value);
        }
      }
    }
    return Optional.absent();
  }
199130
protected function parseUseStatements(File $phpCsFile, int $stackPointer): array
    {
        $useStatements = [];
        $tokens = $phpCsFile->getTokens();
        if ($phpCsFile->findPrevious(T_USE, $stackPointer)) {
            $position = $phpCsFile->findPrevious(T_USE, $stackPointer);
            while ($position !== false) {
                $position = $phpCsFile->findPrevious(T_USE, $position);
                if ($position !== false) {
                    $end = $phpCsFile->findEndOfStatement($position);
                    if ($tokens[$position]['type'] === 'T_USE') {
                        $useTokens = array_slice($tokens, $position + 2, $end - $position - 2);
                        $useStatements[] = $this->parseUseParts($useTokens);
                    }
                }
                $position--;
            }
        }

        return $useStatements;
    }
781719
public static function createForUser(string $userToken)
    {
        $httpClientConfigurator = new HttpClientConfigurator();
        $httpClientConfigurator
            ->setApiUserToken($userToken);

        return static::configure($httpClientConfigurator);
    }
1084691
public function parseDictionaryFile($packageHandle, $packageVersion, $path, $kinds)
    {
        if (!$this->filesystem->isFile($path)) {
            throw new UserMessageException(t('Unable to find the file %s', $path));
        }
        $translations = null;
        if ($kinds & (self::DICTIONARY_SOURCE | self::DICTIONARY_LOCALIZED_SOURCE)) {
            try {
                $translations = Translations::fromPoFile($path);
                if (count($translations) === 0) {
                    $translations = null;
                }
            } catch (Exception $x) {
                $translations = null;
            }
        }
        if ($translations === null && ($kinds & self::DICTIONARY_LOCALIZED_COMPILED)) {
            try {
                $translations = Translations::fromMoFile($path);
                if (count($translations) === 0) {
                    $translations = null;
                }
            } catch (Exception $x) {
                $translations = null;
            }
        }
        $result = null;
        if ($translations !== null) {
            $locale = null;
            $localeID = $translations->getLanguage();
            $locale = $localeID ? $this->app->make(LocaleRepository::class)->findApproved($localeID) : null;
            if ($locale === null) {
                if ($kinds & self::DICTIONARY_SOURCE) {
                    $translations->setLanguage($this->app->make('community_translation/sourceLocale'));
                    foreach ($translations as $translation) {
                        $translation->setTranslation('');
                        $translation->setPluralTranslation('');
                    }
                    $result = new Parsed();
                    $result->setSourceStrings($translations);
                }
            } else {
                if ($kinds & (self::DICTIONARY_LOCALIZED_SOURCE | self::DICTIONARY_LOCALIZED_COMPILED)) {
                    $translations->setLanguage($locale->getID());
                    $result = new Parsed();
                    $result->setTranslations($locale, $translations);
                }
            }
        }

        return $result;
    }
468455
public function findRequiredTokens(FinderInterface $finder, array $tokenCollection)
    {
        foreach ($tokenCollection as $fileTokens) {
            if (!$fileTokens->hasTokens()) {
                continue;
            }
            $file = $this->plugin->directory.'/'.$fileTokens->file;

            if (!file_exists($file)) {
                $this->addWarning(sprintf('Skipping validation of missing or optional file: %s', $fileTokens->file));
                continue;
            }

            try {
                $finder->findTokens($file, $fileTokens);
                $this->addMessagesFromTokens($finder->getType(), $fileTokens);
            } catch (\Exception $e) {
                $this->addError($e->getMessage());
            }
        }
    }
996075
function bindSubtituteFnsWithTokens(actions, tokens) {
  return actions.map(function (action) {
    return Object.keys(action).reduce(function (accum, key) {
      // if it is list of sub keys, and is a fn, then bind with tokens
      if (SUBSTITUTED_KEYS.indexOf(key) !== -1 && typeof action[key] === 'function') {
        accum[key] = action[key].bind(null, tokens);
      } else {
        accum[key] = action[key];
      }
      return accum;
    }, {});
  });
}
752877
async function getSubtitles (file) {
  const filename = path.parse(file).name
  return getSubtitlesByFilename(filename)
}
1366788
public function parseContent($content, $filePath)
    {
        $this->lexer->setInput($content);

        $context = new FileContext($filePath);

        try {
            while ($token = $this->lexer->getNext()) {
                $newContext = $context->enterToken($token, $content);

                if ($newContext === null) {
                    throw new TokenException('unexpected token', $token);
                }

                $context = $newContext;
            }
        } catch (TokenException $ex) {
            $at = $ex->getToken()[Lexer::AT];

            throw new MarkupException($ex->getMessage(), $filePath, $at);
        } catch (\Exception $ex) {
            throw new MarkupException($ex->getMessage());
        }

        return $context;
    }
1130353
def get_subtitle_files(inputfile):
    """"""
    srts = []

    for f in inputfile:
        filename = f.split('.')
        filename[-1] = 'srt'
        srt = '.'.join(filename)
        if os.path.isfile(srt):
            srts.append(srt)

    if len(srts) == 0:
        print("[!] No subtitle files were found.")
        return False

    return srts
146071
protected function getPreviewsFromFileVersion($mediaId, $fileVersion, $locale)
    {
        $title = '';
        /*
         * @var FileVersionMeta
         */
        foreach ($fileVersion->getMeta() as $key => $meta) {
            if ($meta->getLocale() == $locale) {
                $title = $meta->getTitle();
                break;
            } elseif (0 == $key) { // fallback title
                $title = $meta->getTitle();
            }
        }

        $mediaFormats = $this->formatManager->getFormats(
            $mediaId,
            $fileVersion->getName(),
            $fileVersion->getStorageOptions(),
            $fileVersion->getVersion(),
            $fileVersion->getSubVersion(),
            $fileVersion->getMimeType()
        );

        foreach ($mediaFormats as $formatName => $formatUrl) {
            if ($formatName == $this->collectionPreviewFormat) {
                return [
                    'url' => $formatUrl,
                    'title' => $title,
                ];
                break;
            }
        }

        return [];
    }
85061
public function getProperties(array $classToken, ?File $file = null): array
    {
        if (!$file) {
            $file = $this->file;
        }

        $properties = [];
        $startPos = $classToken['scope_opener'] ?? 0;
        $tokens = $file->getTokens();

        while (($propertyPos = $file->findNext([T_VARIABLE], $startPos, $classToken['scope_closer'])) > 0) {
            if ($this->isProperty($propertyPos)) {
                $properties[] = substr($tokens[$propertyPos]['content'], 1);
            }

            $startPos = $propertyPos + 1;
        }

        return $properties;
    }
446939
function checkSubtitleFiles(options, fileWithHashes) {
    if (options.verbose) {
        _utils.logger.info('Checking existing subtitles...');
    }
    var promises = [];
    var _iteratorNormalCompletion3 = true;
    var _didIteratorError3 = false;
    var _iteratorError3 = undefined;

    try {
        for (var _iterator3 = fileWithHashes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
            var file = _step3.value;

            promises.push(_utils.fileManager.subtitleExists(options, file));
        }
    } catch (err) {
        _didIteratorError3 = true;
        _iteratorError3 = err;
    } finally {
        try {
            if (!_iteratorNormalCompletion3 && _iterator3.return) {
                _iterator3.return();
            }
        } finally {
            if (_didIteratorError3) {
                throw _iteratorError3;
            }
        }
    }

    return Promise.all(promises);
}