doc: http://open.youku.com/docs/doc?id=84
432954
def search_keyword_top(self, category=None, count=20, period='today'):
        
        url = 'https://openapi.youku.com/v2/searches/keyword/top.json'
        params = {
            'client_id': self.client_id,
            'count': count,
            'period': period
        }
        if category:
            params['category'] = category
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
208458
def subscribe_get(self, access_token, page=1, count=20):
        
        url = 'https://openapi.youku.com/v2/users/subscribe/get.json'
        params = {
            'client_id': self.client_id,
            'access_token': access_token,
            'page': page,
            'count': count
        }
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
535735
function() {
		var api_url,
			self = this;
					
		// Create Dom element
		this._el.content_item = TL.Dom.create("div", "tl-media-twitter", this._el.content);
		this._el.content_container.className = "tl-media-content-container tl-media-content-container-text";
        		
		// Get Media ID
        if(this.data.url.match("^(https?:)?\/*(www.)?twitter\.com"))
        {
		if (this.data.url.match("status\/")) {
			this.media_id = this.data.url.split("status\/")[1];
		} else if (this.data.url.match("statuses\/")) {
			this.media_id = this.data.url.split("statuses\/")[1];
		} else {
			this.media_id = "";
		}
        }
        
        else if(this.data.url.match("<blockquote class=['\"]twitter-tweet['\"]")) {
		
        var found = this.data.url.match(/(status|statuses)\/(\d+)/);
		if (found && found.length > 2) {
		    this.media_id = found[2];
		} else {
		    self.loadErrorDisplay(self._("twitterembed_invalidurl_err"));
		    return;
		}
    }
        
		// API URL
		api_url = "https://api.twitter.com/1/statuses/oembed.json?id=" + this.media_id + "&omit_script=true&include_entities=true&callback=?";
		
		// API Call
		TL.ajax({
			type: 'GET',
			url: api_url,
			dataType: 'json', //json data type
			success: function(d){
				self.createMedia(d);
			},
			error:function(xhr, type){
				var error_text = "";
				error_text += self._("twitter_load_err") + "<br/>" + self.media_id + "<br/>" + type;
				self.loadErrorDisplay(error_text);
			}
		});
		 
	}
