我正在尝试构建一个小的 JavaScript 程序来查询 YouTube API对于给定的播放列表,按持续时间排序。否则一切都完美无缺,但排序并不代表整个播放列表,只是其中的 25 个最新视频!这是最低限度的完整工作 example as a JSFiddle这是其中的 JavaScript 部分:
var playlistId = "UUAuUUnT6oDeKwE6v1NGQxug";
jQuery.getJSON(
"https://gdata.youtube.com/feeds/api/playlists/"+playlistId+"?v=2&orderby=duration&alt=json",
function(data) {
$.each(data.feed.entry, function(key, val) {
var title = val.title.$t;
var url = val.content.src;
var duration = val.media$group.yt$duration.seconds;
var minutes = Math.floor(duration / 60);
var seconds = (duration % 60);
if( seconds < 10 ) seconds = "0"+seconds;
var newRow = $("<tr></tr>");
newRow.append("<td><a href='"+url+"'>"+title+"</a></td>");
newRow.append("<td class='dur'>"+minutes+":"+seconds+"</td>");
$("#videos").append(newRow);
});
}
);
我已经在 XML 和 JSON 中尝试过,除了播放列表搜索之外,我还尝试过其他类型的搜索。让 API 只对结果的最新视频进行排序似乎毫无意义。 如何准确检索播放列表中最长或最短的视频,或者特定用户为此上传的视频?
最佳答案
编辑
我认为您想要的功能不可用。按时长排序在 YouTube 上什至不可用。我认为您需要使用 max-results 和 start-index 来获取视频 block 。然后,您可以按持续时间对编译列表进行排序。
这是一个可能的解决方案的工作示例:http://jsfiddle.net/PKcnb/8
我发现谷歌在哪里明确表示不可能。
YouTube API v2.0 – Video Feed Types: Videos uploaded by a specific user
This section explains how to retrieve a feed containing all of the videos uploaded by a specific user. You should not include search parameters in requests to retrieve an uploaded videos feed. The parameters will generate a feed from YouTube's search index, effectively restricting the result set to indexed, public videos, rather than returning a complete list of the user's uploaded videos.
接着说:
To request a feed of all videos uploaded by the currently logged-in user, send a GET request to the following URL. This request requires an authentication token, which enables YouTube to identify the user.
因此,这可能是可行的,但您必须使用身份验证 token 对其进行测试。
原帖
API docs for orderby让它听起来像是只对响应进行了排序。
The orderby parameter, which is supported for video feeds and playlist feeds, specifies the method that will be used to order entries in the API response.
此外,the max-results tag会让您指定要返回的商品数量。
Here's an example of how you could pull more (50 in this example)结果已经排序。看起来你可能需要尽可能多地请求然后排序。绝对不理想。
关于javascript - YouTube API 'orderby=duration' 不处理整个播放列表,只处理最新的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13901360/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request