Switching between Youku and YouTube based on whether you're in China

chinese youtube app
youku tudou
chinese youtube alternative
china - youtube
china youtube site
china own youtube
iqiyi

I'm hosting a conference website where I want to embed a Youku video if you're in China and a YouTube video otherwise. The conference website is being served through a CDN inside the Great Firewall. I was given the code below to switch between internal and external versions of Youku.

Unfortunately, ipinfo.io does not seem to be accessible inside the Great Firewall, so the code times out after 10 seconds.

I've considered rewriting the page to use a Youku video by default, writing a small, non-blocking JavaScript function that tries to reach YouTube. If it can, replace the Youku with YouTube. If it can't, exit harmlessly. That way, the reachability of YouTube becomes the key test, not whether you're in China.

Alternatively, I've thought of hosting the video on my site, so that it will be replicated via the CDN inside the Great Firewall. However, that would mean that the video would always be downloaded at full resolution, even if you're on a slow connection.

Any better suggestions on how to switch between Youku and Youtube, or more generally have a video playable both inside and outside China?

jQuery.get("https://ipinfo.io", function(response) {
    var country = response.country;

    if(country == 'CN') {
        youku.attr('src',chinaVideo)
    } else {
        youku.attr('src',generalVideo)
    }
}, "jsonp");

Here is the JavaScript we are going with:

$(document).ready(function (){
    var country = '',
    youku = $('#youku');

    $.ajax({
        url: "https://ipinfo.io",
        dataType: "jsonp",
        success: function(response){
            var country = response.country;

            if(country != 'CN') {
                youku.attr('src','https://www.youtube.com/embed/K3cEE5h7c1s')
            }
         },
         error: function(){
            console.log('sorry...')
         },
         timeout: 5000
    });     
});

We are including the Youku link in the HTML and switching to YouTube if country is not China. This still works if connecting to ipinfo.io times out, which sometimes happens in China.

Edit: revised to add a 5 second timeout.

Edit2: We implemented this as an open source Wordpress plugin, in case others are interested. https://github.com/cncf/china-video-block

The “YouTube of China” is acting more and more like YouTube , And it would help create some brand loyalty: If you're a content creator with funding from Youku, it's bad form to post your videos on a  We are including the Youku link in the HTML and switching to YouTube if country is not China. This still works if connecting to ipinfo.io times out, which sometimes happens in China. Edit: revised to add a 5 second timeout.


It is better to specifically check if YouTube is blocked in user's network rather than filtering out country based on IP which is never 100% reliable. This way it will even work in any school/office environment where YouTube could be blocked by network administrator for any reason.

This is the best answer I could find in this regard which tries to load the favicon of YouTube via JavaScript. If it succeeds to download that tiny image, YouTube is accessible. The image is only 0.2 kilobytes of download and it is most likely already cached by any user who ever visited YouTube.

That means the result is almost instantaneous for users with YouTube access and will take few seconds for users with blocked firewalls. The code is simple:

jQuery(function(){
    var youku = jQuery('#youku');
    var image = new Image();
    image.onload = function(){
        youku.attr('src','https://www.youtube.com/embed/K3cEE5h7c1s')
    };
    image.onerror = function(){
        youku.attr('src','https://www.youku.com/embed/K3cEE5h7c1s')
    };
    image.src = "https://youtube.com/favicon.ico";
});

This one is a better solution than stated above as it does not wait for document.ready event of jQuery, the image starts to load instantly.

(function(){
    var image = new Image();
    image.onload = function(){
        jQuery(function(){
            jQuery('#youku').attr('src','https://www.youtube.com/embed/K3cEE5h7c1s')
        });
    };
    image.onerror = function(){
        jQuery(function(){
            jQuery('#youku').attr('src','https://www.youku.com/embed/K3cEE5h7c1s')
        });
    };
    image.src = "https://youtube.com/favicon.ico";
})();

Update based on comments:

In case there is possibility of the image being cached previously on user's computer, adding the current timestamp parameter to the image URL will ensure the image is loaded despite previously cached.

    image.src = "https://youtube.com/favicon.ico?_=" + Date.now();

YouTube = Youku? Websites and Their Chinese Equivalents, World Changing Ideas Baidu's stock price and traffic grew when Google halted China-based Dangdang, which recently filed for its IPO, does face threats from If Qiyi, Youku, and Tudou begin eroding its market share and viewer And you can say so much more in 140 Chinese characters than in  Youku Tudou set the goal of developing about 10,000 channels with monthly advertising income of over 10,000 yuan each and about 100 top-performing channels valued at more than 100 million yuan each. This is an ambitious goal because in 2015 the company only had 10 channels valued at more than 100 million yuan each.


Your current solution is not ideal as it depends on the GET request timing out, which is going to slow things down. Since the issue largely revolves around ipinfo.io being blocked in China, it's likely that an effective solution would involve an IP identification service based within China.

