承接 aportela/scraper-lyrics 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aportela/scraper-lyrics

最新稳定版本:1.4.2

Composer 安装命令:

composer require aportela/scraper-lyrics

包简介

Custom php lyrics scraper

README 文档

README

Custom php lyrics scraper

Requirements

  • mininum php version 8.4

Install (composer) dependencies:

composer require aportela/scraper-lyrics

WARNING:

Please, to prevent source providers from making changes or banning the operation of this scraper, use it reasonably, caching the results in your own storage or database to avoid repeating the same calls. Also, try not to make several calls per second that could be interpreted as a DDOS attack.

Code example:

<?php

    require "vendor/autoload.php";

    $logger = new \Psr\Log\NullLogger("");

    $cache = null;
    // uncomment the following lines for storing into disk cache the lyrics
    //$cachePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . "cache";
    //$cache = new \aportela\SimpleFSCache\Cache($logger, \aportela\SimpleFSCache\CacheFormat::TXT, $cachePath);
    $lyrics = new \aportela\ScraperLyrics\Lyrics($logger, $cache);

    /**
    Search/Scrap on all providers
    */
    if ($lyrics->scrap(
        "Bohemian Rhapsody",
        "Queen"
    )) {
        echo sprintf(
            "<H1>Title: %s</h1><H2>Artist: %s</H2><H3>Source: %s</H3><PRE>%s</PRE>",
            $lyrics->getTitle(),
            $lyrics->getArtist(),
            $lyrics->getSource(),
            $lyrics->getLyrics()
        );
    }

/**
    Search/Scrap on custom scrap providers
    You can use this method if at some point in the future a provider stops working and you want to ignore scraping with him (which will give an error) in case you previously used the global (scrap) method
*/
if ($lyrics->scrap(
    "Bohemian Rhapsody",
    "Queen",
    [
        \aportela\ScraperLyrics\SourceProvider::SEARCH_ENGINE_DUCKDUCKGO,
        \aportela\ScraperLyrics\SourceProvider::MUSIXMATCH
    ]
)) {
    echo sprintf(
        "<H1>Title: %s</h1><H2>Artist: %s</H2><H3>Source: %s</H3><PRE>%s</PRE>",
        $lyrics->getTitle(),
        $lyrics->getArtist(),
        $lyrics->getSource(),
        $lyrics->getLyrics()
    );
}

/**
    Search/Scrap on custom source provider
    Same as the previous one but for a single source provider
*/

if ($lyrics->scrapFromSourceProvider(
    "Bohemian Rhapsody",
    "Queen",
    \aportela\ScraperLyrics\SourceProvider::SEARCH_ENGINE_DUCKDUCKGO
)) {
    echo sprintf(
        "<H1>Title: %s</h1><H2>Artist: %s</H2><H3>Source: %s</H3><PRE>%s</PRE>",
        $lyrics->getTitle(),
        $lyrics->getArtist(),
        $lyrics->getSource(),
        $lyrics->getLyrics()
    );
}

PHP Composer

统计信息

  • 总下载量: 55
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0-only
  • 更新时间: 2023-09-29