Hongmu Notes
Home Language Notes Back up some PHP code from Yiyun.
Language Notes PHP

Back up some PHP code from Yiyun.

Back up some PHP code from Yiyun.

I conducted some testing and collected a dataset of songs from Yiyun – approximately over 20,000 artists and 10 million songs in total. Naturally, I have deleted all this data; the main purpose was to write some code for research, and I've also backed up the code here.

Collect songs based on singer ID:

 隐藏内容:会员可查看
<?php

$shuju_file = "shuju.txt";
$shuju = @json_decode(@file_get_contents($shuju_file),true);

$id = empty($shuju['id'])?0:$shuju['id'];
$page = empty($shuju['page'])?0:$shuju['page'];


$urls = file_get_contents("songid.txt");
$array = explode(PHP_EOL,$urls);
$api = json_decode(file_get_contents("http://music.4s5.cn/artist/songs?id={$array[$id]}&limit=100&offset={$page}"),true);


echo "<p>当前歌手id:{$array[$id]}----歌手数".count($array)."----当前歌手序号:{$id}---当前歌手歌曲量:{$shuju['total']}---当前采集到歌手歌曲第{$shuju['page']}首</p>";
// die;
// 数据库信息
$host = "localhost"; // 数据库主机名
$username = "music163"; // 数据库用户名
$password = "dDHAHeiCR8rXyb68"; // 数据库密码
$database = "music163"; // 数据库名称

// 创建连接
$conn = new mysqli($host, $username, $password, $database);

// 检查连接是否成功
if ($conn->connect_error) {
  die("连接失败: " . $conn->connect_error);
}

if(!empty($api['songs'])){
    foreach ($api['songs'] as $v){
        // print_r($v);
        insertData($conn, "INSERT INTO `music163`.`hm_song` (`id`, `songid`, `song`) VALUES (NULL, '{$v['id']}', '".addcslashes($v['name'],"'")."');",$v['name']);
    }
}
// 关闭连接
$conn->close();

function insertData($conn, $sql,$name = '') {
  // 执行插入操作
  if ($conn->query($sql) === TRUE) {
    echo "<p style='color:green'>数据入库成功---{$name}"."</p>";
  } else {
    echo "<p style='color:red'>已采集过本歌曲: " . $conn->error ."----{$name}</p>";
  }
}

// die;
$total = $api['total'];
if($shuju['page'] <= $total){
    $shuju['page'] = $shuju['page'] + 100;
    file_put_contents($shuju_file,json_encode([
        'id'  => $shuju['id'],
        'page'  =>  $shuju['page'],
        'total' => $api['total'],
        ]));
    go();
}else if(count($array) >= $shuju['id']){
    $shuju['id']++;
    file_put_contents($shuju_file,json_encode([
        'id'  => $shuju['id'],
        'page'  =>  0,
        'total' => $api['total'],
        ]));
        echo "正在切换歌手.....";
    go();
}else{
    echo "所有歌手采集完成";
}



function go(){
    $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    echo '<meta http-equiv="refresh" content="'.mt_rand(0,1).'; url='.$url.'">';
}

Complete List of Singers' IDs:

两万多个,我就放我百度云吧,不然网页卡成狗
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(Adaptive mobile version) Responsive e-device website PBootCMS template – includes download functionality – 1035

(Adaptive mobile version) Responsive e-device website PBootCMS template – includes download functionality – 1035 Practical Collection pbootcms Template

A responsive PbootCMS website template suitable for both PC and WAP devices, featuring a download function. The modern, tech-oriented design is ideal for electronics companies to showcase their products and download technical documentation. This template helps electronics enterprises present their brands online and attract customers. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 47
(Adaptive mobile version) Responsive high-end food processing enterprise website template (PBootCMS) – Download HTML5 food industry website source code – 0328

(Adaptive mobile version) Responsive high-end food processing enterprise website template (PBootCMS) – Download HTML5 food industry website source code – 0328 Practical Collection pbootcms Template

This premium, adaptive mobile-responsive PbootCMS website template for food processing enterprises is built using HTML5 technology. Its clean and professional design is ideal for food processing companies to showcase their product lines, production environments, and brand strength. It helps food businesses establish a safe and high-end brand image online. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: ww...
👁 38
Uncaught ReferenceError: jQuery is not defined

Uncaught ReferenceError: jQuery is not defined Summary of pitfalls

This error usually indicates that the jQuery library has not been loaded correctly; you need to ensure that the jQuery library is properly included in your HTML file. You can add the following code within the <head> tag of your HTML file to include jQuery: <script src="https://code.jquery.com/jquery-...>
👁 280
Nine Huiyang Needles and Thirteen Ghost Points

Nine Huiyang Needles and Thirteen Ghost Points Hobbies Memo notes

Song of the Nine Needles of Huiyang: The three yin junctions of the Yamen Laogong Palace, the junction of the gushing spring and Taixi River in the middle of the abdomen, and the three-mile convergence of the Huanyang Valley. This is the point of the Nine Needles of Huiyang. Sun Zhenren's Song of Acupuncture at the Thirteen Ghost Acupoints: The disease caused by the evil and insane, there are thirteen acupuncture points that must be identified. The body of the acupuncture is first the ghost palace, and the ghosts believe that all the acupuncture points should be followed one by one, one by one from the beginning, men from the left, women from the right. One needle is for the human being in the ghost palace, and the left needle is for the needle to come out for the right; the second needle is for the name of the ghost to be inserted three points deep under the big nail; the third needle is for the name of the ghost to be inserted two points deep; the fourth needle is for the palm of the hand...
👁 207
Game Software APP Download Website Template 0588

Game Software APP Download Website Template 0588 Practical Collection Yiyou template

An eYouCMS template designed for game, software, and app download websites. Its dynamic, tech-driven design is ideal for showcasing game products, software applications, app downloads, and user reviews, helping software download platforms attract online user traffic. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS (...
👁 60
(Adaptive mobile version) Book and Journal Publishing Website – PBootCMS Template (1036)

(Adaptive mobile version) Book and Journal Publishing Website – PBootCMS Template (1036) Practical Collection pbootcms Template

A PbootCMS website template designed for books, journals, and picture books, compatible with both PC and WAP devices. Its artistic and fresh design makes it ideal for book publishers and picture book brands to showcase their products and brand stories. This template helps publishing organizations attract online readers and enhance their brand image. Template Demo | Installation Instructions | Website Admin Panel: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: P...
👁 46