Last update at :2024-02-07,Edit by888u
I saw some videos from large video websites in other friends’ blog articles. I was greedy for them, so I studied how to parse Youku videos. I think it’s okay to write them directly in HTML, but I still want to Study the short code, for example, use it directly to parse. After several hours of research, I successfully implemented this function. It is estimated that those code experts may complete it in a few minutes, but I still share the solution process.
1. Research the resolution address
I found that Youku’s analysis is relatively simple. First, you have to find a video. The video address is as follows:
http://v.youku.com/v_show/id_XMzkxODc0MDYxNg==.htm
We just need to take out the red part and add the https://player.youku.com/embed/ code in front of it, for example:
https://player.youku.com/embed/XMzkxODc0MDYxNg
Open the above address and you will see the video. This method is shared online.
2. Add short code
We need to add the short code to the function file. The function file of all themes is functions.php, but some themes have very little code in this file and will be parsed to another address. Just look at the code. , we add the following code here:
//Youku video function youku($atts,$content=null,$code=""){ $return = ''; return $return; } add_shortcode('youku','youku'); //Add button function more_button_a(){ if(!current_user_can('edit_posts')&&!current_user_can('edit_pages')) return; if(get_user_option('rich_editing')=='true'){ add_filter('mce_external_plugins','add_plugin'); add_filter('mce_buttons','register_button'); } } add_action('init','more_button_a'); function register_button($buttons){ array_push($buttons," ","youku"); return $buttons; } function add_plugin($plugin_array){ $plugin_array['youku'] = get_bloginfo('template_url').'/buttons/more.js'; return $plugin_array; }This short code has two functions. One is to add a short code to parse the video; the other is to add a button to the article editing window in the background. There is a js behind it, /buttons/more.js. This JS file actually Just call a picture. The two parameters height=”350″ width=”570″ can adjust the height and width of the video. At the same time, with the DIV parameter class="video-container", you can write the style you want in the CSS file. We create a folder named buttons under the theme folder, then create a more.js file and write the following code:
(function() { tinymce.create('tinymce.plugins.youku', { init: function(ed, url) { ed.addButton('youku', { title: 'Youku Video', image : url+'/images/youku.png', onclick : function() { ed.selection.setContent(''); } }); }, createControl : function(n, cm) { return null; }, }); tinymce.PluginManager.add('youku', tinymce.plugins.youku); })();This code is the image that needs to be called before corresponding to the short code button. Then create an images folder in the buttons folder, put an image named youku.png in it, and the call is completed. I copied other friends’ Icon picture, the written effect is as follows:
Let’s take a look at the input results again. Let’s enter the video above: This is the actual code
Summary: You can use this method to parse videos from other websites. As long as you find the corresponding parsing address, I will share the parsing of Tencent Video and bilibili later.
Recommended site searches: icp registration query, registration-free virtual space, host discount code, mobile server hosting, registration cancellation, registration-free, free domain name space, virtual host purchase for 0 yuan, Hong Kong's best virtual host, South Korea cn2 server< /p>
发表评论