Try using http://www.ip138.com/. Google Translate works well enough to read it in English. There doesn't seem to be a formal JSON API, but you can hit http://www.ip138.com/ips138.asp?ip=<IP_ADDRESS_HERE> and get the location info.

To do so, navigate the DOM with jQuery (since you're already using it) to the line with 本站数据:, which will precede the name of the country. I think the selector for that as the page is currently constructed is simply $( "li" ).first(). Extract the string after the colon and the POST it to the Google Translate API to get the country name in English and voila! You have a faster and more reliable (if considerably more complicated) way to see if a visitor is in China or not.

EDIT: It is not entirely clear if you possess the user's IP address beforehand. If not, you can use a similar method with https://geoiptool.com/zh/, which is also based within China and thus not blocked. I'm happy to flesh this part out as needed.

Youku, Youku Tudou Inc., (formerly Youku Inc.) doing business as Youku is a video hosting service In 2007, the company received $25 million in funding from venture capitalists. As of January 2019, according to Alexa, Youku was the 50th most visited site By using this site, you agree to the Terms of Use and Privacy Policy. PowToon is a free tool that allows you to develop cool animated clips and animated presentations for your website, office meeting, sales pitch, nonprofit fundraiser, product launch, video resume


Any better suggestions on how to switch between Youku and Youtube, or more generally have a video playable both inside and outside China?

I'd suggest taking a look at Alibaba Cloud. They have a bunch of services, but AFAIK there is no free plan. Since I'm not familiar with other cloud providers for China, let me describe a solution for Alibaba Cloud.

I see two possible options for you:

  1. use their CDN Service and create two JS bundles - one for China and second for the rest of the world. The first one will embed video from Youku and second - from Youtube. After uploading them to CDN, you can force-push them to local nodes in China/world so there is always a quick and up-to-date response for users;
  2. use their Media Transcoding Service for video processing + Object Storage Service for video hosting + CDN Service for distribution. This way you can create multiple videos of different quality and distribute them near your users. JS will embed the video directly from CDN. For one video this might be an overkill.

It's A Major Mistake To Construe Youku As Another YouTube, First off, a major mistake is misconstruing Youku for a Youtube. We The cost of professionally produced content, according to Youku, Pressure from the Chinese government for the larger players to remove infringing If you're going to play by the rules in a market where no one else will, you will lose. Key areas/concepts: *Language choice in communities *Language choice among individuals: code-switching *Social factors invoked in code switching *Code switching in education *Attitudes to code


What about using the client's time zone? While not perfect, it would allow you to avoid relying on timeouts or any geoip service requests altogether. If possible, I would avoid an approach that might result in many, repeated calls to the same blocked resource from the same address block (e.g. from conference attendees). When I last lived in China, I remember triggering TCP resets from the Great Firewall which would last a good 30 seconds or more.

Intl.DateTimeFormat().resolvedOptions().timeZone is reasonably well-supported in modern browsers. In China, it should return the IANA time zone for China: "Asia/Shanghai":

console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

Western YouTube stars look to crack the Chinese social networks , Since YouTube, Facebook and Instagram are all blocked in China, videos including Weibo, Youku-Tudou (the Chinese equivalent of YouTube) For instance, if a social star talks about his or her life in English or tells jokes based on over from YouTube, rather than customized to the Chinese audience. Code switching between Indonesian, French and English - Duration: 1:14. Santi Dharmaputra Recommended for you. 1:14. Language: English Location: United States Restricted Mode: Off


Switching to the Mac: The Missing Manual, Yosemite Edition, When you hold down any of the modifier keys on your keyboard (like ⌘ You open the Keyboard Viewer by choosing its name from the new menulet that appears. directly to Youku Tudou (like YouTube) and Weibo (a microblogging service). If you want to write in Chinese, you can draw the characters you want, right on  Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.


Switching to the Mac: The Missing Manual, El Capitan Edition, button posting directly to Youku Tudou (like YouTube) and Weibo (a microblogging service). If you want to write in Chinese, you can draw the characters you want, right on the Chinese writing system you prefer, and then turn on Trackpad Handwriting. Keyboard Viewer, which is descended from the Key Caps program. YouTube Explained is a mix of analytical and comedic content covering YouTube videos, movies, songs and pretty much anything that can be explained. I try to


How Youku is helping China's film-makers get round the censors , China's answer to YouTube is bringing cinema – including 250 Hollywood UK edition · switch to the Australia edition · switch to the International edition 445m, according to CMM Intelligence, a Beijing-based market research firm. censors, and if that was the case we were shutting ourselves off from  Click the Account drop-down arrow in the top-right corner of the page. From the drop-down menu, choose the Page link that you want to use. This menu is where you toggle among your personal and Page Profiles. If you’re an Admin of several pages, you need to select the correct Page.