春江暮客

春江暮客的个人学习分享网站

Python implementation for Qianqian Music MP3 download

Python implementation for Qianqian Music MP3 download

2019年1月8日 | Miscellaneous

Entering the Qianqian Music homepage and selecting Jay Chou’s “Confession Balloon” reveals that it’s a 2016 song with no preview available, which is sad. Is there a way to get the MP3 file? The answer is yes. A runnable program for music download is available at the end of the article.

Without further ado, I opened the charts and chose a new song that could be previewed; “Sheng Pi Zi” was the first one I could listen to.

Python implementation for Qianqian Music MP3 download

1. Analyze API information

Opening the developer tools, I found that music files are definitely submitted through an API. Among many requests, I found a request that could retrieve music files. See the image below:

Python implementation for Qianqian Music MP3 download

Check the request details:

Python implementation for Qianqian Music MP3 download The songid parameter can be found in the current URL: http://music.taihe.com/song/611238837. It’s simple. from should be “web” or “app”, etc. The format defining the return data type doesn’t need to be changed. method doesn’t need to be changed. The _ parameter is a 13-digit timestamp. callback is the prefix of the returned JSON data. The 1546915161467 after the underscore is a 13-digit timestamp, while the preceding 17200943498528136486 is unknown. We’ll try to use the known parameters to see if we can retrieve information without changing the unknown content.

……

阅读全文

Python implementation for Qianqian Music MP3 download

Python implementation for Qianqian Music MP3 download

2019年1月8日 | Miscellaneous

Entering the Qianqian Music homepage and selecting Jay Chou’s “Confession Balloon” reveals that it’s a 2016 song with no preview available, which is sad. Is there a way to get the MP3 file? The answer is yes. A runnable program for music download is available at the end of the article.

Without further ado, I opened the charts and chose a new song that could be previewed; “Sheng Pi Zi” was the first one I could listen to.

Python implementation for Qianqian Music MP3 download

1. Analyze API information

Opening the developer tools, I found that music files are definitely submitted through an API. Among many requests, I found a request that could retrieve music files. See the image below:

Python implementation for Qianqian Music MP3 download Check the request details:

Python implementation for Qianqian Music MP3 download

The songid parameter can be found in the current URL: http://music.taihe.com/song/611238837. It’s simple. from should be “web” or “app”, etc. The format defining the return data type doesn’t need to be changed. method doesn’t need to be changed. The _ parameter is a 13-digit timestamp. callback is the prefix of the returned JSON data. The 1546915161467 after the underscore is a 13-digit timestamp, while the preceding 17200943498528136486 is unknown. We’ll try to use the known parameters to see if we can retrieve information without changing the unknown content.

……

阅读全文

Mounting an External Hard Drive in Linux

Mounting an External Hard Drive in Linux

2019年1月6日 | Miscellaneous

After a machine restart, the external hard drive wasn’t recognized and needed to be remounted. However, after using fdisk -l, the external hard drive was nowhere to be found, making it impossible to mount.

In practice, this kind of problem usually has two steps: first confirm whether Linux can still see the disk device, then decide whether you can mount it directly or need to rescan the bus so the device appears again.

Mounting an External Hard Drive in Linux

How to Mount a Disk

First, use fdisk -l to check the current hard drive status.

    ➜  ~ fdisk -l 
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

    Disk /dev/sdb: 320.1 GB, 320072933376 bytes, 625142448 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: gpt
    Disk identifier: AF1B577B-830C-4026-AC5F-37870D362B3C

    #         Start         End    Size  Type            Name
    1          2048      411647    200M  EFI System      EFI System Partition
    2        411648     2508799      1G  Microsoft basic
    3       2508800   625141759  296.9G  Linux LVM

    Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk /dev/mapper/centos-swap: 3623 MB, 3623878656 bytes, 7077888 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk /dev/mapper/centos-home: 261.5 GB, 261468717056 bytes, 510681088 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk /dev/sda: 1000.2 GB, 1000170586112 bytes, 1953458176 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x16f2a91f

          Device Boot      Start        End    Blocks  Id  System
    /dev/sda1             1 4294967295 2147483647+ ee  GPT

Here, my external hard drive is 1TB, so I can identify it as /dev/sda1. Then I can mount it with mount:

……

阅读全文

Drawing Violin Plots with Seaborn

Drawing Violin Plots with Seaborn

2019年1月4日 | Technology

Introduction

A violin plot is used to display the distribution and probability density of multiple data groups. Similar to a box plot, it offers a better representation of data density. Violin plots are particularly useful when dealing with very large datasets that are difficult to display individually. Python’s Seaborn package makes it very convenient to create violin plots.

If you only need the median and quartiles, a box plot is often enough. If you also want to see whether the data looks skewed, wide, narrow, or even bimodal, a violin plot is usually more informative.

Parameters

Drawing Violin Plots with Seaborn

The parameters corresponding to each position in a violin plot are shown above. The middle line represents the box plot data, specifically the 25th, 50th (median), and 75th percentiles. The thin lines indicate the 95% confidence interval.

Drawing Violin Plots with Seaborn

Single Variable Data

While a box plot would suffice for a single variable, a violin plot can certainly be used as well:

……

阅读全文

Five Easy Steps to Achieve Linux Passwordless Login

Five Easy Steps to Achieve Linux Passwordless Login

2019年1月2日 | Miscellaneous

SSH, which stands for Secure Shell, is a widely used and reliable program for securely executing commands remotely on Linux systems. SCP, used for secure file transfers, is also based on the SSH security protocol.

When you have many servers, frequently typing passwords can be quite troublesome. So, how can you log in without a password while maintaining security? Of course, it’s possible. Here, we’ll outline five steps to achieve passwordless login for Linux servers such as RHEL/CentOS 7.x/6.x/5.x and Fedora.

The important point is that this does not mean “turning security off.” It means replacing password-based login with SSH key-based authentication, which is usually a better operational choice when your private key is handled properly.

Five Easy Steps to Achieve Linux Passwordless Login

Let’s look at the environment:

    SSH Client : 192.168.1.12 ( Mac )
    SSH Remote Host : 192.168.1.11 ( CentOS 7 )

This article will demonstrate passwordless login from a Mac to a remote CentOS 7 server.

……

阅读全文

The difference between shallow copy and deepcopy in Python

The difference between shallow copy and deepcopy in Python

2018年12月29日 | Technology

In Python, copying objects is common, and a lot of “why did both variables change?” bugs come from mixing up three different operations: assignment, shallow copy, and deep copy.

“The difference between shadowcopy and deepcopy in python”

Among assignment (=), shallow copy (copy), and deep copy (deepcopy), the most confusing part is usually not assignment vs. copy, but whether a shallow copy still shares nested mutable objects.

Assignment does not copy an object. It only binds another variable name to the same object. Because of that, changes seen through one variable are still changes to the same underlying object.

A shallow copy duplicates the outer container, but nested mutable objects may still be shared. A deep copy recursively duplicates nested objects too, so it is usually more isolated.

A practical rule of thumb is:

  • Use assignment when you only want another name for the same object.
  • Use shallow copy when copying the outer container is enough.
  • Use deep copy when nested lists or dictionaries also need to be independent.

Below is a practical code example illustrating the differences among the three.

……

阅读全文

python3 requests module usage examples

python3 requests module usage examples

2018年12月28日 | Technology
This article explains common Python requests usage through examples including GET, POST, headers, authentication, file download, upload, and cookies, with a couple of practical habits that make real scripts more reliable.……

阅读全文

友情链接

其它