363216
public static void download(String entranceURL, String type, String path, boolean containEntrance, boolean justOriginalName){
        int timeout = 300000;
        if(!entranceURL.endsWith("/")){
            entranceURL += "/";
        }
        Set<String> urls = new HashSet<>();
        boolean ok = false;
        int limit=0;
        while (!ok && (limit++) < 3) {
            try {
                System.out.println("【"+type+"】*** connect " + entranceURL);
                for (Element element : Jsoup.connect(entranceURL).timeout(timeout).get().select("a")) {
                    String href = element.attr("href").trim();
                    if (!href.startsWith("http")) {
                        if(href.startsWith("/")){
                            href = "http://www.bbc.co.uk" + href;
                        }else{
                            href = entranceURL + href;
                        }
                    }
                    if (href.startsWith(entranceURL) && (!href.equals(entranceURL) || containEntrance) ) {
                        urls.add(href);
                    }
                }
                ok = true;
            } catch (Exception e) {
                System.out.println(e.getMessage() + " retry...");
            }
        }
        AtomicInteger i = new AtomicInteger(1);
        Set<String> resources = new HashSet<>();
        urls.stream().sorted().forEach(url -> {
            boolean success = false;
            int times=0;
            while (!success && (times++) < 3) {
                try {
                    System.out.println(i.get() + "、connect " + url);
                    for (Element element : Jsoup.connect(url).timeout(timeout).get().select("a")) {
                        String href = element.attr("href").trim();
                        //只下载mp3、mp4、wav和pdf文件
                        if (href.endsWith(".mp3") || href.endsWith(".wav") || href.endsWith(".mp4") || href.endsWith(".pdf")) {
                            if (!href.startsWith("http")) {
                                if(href.startsWith("/")){
                                    href = "http://www.bbc.co.uk" + href;
                                }else{
                                    String[] attr = url.split("/");
                                    href = url.substring(0, url.length()-attr[attr.length-1].length()) + href;
                                }
                            }
                            resources.add(href);
                        }
                    }
                    i.incrementAndGet();
                    success = true;
                } catch (Exception e) {
                    System.out.println(e.getMessage() + " retry...");
                }
            }
        });
        AtomicInteger j = new AtomicInteger(1);
        count += resources.size();
        resources.stream().sorted().forEach(resource -> {
            boolean success = false;
            int times=0;
            while (!success && (times++) < 3) {
                try {
                    //提取文件名称
                    String[] attr = resource.split("/");
                    String fileName = attr[attr.length - 2] + "_" + attr[attr.length - 1].replace(attr[attr.length - 2], "");
                    if(attr[attr.length - 1].endsWith(attr[attr.length - 2])){
                        fileName = attr[attr.length - 1];
                    }
                    fileName = fileName.replace("_download", "");
                    if(justOriginalName){
                        fileName = attr[attr.length - 1];
                    }
                    System.out.println(resources.size() + "/" + j.get() + "、find resource: " + resource);
                    //确保本地路径存储
                    Path dir = Paths.get(path, type);
                    if (!Files.exists(dir)) {
                        //不存在则新建
                        dir.toFile().mkdirs();
                    }
                    //保存文件的完整本地路径
                    Path out = Paths.get(path, type, fileName);
                    //如果文件存在则表示之前已经下载过，本次不用下载
                    //因为BBC的访问不稳定，所以可能需要执行程序多次才能完整下载完毕，所以这里要处理已存在文件的问题
                    if (!Files.exists(out)) {
                        //下载文件
                        Connection.Response response = Jsoup.connect(resource).maxBodySize(0).ignoreContentType(true).timeout(timeout).execute();
                        //将文件保存到本地
                        Files.write(out, response.bodyAsBytes());
                        System.out.println(resources.size() + "/" + j.get() + "、save resource to: " + out);
                    } else {
                        System.out.println(resources.size() + "/" + j.get() + "、resource exist, don't need to download");
                    }
                    j.incrementAndGet();
                    success = true;
                } catch (Exception e) {
                    System.out.println(e.getMessage() + " retry...");
                }
            }
        });
    }
152357
def searche_top_category(self):
        
        url = 'https://openapi.youku.com/v2/schemas/searche/top/category.json'
        r = requests.get(url)
        check_error(r)
        return r.json()
267569
def comment_expression(self):
        
        url = 'https://openapi.youku.com/v2/schemas/comment/expression.json'
        r = requests.get(url)
        check_error(r)
        return r.json()
594488
def refresh_token(self, refresh_token):
        ''''''
        url = 'https://api.youku.com/oauth2/token.json'
        data = {'client_id': self.client_id,
                'grant_type': 'refresh_token',
                'refresh_token': refresh_token}
        r = requests.post(url, data=data)
        check_error(r)
        return r.json()
559427
def find_shows_by_category(self, category, genre=None, area=None,
                               release_year=None, paid=None,
                               orderby='view-today-count',
                               streamtypes=None, person=None,
                               page=1, count=20):
        
        url = 'https://openapi.youku.com/v2/shows/by_category.json'
        params = {
            'client_id': self.client_id,
            'category': category,
            'genre': genre,
            'area': area,
            'release_year': release_year,
            'paid': paid,
            'orderby': orderby,
            'streamtypes': streamtypes,
            'person': person,
            'page': page,
            'count': count
        }
        params = remove_none_value(params)
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
143710
def show_category(self):
        
        url = 'https://openapi.youku.com/v2/schemas/show/category.json'
        r = requests.get(url)
        check_error(r)
        return r.json()
126814
def playlist_category(self):
        
        url = 'https://openapi.youku.com/v2/schemas/playlist/category.json'
        r = requests.get(url)
        check_error(r)
        return r.json()
