如何从kinox.to获取流网址?

时间:2016-08-03 00:13:35

标签: bash

我找到了以下代码:

#!/bin/sh
# Get stream URLs for the second episode of the seventh season of futurama:
# kinox.sh futurama 7 2
# for shows with spaces, insert a plus sign instead:
# kinox.sh it+crowd 3 1

# grab the stream by searching for the show on kinox.to, filtering to only     show english versions, and extracting the internal show name
export stream_page=$(curl -sL "http://kinox.to/Search.html?q=$1" | pcregrep -M 'lng\/2\.png(\n|.)+?class="Title"' | pcregrep -o1 'Stream\/(.+?)\.html' | head -n 1)

# get the show's page, with the undocumented additional parameters for season and episode, and grab the "rel" attribute of the hoster list
export stream_rel=$(curl -sL http://kinox.to/Stream/$stream_page.html,s$2e$3 |grep rel= | pcregrep -o1 '<li i.+?rel="(.+?)"' | perl -pe 's/&amp;/&/g')

# for every rel attribute (which will contain season, episode, hoster id and mirror id)
while read -r line; do
# call the "secret" API. This will yield a JSON object, but since we're only interested in one attribute, we'll throw some regex on top and print the list of stream urls
curl -sL "http://kinox.to/aGET/Mirror/$line" | pcregrep -o1 'map> <a href=\\"(.+?)\\"' | tr -d '\' |perl -pe 's/\/Out\/\?s=//g'
done <<< "$stream_rel"

它是如何工作的还是有更简单的方法?我想把它转移到python。提前致谢

1 个答案:

答案 0 :(得分:0)

底线是您需要进行基本调试以找出问题在脚本中的位置。

正如评论中所提到的,没有明显的错误突出。 (好吧,我撒谎,有一个明显的问题,但是考虑到许多现代shell解释POSIX shell的方式,它可能没有问题处理。)对于记录,你正在调用POSIX shell {{ 1}}作为shell解释器,但是您正在为#!/bin/bash循环提供一个while,这在POSIX shell中是不存在的。

你如何进行一般调试?对于初学者,请使用herestring运行脚本,例如:

sh -x scriptname arg1 arg2 arg3

我的盒子$ sh -x curl_stream_ex.sh futurama 7 2 ++ curl -sL 'http://kinox.to/Search.html?q=futurama' ++ pcregrep -M 'lng\/2\.png(\n|.)+?class="Title"' curl_stream_ex.sh: line 8: pcregrep: command not found 未安装,“它是否安装在你的盒子上?”解决这个问题,例如

pcregrep

再次尝试(这次使用$ sudo zypper in -r oss pcre-tools pcre-doc <snip> (1/2) Installing: pcre-doc-8.33-2.1.2 ......................[done] (2/2) Installing: pcre-tools-8.33-2.1.2 ....................[done] committingCommitResult (total 2, done 2, error 0, skipped 0, updateMessages 0) 作为解释器,并使用提供的bash示例):

futurama 7 2

好的,有一个警告,这不是致命的,但让我们继续并解决这个问题。好消息是我们现在知道服务器处于活动状态,并且有一些响应示例$ bash -x curl_stream_ex.sh futurama 7 2 ++ pcregrep -o1 'Stream\/(.+?)\.html' ++ pcregrep -M 'lng\/2\.png(\n|.)+?class="Title"' ++ curl -sL 'http://kinox.to/Search.html?q=futurama' ++ head -n 1 + export stream_page=Futurama_Into_the_Wild_Green_Yonder + stream_page=Futurama_Into_the_Wild_Green_Yonder ++ curl -sL http://kinox.to/Stream/Futurama_Into_the_Wild_Green_Yonder.html,s7e2 ++ grep rel= ++ perl -pe 's/&amp;/&/g' ++ pcregrep -o1 '<li i.+?rel="(.+?)"' + export 'stream_rel=Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=62&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=30&Mirror=1 Futurama_Into_the_Wild_Green_Yonder&Hoster=33' + stream_rel='Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=62&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=30&Mirror=1 Futurama_Into_the_Wild_Green_Yonder&Hoster=33' + read -r line + curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2' + pcregrep -o1 'map> <a href=\\"(.+?)\\"' + perl -pe 's/\/Out\/\?s=//g' + tr -d '\' tr: warning: an unescaped backslash at end of string is not portable <snip> 的内容。要修复futurama 7 2非可移植的非转义反斜杠,请执行以下命令:

tr

(为了便携性)应该是:

tr -d '\'

再试一次。

tr -d '\\'

没有错误,但看起来$ bash -x curl_stream_ex.sh futurama 7 2 ++ pcregrep -M 'lng\/2\.png(\n|.)+?class="Title"' ++ curl -sL 'http://kinox.to/Search.html?q=futurama' ++ head -n 1 ++ pcregrep -o1 'Stream\/(.+?)\.html' + export stream_page=Futurama_Into_the_Wild_Green_Yonder + stream_page=Futurama_Into_the_Wild_Green_Yonder ++ curl -sL http://kinox.to/Stream/Futurama_Into_the_Wild_Green_Yonder.html,s7e2 ++ perl -pe 's/&amp;/&/g' ++ grep rel= ++ pcregrep -o1 '<li i.+?rel="(.+?)"' + export 'stream_rel=Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=62&Mirror=1 Futurama_Into_the_Wild_Green_Yonder&Hoster=30&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=33' + stream_rel='Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=62&Mirror=1 Futurama_Into_the_Wild_Green_Yonder&Hoster=30&Mirror=2 Futurama_Into_the_Wild_Green_Yonder&Hoster=33' + read -r line + curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2' + pcregrep -o1 'map> <a href=\\"(.+?)\\"' + tr -d '\\' + perl -pe 's/\/Out\/\?s=//g' + read -r line + curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=62&Mirror=1' + pcregrep -o1 'map> <a href=\\"(.+?)\\"' + tr -d '\\' + perl -pe 's/\/Out\/\?s=//g' + read -r line + curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=30&Mirror=2' + tr -d '\\' + pcregrep -o1 'map> <a href=\\"(.+?)\\"' + perl -pe 's/\/Out\/\?s=//g' + read -r line + curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=33' + pcregrep -o1 'map> <a href=\\"(.+?)\\"' + perl -pe 's/\/Out\/\?s=//g' + tr -d '\\' + read -r line 的{​​{1}}行没有返回任何内容。直到脚本中的那一点,事情看起来还不错。具体来说,通过pcregrep上的pcregrep -o1 'map> <a href=\\"(.+?)\\"'read -r命令,curl会返回以下内容:

$line

因此,在不知道更多的情况下,似乎curl的流格式(或内容)已经更改或更新,因为无论何时编写找到的脚本,今天。你需要做什么,以及我无法帮助你,因为我不知道你在做什么信息,是重写$ curl -sL 'http://kinox.to/aGET/Mirror/Futurama_Into_the_Wild_Green_Yonder&Hoster=52&Mirror=2' {"Stream":"<a href=\"http:\/\/shared.sx\/992ba73be8\" target=\"_blank\"><img src=\"\/gr\/sys\/player\/default.flash.png\" usemap=\"#Link\" width=\"752\" height=\"370\" border=\"52\" \/><\/a><map name=\"Link\"><area shape=\"rect\" coords=\"220,250,515,310\" target=\"_blank\" href=\"\" alt=\"Download This Movie\" title=\"Download This Movie\"><\/map>","Replacement":"<li id=\"Hoster_52\" class=\"MirBtn MirBtnA MirBaseStyleflv MirStyle52\" rel=\"Futurama_Into_the_Wild_Green_Yonder&amp;Hoster=52&amp;Mirror=3\">\t<div class=\"Named\">Shared.sx<\/div>\t<div class=\"Data\"><b>Mirror<\/b>: 3\/3<br \/><b>Vom<\/b>: 25.10.2015<\/div><\/li>","HosterName":"Shared.sx","HosterHome":"http:\/\/shared.sx"} 在返回的文本上使用的正则表达式通过http://kinox.to将其解析为包含您尝试获取的链接的网址。

这就是解决问题的方法。使用pcregrepcurlsh是没有区别的,如果没有正确的bash,解释器都不会返回任何有用的内容。