A method for preventing m3u8 videos from being downloaded in batches
By using cookies and encryption technology in video playback, recording the user's video clip request sequence number and timestamp, and rewriting the URL, the problem of m3u8 videos being downloaded concurrently in batches is solved, the security of the video is improved, and illegal sharing is prevented.
Patent Information
- Application Number
- CN202211521521.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-30
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-11-30
AI Technical Summary
Existing technology cannot effectively prevent m3u8 videos from being downloaded in batches concurrently, resulting in illegal sharing of videos, and it is difficult to identify fake HTTP requests.
By using cookies and encryption technology, setting the cookie information of the hls_token attribute, recording the user's video clip request sequence number and timestamp, judging concurrent requests, and rewriting the original URL, it is difficult to automatically assemble video files.
It significantly increases the cost of illegal theft and prevents videos from being illegally shared. Through cookie encryption and URL rewriting, it prevents forged requests and automatic downloads to ensure the security of videos.
Smart Images

Figure CN116233499B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of video playback, and in particular to a method for preventing m3u8 videos from being downloaded in batches concurrently. Background Art
[0002] In recent years, with the widespread development of broadband technology and mobile Internet technology, more and more users watch online videos through devices such as mobile phones, PCs and tablets.
[0003] The online video playback technology has also developed from the early RTSP and RTMP to the video streaming technology based on HTTP, such as the HTTP progressive download first promoted by YouTube and Smooth Streaming promoted by Microsoft. With the rise of iPhone and iPad in the field of mobile terminals, Apple launched the HTTP Live Streaming solution in 2017. Its architecture is simple and easy to implement, and it supports both on-demand and live playback. The client can also dynamically obtain the corresponding video code stream according to the changes in network bandwidth, so that video playback can overcome the jitter of network bandwidth, thereby improving customer experience. Because of the above advantages, HTTP Live Streaming has gradually become one of the mainstream video online playback protocols. At the same time, its terminal technology is accepted by HTML5, and all mainstream browsers support the playback of HTTP Live Streaming videos by default. Therefore, HTTP Live Streaming has gradually been adopted by major online network video operators.
[0004] When using HTTP Live Streaming to play videos, you usually need to provide an m3u8 file on the server side, such as Figure 1 As shown, the content contains the URLs of all video segments corresponding to the video. Among them, EXT-X-TARGETDURATION specifies the maximum duration of the media segment, and each EXTINF defines the duration of a specific media segment in seconds.
[0005] After the client player obtains the m3u8 file, it extracts the URL of the video segment from each EXTINF segment, and then obtains these media segments from the server. After receiving the server response, it decodes and plays. The player then obtains the next video segment based on the m3u8 file.
[0006] Since m3u8 itself and each URL in the m3u8 file are in plain text, some users can concurrently and batch obtain video clips from the server according to the URL list in the m3u8 file for some purposes, and assemble them into independent video files locally, and illegally share them with other users, causing losses to video operators, video copyright holders, etc. At present, there are many m3u8 browser download plug-ins on the Internet. Users can enter the m3u8 URL, a 1-hour high-definition video, and complete the download and reassembly of all video clips within half a minute through the 4G network, and then illegally share the assembled complete video file with other users, with extremely low illegal costs.
[0007] Currently, the server side of the industry usually distinguishes between normal playback requests and batch download requests by judging the referer or custom HTTP header in the HTTP request. However, for some users, they can forge HTTP headers based on the value of the header in the normal playback request to deceive the server's trust.
[0008] At the same time, the streaming media servers at the back end of large network video operators are usually deployed in clusters. Video playback requests from different users, as well as playback requests from the same user for different video segments of the same content, will be randomly assigned to different streaming media servers in the cluster in a load balancing manner. The server does not save user session information, so it is difficult for each individual server to identify users' concurrent and batch download requests.
[0009] To address this problem, the present application proposes a method for preventing m3u8 videos from being downloaded in batches concurrently, thereby preventing the videos from being illegally stolen. Summary of the invention
[0010] Aiming at the deficiencies in the prior art, the present invention provides a method for preventing m3u8 videos from being downloaded in batches concurrently. By utilizing cookies and encryption technology, users are unable to download in batches and automatically assemble video clip files from a server by forging HTTP requests, which greatly increases the illegal costs of users and prevents videos from being illegally stolen.
[0011] To achieve the above object, the present invention adopts the following technical solutions:
[0012] A method for preventing m3u8 videos from being downloaded in batches concurrently comprises the following steps:
[0013] S1: Video service provider publishes video content to the server;
[0014] S2: When the user plays the video, the client browser requests the server to obtain the m3u8 file;
[0015] S3: The server returns the m3u8 file to the client browser and sets Cookie information for the client browser;
[0016] S4: The client browser parses the m3u8 file, and then initiates an HTTP request to the server for a video clip to be played, carrying cookie information;
[0017] S5: The server obtains the cookie information, decrypts it to obtain the plain text, determines whether the currently processed server needs to be adjusted, and then makes the corresponding server respond to the corresponding HTTP request;
[0018] S6: After verifying and updating the information recorded in the Cookie information, the corresponding server returns the video clip content file required by the user and the updated Cookie information to the client browser;
[0019] S7: loop the contents of steps S4-S6 to complete the playback of the entire video content.
[0020] To optimize the above technical solutions, the specific measures taken also include:
[0021] Furthermore, the specific content of step S1 is: the video service provider rewrites the URL of each video clip in the m3u8 file, and then synchronizes the corresponding relationship between all rewritten URL's and the original URL together with the video file to each server in the video server cluster.
[0022] Furthermore, the specific content of step S2 is: the client browser initiates an HTTP request to the video server cluster, and the load balancer of the video server cluster routes the user's request to a server in the cluster, and the server responds to the request of the client browser.
[0023] Furthermore, the specific content of step S3 is:
[0024] The corresponding server returns the corresponding m3u8 file to the client browser. At the same time, the server sets Cookie information for the client browser. The file format is:
[0025] hls_token=[uid, ver, server_info, video_seq_no_queue, timestamp_queue]
[0026] In the formula, hls_token is represented as the attribute name; [...] is represented as the attribute value, where the value of uid is the unique ID that identifies the video played by the user this time; ver represents the version of the token generation algorithm, which is used to encrypt the cookie information to prevent malicious users from cracking the cookie information to find the server information and then obtain the video data. At the same time, the token algorithm will be updated from time to time. After the server updates the algorithm, a buffer period is set. During the buffer period, the server still supports the processing of the old generation algorithm token; server_info is the server information that records the setting of cookie information, including the server IP and server ID; video_seq_no_queue records the url′ sequence number of the video clips requested to be played by the client browser for the last n times in the m3u8 file; timestamp_queue records the local time when the client browser’s last n video clip requests were processed on the server side;
[0027] After being encrypted by the ver token generation algorithm, the format of the Cookie information is as follows: hls_token = XXXXX, where XXXXX is the encrypted Cookie information attribute value, and when the server feeds back the Cookie information to the client server for the first time, the internal video_seq_no_queue and timestamp_queue are both empty values.
[0028] Furthermore, the specific content of step S5 is:
[0029] The load balancer of the video server cluster distributes the client request to a server in the cluster. The server obtains the value of hls_token in the cookie information, decrypts it to obtain the plain text, and determines whether the server id and ip in server_info are the information of the current server. If so, it starts to process the HTTP request. Otherwise, it redirects the client request to the server corresponding to server_info through HTTP302 redirection.
[0030] Furthermore, the specific content of step S6 is:
[0031] The server obtains the video_seq_no_queue and timestamp_queue parameters in the cookie information;
[0032] When the length of the video_seq_no_queue queue is less than n, the server directly updates the video segment url′ sequence number and server local timestamp requested this time to the video_seq_no_queue and timestamp_queue queues in the cookie information, and returns the cookie information to the client browser. At the same time, according to the corresponding relationship between url and url′, the correct video segment content file is also returned to the client browser for playback;
[0033] When the length of the video_seq_no_queue queue is equal to n, the server determines whether the difference between the current local time and the first timestamp recorded in the timestamp_queue is less than the time of a video clip; if it is, the client's request is rejected; otherwise, the request is responded to normally, and the video clip url′ number and the server local timestamp requested this time are updated to the video_seq_no_queue and timestamp_queue queues in the Cookie information, and the Cookie information is returned to the client browser. At the same time, according to the correspondence between url and url′, the correct video clip content is also returned to the client browser for playback.
[0034] A computer-readable storage medium stores a computer program, wherein the computer program enables a computer to execute any of the above methods for preventing m3u8 videos from being downloaded in batches concurrently.
[0035] An electronic device comprises: a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for preventing m3u8 videos from being downloaded in batches concurrently as described in any one of the above items is implemented.
[0036] The beneficial effects of the present invention are:
[0037] 1. Through Cookie technology, the serial number and timestamp of the video segment requested by the client are written into Cookie. The server compares the video segment currently requested by the client with the segments requested in the past, so as to determine whether it is a normal playback request or the client is using tools to download concurrent batches of video clips. The server denies service to abnormal requests and encrypts the Cookie content, which cannot be forged by users, further preventing the video content from being stolen.
[0038] 2. Change the URLs of the video clips in m3u8 so that the client tool cannot find the file pattern and it is difficult to automatically splice them into separate video files. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is an example diagram of the m3u8 file format proposed in the background technology of this application.
[0040] Figure 2 It is a flowchart of the overall technical solution of this application. DETAILED DESCRIPTION
[0041] The present invention will now be described in further detail with reference to the accompanying drawings.
[0042] refer to Figure 1 and Figure 2 , the overall idea of this application is:
[0043] 1. In the same time period, limit the response to concurrent HTTP requests for video segments from the same client. For example, within the duration of each video segment (for example, within 20 seconds), respond to at most three concurrent requests for consecutive video segments from the same client. The number of responses to concurrent requests here is configurable. In this way, the client cannot use the tool to concurrently and batch download video segments. The specific implementation method is to record the sequence numbers of the video segments of the three most recent requests in m3u8 and the timestamps of the server's responses in Cookies. Each HTTP request carries the same Cookie. The server compares the sequence number of the segment currently obtained by the client and the current local time with the processed sequence number and time in the Cookie, and then determines whether it is a normal playback request from the browser or an illegal request from the user using a dedicated download tool.
[0044] 2. Avoid exposing the original video clip URL directly to the client. When the content management system publishes the m3u8 file, each video URL is randomly rewritten, and the mapping relationship between the original URL and the rewritten URL is configured on the video server. In this way, because each URL has no regularity, the file name after the tool downloads has no regularity, and finally, it is more difficult for the client to automatically assemble the video clips.
[0045] The following is described with specific embodiments:
[0046] 1. The content management system of the video service provider publishes content to the video server. The content management system rewrites the URL of each video clip in the m3u8 file, especially the file name of the ts or mp4 file;
[0047] For example: "http: / / example.com / movie1 / fileSequenceA.ts"
[0048] Rewrite it to "http: / / example.com / movie1 / kdadasiw32ds.ts". All the correspondence between the rewritten URL and the original URL, together with the video file, are synchronized to each server in the video server cluster.
[0049] 2. The user starts playing the video, and the client browser obtains the m3u8 file from the server. The user's browser obtains the URL of the video's m3u8 file from the video web page and initiates an HTTP request to the video server cluster. The load balancer of the video server cluster routes the user's request to a server in the cluster according to the pre-configured load balancing strategy, and the server responds to the browser's request.
[0050] 3. The server returns the m3u8 file to the client browser. The server returns the corresponding file to the client browser according to the URL of the m3u8. At the same time, the server sets a cookie for the client. The attribute name can be set to hls_token, and the value format is "hls_token = [uid, ver, server_info, video_seq_no_queue, timestamp_queue]". Among them, the value of uid is GUID, which is the ID that uniquely identifies the user's video playback this time, and is a 128-bit globally unique identifier; ver represents the version of the token generation algorithm. To prevent users from cracking the token algorithm, the token algorithm will be updated irregularly. After the server updates the algorithm, it will set a buffer period, such as 2 hours. During the buffer period, the processing of the token generated by the old algorithm is still supported. Outside the buffer period, the server directly rejects the client's request; server_info is the information of the server that sets the cookie, including the IP and server ID; video_seq_no_queue is the sequence number of the video clips requested by the player for the last three times in m3u8; timestamp_queue is the local time when the player's last three video clip requests were processed on the server side. The entire token attribute value is encrypted, and the encryption algorithm can also be updated with the update of the token algorithm. For example, the sample of the cookie attribute value is "hls_token = [6F9619FF-8B86-D011-B42D-00C04FC964FF, 5, 128.7.2.203server1, [5, 6, 7], [FriJan10202018:52:45GMT+0800, 60, FriJan10202018:52:55GMT+0800, 60, FriJan10202018:52:65GMT+0800, 60]]". After encryption, the format of the cookie is as follows: hls_token = XXXXX, where XXXXX is the encrypted cookie attribute value. In the HTTP response corresponding to the m3u8 file, video_seq_no_queue and timestamp_queue in hls_token are both empty.
[0051] 4. The client browser parses the m3u8 file and then initiates an HTTP Get request to the server to obtain the first video segment. The HTTP request carries the hls_tokenCookie.
[0052] 5. The load balancer of the server cluster distributes the client request to a server in the cluster. The server obtains the value of hls_token from the HTTP request, decrypts it to obtain the plain text, and determines whether the server id and ip in server_info are local information. If so, it starts to process the HTTP request. Otherwise, it redirects the client request to the server corresponding to server_info through HTTP302 redirection.
[0053] 6. The server corresponding to server_info first obtains the sequence number of the video clip requested by the client in m3u8;
[0054] When the length of the video_seq_no_queue queue is less than 3, the server directly updates the video segment url′ sequence number and server local timestamp requested this time to the video_seq_no_queue and timestamp_queue queues in the cookie information, and returns the cookie information to the client browser. At the same time, according to the corresponding relationship between url and url′, the correct video segment content file is also returned to the client browser for playback;
[0055] When the length of the video_seq_no_queue queue is equal to 3, the server determines whether the difference between the current local time and the first timestamp recorded in the timestamp_queue is less than the time of a video clip; if it is less, the client's request is rejected; otherwise, the request is responded to normally, the video clip url′ number and the server local timestamp requested this time are updated to the video_seq_no_queue and timestamp_queue queues in the Cookie information, and the Cookie information is returned to the client browser. At the same time, according to the correspondence between url and url′, the correct video clip content is also returned to the client browser for playback.
[0056] 7. The client browser obtains the video segment, decodes and plays it, and then carries the same cookie to obtain the next video segment from the server.
[0057] It should be noted that the terms such as "upper", "lower", "left", "right", "front", "back", etc. cited in the invention are only for the convenience of description and are not used to limit the scope of implementation of the present invention. Changes or adjustments in their relative relationships should be regarded as the scope of implementation of the present invention without substantially changing the technical content.
[0058] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.
Claims
1. A method for preventing m3u8 videos from being downloaded in batches concurrently, characterized in that: The following steps are involved: S1: The video service provider publishes the video content to the server. Specifically, the video service provider rewrites the URL of each video clip in the m3u8 file, and then synchronizes the corresponding relationship between all rewritten URLs and the original URLs, together with the video file, to each server in the video server cluster. S2: When the user plays the video, the client browser requests the server to obtain the m3u8 file; S3: The server returns the m3u8 file to the client browser and sets Cookie information for the client browser; S4: The client browser parses the m3u8 file, and then initiates an HTTP request to the server for a video clip to be played, carrying cookie information; S5: The server obtains the cookie information, decrypts it to obtain the plain text, determines whether the currently processed server needs to be adjusted, and then makes the corresponding server respond to the corresponding HTTP request; S6: After verifying and updating the information recorded in the Cookie information, the corresponding server returns the video clip content file required by the user and the updated Cookie information to the client browser; specifically: The server obtains the video_seq_no_queue and timestamp_queue parameters in the cookie information; When the length of the video_seq_no_queue queue is less than n, the server directly updates the video segment url´ sequence number and server local timestamp to the video_seq_no_queue and timestamp_queue queues in the cookie information, and returns the cookie information to the client browser. At the same time, according to the corresponding relationship between url and url´, the correct video segment content file is also returned to the client browser for playback; When the length of video_seq_no_queue is equal to n, the server determines whether the difference between the current local time and the first timestamp recorded in timestamp_queue is less than the time of a video segment; If it is less than, the client's request is rejected; otherwise, the request is responded to normally, the video clip url' sequence number and server local timestamp are updated to the video_seq_no_queue and timestamp_queue queues in the cookie information, and the cookie information is returned to the client browser. At the same time, according to the corresponding relationship between url and url', the correct video clip content is also returned to the client browser for playback. S7: loop the contents of steps S4-S6 to complete the playback of the entire video content.
2. A method for preventing m3u8 videos from being downloaded in batches concurrently according to claim 1, characterized in that: The specific content of step S2 is: the client browser initiates an HTTP request to the video server cluster, and the load balancer of the video server cluster routes the user's request to a server in the cluster, and the server responds to the request of the client browser.
3. A method for preventing m3u8 videos from being downloaded in batches concurrently according to claim 2, characterized in that, The specific content of step S3 is: The corresponding server returns the corresponding m3u8 file to the client browser. At the same time, the server sets Cookie information for the client browser. The file format is: hls_token=[uid, ver, server_info, video_seq_no_queue, timestamp_queue] In the formula, hls_token is represented as the attribute name; [...] is represented as the attribute value, where the value of uid is the unique ID that identifies the video played by the user this time; ver represents the version of the token generation algorithm, which is used to encrypt the cookie information to prevent malicious users from cracking the cookie information to find the server information and then obtain the video data. At the same time, the token algorithm will be updated irregularly. After the server updates the algorithm, a buffer period is set. During the buffer period, the server still supports the processing of the old generation algorithm token; server_info is the server information that records the setting of cookie information, including the server IP and server ID; video_seq_no_queue records the url´ sequence number of the video clips requested to be played by the client browser for the last n times in the m3u8 file; timestamp_queue records the local time when the client browser's last n video clip requests were processed on the server side; After being encrypted by the ver token generation algorithm, the format of the Cookie information is as follows: hls_token=XXXXX, where XXXXX is the attribute value of the encrypted cookie information, and when the server feeds the cookie information back to the client server for the first time, the internal video_seq_no_queue and timestamp_queue are both empty.
4. A method for preventing m3u8 videos from being downloaded in batches concurrently according to claim 3, characterized in that: The specific content of step S5 is: The load balancer of the video server cluster distributes the client request to a server in the cluster. The server obtains the value of hls_token in the cookie information, decrypts it to obtain the plain text, and determines whether the server id and ip in server_info are the information of the current server. If so, it starts to process the HTTP request. Otherwise, it redirects the client request to the server corresponding to server_info through HTTP 302 redirection.
5. A computer-readable storage medium storing a computer program, characterized in that: The computer program enables the computer to execute the method for preventing m3u8 videos from being downloaded in batches concurrently as described in any one of claims 1 to 4.
6. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for preventing m3u8 videos from being downloaded in batches concurrently as described in any one of claims 1 to 4 is implemented.