194402
def find_next_video_in_playlist(self, playlist_id, cur_video_id):
        
        url = 'https://openapi.youku.com/v2/playlists/video/next.json'
        params = {
            'client_id': self.client_id,
            'playlist_id': playlist_id,
            'video_id': cur_video_id
        }
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
1296275
def open
      unless addon_name = shift_argument
        error("Usage: heroku addons:open ADDON\nMust specify ADDON to open.")
      end
      validate_arguments!
      requires_preauth

      addon = resolve_addon!(addon_name)
      web_url = addon['web_url']

      begin
        attachment = resolve_attachment!(addon_name)
        web_url = attachment['web_url']
      rescue Heroku::API::Errors::NotFound
        # no-op
      rescue Heroku::API::Errors::RequestFailed => e
        if MultiJson.decode(e.response.body)["id"] != "multiple_matches"
          raise
        end
      end

      service = addon['addon_service']['name']
      launchy("Opening #{service} (#{addon['name']}) for #{addon['app']['name']}", web_url)
    end
955973
def docomo_openiarea_url_for(options = {})
      url = options
      if options.is_a?(Hash)
        options = options.symbolize_keys
        options[:only_path] = false
        posinfo = options.delete(:posinfo) || '1' # 基地局情報を元に測位した緯度経度情報を要求
        url = url_for(options)
      else
        posinfo = '1'
      end
      "http://w1m.docomo.ne.jp/cp/iarea?ecode=OPENAREACODE&msn=OPENAREAKEY&posinfo=#{posinfo}&nl=#{CGI.escape(url)}"
    end
398847
def myanimelist(username):
    
    params = {
        "u": username,
        "status": "all",
        "type": "anime"
    }

    resp = requests.request("GET", ENDPOINT_URLS.MYANIMELIST, params=params)

    # Check if MAL's hitting you with a 429 and raise an exception if so.
    if resp.status_code == 429:  # pragma: no cover
        raise MALRateLimitExceededError("MAL rate limit exceeded")

    resp = bs4.BeautifulSoup(resp.content, "xml")

    all_anime = resp.find_all("anime")

    # Check if there's actually any anime being returned to us.
    # If not, user probably doesn't exist.
    # MAL should do a better job of highlighting this, but eh.
    if not len(all_anime):
        raise InvalidUsernameError("User `{}` does not exist"
                                   .format(username))

    scores = []

    for anime in all_anime:
        # See if anime is on their PTW and move on if so.
        # This makes sure rated anime that the user hasn't
        # seen does not get added to `scores`.
        # Why do people even do this?
        # PTW == status "6"
        if anime.my_status.string == "6":
            continue

        id = anime.series_animedb_id.string
        id = int(id)

        score = anime.my_score.string
        # Might need changing if MAL allows float scores.
        score = int(score)

        if score > 0:
            scores.append({"id": id, "score": score})

    # Check if there's actually anything in scores.
    # If not, user probably doesn't have any rated anime.
    if not len(scores):
        raise NoAffinityError("User `{}` hasn't rated any anime"
                              .format(username))

    return scores
459248
def create_friendship(self, access_token,
                          user_id=None, user_name=None):
        
        url = 'https://openapi.youku.com/v2/users/friendship/create.json'
        data = {
            'client_id': self.client_id,
            'access_token': access_token,
            'user_id': user_id,
            'user_name': user_name
        }
        data = remove_none_value(data)
        r = requests.post(url, data=data)
        check_error(r)
        return r.json()
553293
def find_comment_by_id(self, comment_id):
        
        url = 'https://openapi.youku.com/v2/comments/show.json'
        params = {
            'client_id': self.client_id,
            'comment_id': comment_id
        }
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
555965
def find_playlists_by_ids(self, playlist_ids):
        
        url = 'https://openapi.youku.com/v2/playlists/show_batch.json'
        params = {
            'client_id': self.client_id,
            'playlist_ids': playlist_ids
        }
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()