I found out by making a python script to record radiko while reading the code of the predecessors

Summary

Tried environment

What I made

https://github.com/1021ky/radiko_recorder

What I found

Protocol called hls used in Radiko

Outline of processing performed when listening to a program on Radiko

It turned out that the client and the server are communicating with each other by HTTP as shown in the figure below.

処理概要.png

How did you find out

Roughly it looks like this. I couldn't go in this order smoothly, and I went back and forth several times.

  1. Read the code written by another person → I understand that authorization processing and audio file acquisition processing are required
  2. Write the code → Call Radiko's API and get HTTP status code 40X, so you know that something is missing
  3. Find out what kind of communication is being done with the developer tools of Google Chrome → Understand that it was insufficient by looking at the specific communication content
  4. After writing the code, I will summarize what I did this time → There were words that I could not explain well → I understand that hls and m3u8 are specified by RFC, not by Radiko's own specifications

I read the code from the following article.

  1. Simple Radiko Recording Script
  2. [Python] Play Radiko
  3. I made a software that automatically searches and records radiko, super A & G, sound spring and sound with Python3
  4. Road to radiko recording (download) Part 1

Since 1 was written in a shell script, I googled the commands I didn't understand and immediately knew what kind of package I needed.

However, I wasn't sure why the pre-processing was done or what it was doing. (The shell power is insufficient.) I was trying to write a few in Python, which I usually use, so it was easy to understand, and I found that the process I didn't understand in the shell script earlier was the authorization process. In 4, I found out how to find out what kind of logic is used to generate the partial key of Radiko's original specifications.

Now that we have the packages and libraries we need, we've written the code. So, as mentioned above, I called Radiko's API and returned an HTTP status code of 40X series, so I investigated what the Chrome developer tools are doing on the browser that fails with my code. The following is when I investigated the authorization process. devtool_auth.png

Looking at the request content, I knew when and where I needed something in the request header that started with X-Radiko-***. When I took a quick look at the code, I had overlooked it. So, it finally started to work.

What I got in the article

What is hls when putting it together? What is m3u8? I wondered again, and when I looked it up, I found that it was decided by RFC. If it was decided by RFC, I also found that there might be a library that makes them easy to handle.

The m3u8 library was easy to use and cleaned up my messy code. Also, reading the RFC and understanding the terms made it easier to name methods and variables. For example, the variables Master Playlist and Media playlist were very appropriate before reading the RFC and had names that were unclear when read again.

A recently read book, Isao Ueda. 101 principles that will be useful for a lifetime that you want to learn by the third year of Principles of Programming.

There is also a saying, "Good programmers write good code, great programmers borrow good code."

There was. When I read it, I had an understanding that I could understand somehow, but this time, I feel that I have deepened my understanding that knowing what is standard will lead to an improvement in level.

Summary

Recommended Posts

I found out by making a python script to record radiko while reading the code of the predecessors
I made a script to record the active window using win32gui of Python
I tried to create a Python script to get the value of a cell in Microsoft Excel
First python ② Try to write code while examining the features of python
I found out by analyzing the reviews of the job change site! ??
I wrote the code to write the code of Brainf * ck in python
I tried to get the authentication code of Qiita API with Python.
I tried to verify and analyze the acceleration of Python by Cython
Python code to determine the monthly signal of a relative strength investment
I made a program to check the size of a file in Python
I tried to verify the result of A / B test by chi-square test
Python: I want to measure the processing time of a function neatly
I made a function to see the movement of a two-dimensional array (Python)
A super introduction to Django by Python beginners! Part 2 I tried using the convenient functions of the template
[You have to know it! ] I tried to set up a Python environment profitably by making full use of the privileges of university students.
I created a script to check if English is entered in the specified position of the JSON file in Python.
[python] How to sort by the Nth Mth element of a multidimensional array
Python script to get a list of input examples for the AtCoder contest
I tried to refactor the code of Python beginner (junior high school student)
I tried to put out the frequent word ranking of LINE talk with Python
I used Python to find out about the role choices of the 51 "Yachts" in the world.
Add a function to tell the weather of today to slack bot (made by python)
Template of python script to read the contents of the file
Get the return code of the Python script from bat
I checked out the versions of Blender and Python
I felt that I ported the Python code to C ++ 98.
Python Note: The mystery of assigning a variable to a variable
I tried to summarize the string operations of Python
A super introduction to Django by Python beginners! Part 6 I tried to implement the login function
I tried to create a RESTful API by connecting the explosive Python framework FastAPI to MySQL.
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I made a class to get the analysis result by MeCab in ndarray with python
[OCI] Python script to get the IP address of a compute instance in Cloud Shell
I made a function to crop the image of python openCV, so please use it.
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
A Python script that allows you to check the status of the server from your browser
When I got a list of study sessions in Python, I found something I wanted to make
I tried to find the entropy of the image with python
I replaced the Windows PowerShell cookbook with a python script.
Find out the apparent width of a string in python
[Python] How to make a list of character strings character by character
I just changed the sample source of Python a little.
I want to start a lot of processes from python
I made a function to check the model of DCGAN
[Python] I tried to visualize the follow relationship of Twitter
Debug by attaching to the Python process of the SSH destination
The process of making Python code object-oriented and improving it
I wrote a script to combine the divided ts files
I want to know the features of Python and pip
[Python] The first step to making a game with Pyxel
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
A Python script that compares the contents of two directories
I tried to remodel the code of Python beginner (junior high school student) into object-oriented crunchy
I wrote AWS Lambda, and I was a little addicted to the default value of Python arguments
I will publish a shell script created to reduce the trouble of creating LiveUSB on Linux
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 1
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 2
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
I tried to summarize the contents of each package saved by Python pip in one line
[Python] How to use the for statement. A method of extracting by specifying a range or conditions.