Advertisement
Guest User

Untitled

a guest
Dec 8th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.79 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(0);
  4. error_reporting(0);
  5. if (PHP_SAPI !== 'cli') { die(); }
  6. $opt=getopt('d:fl:m:o:t:v',array('rlt:','rgt:','only','proxy:','version','socks4-proxy:','socks5-proxy:','reapilink:','redownlink:','downcookie:','downreferer:','downuseragent:','without-proxy-getdownlink'));
  7. if (isset($opt['v']) || isset($opt['version'])) { die("osu-bot was created by asd.\nProject URL:https://github.com/lslqtz/osu-bot/\nVersion:1.8.\n"); }
  8. function curl($url,$head,$followlocation,$get_effective_url,$without_postdata,$without_cookie,$without_cookiejar,$without_cookiefile,$without_timeout,$without_referer,$without_useragent,$without_proxy) {
  9. $retry=0;
  10. retry:
  11. global $opt;
  12. if (!function_exists('curl_init')) { die("Error:Can't Find curl.\n"); }
  13. $curl=curl_init();
  14. curl_setopt($curl,CURLOPT_URL,$url);
  15. if ($head) {
  16. curl_setopt($curl,CURLOPT_HEADER,1);
  17. curl_setopt($curl,CURLOPT_NOBODY,1);
  18. }
  19. $without_timeout=($without_timeout === 1 || !isset($opt['t'])) ? 120 : $opt['t'];
  20. curl_setopt($curl,CURLOPT_TIMEOUT,$without_timeout);
  21. if ($without_postdata !== 1) {
  22. curl_setopt($curl,CURLOPT_POST,1);
  23. curl_setopt($curl,CURLOPT_POSTFIELDS,$without_postdata);
  24. }
  25. curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  26. curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0);
  27. if ($without_cookie !== 1) {
  28. if ($without_cookiejar !== 1) {
  29. curl_setopt($curl,CURLOPT_COOKIEJAR,$without_cookiejar);
  30. } elseif ($without_cookiefile !== 1) {
  31. curl_setopt($curl,CURLOPT_COOKIEFILE,$without_cookiefile);
  32. } else {
  33. curl_setopt($curl,CURLOPT_COOKIE,$without_cookie);
  34. }
  35. }
  36. if (!$without_referer && isset($opt['downreferer'])) {
  37. curl_setopt($curl,CURLOPT_REFERER,$opt['downreferer']);
  38. }
  39. if (!$without_useragent && isset($opt['downuseragent'])) {
  40. curl_setopt($curl,CURLOPT_USERAGENT,$opt['downuseragent']);
  41. }
  42. if (!$without_proxy) {
  43. if (isset($opt['proxy'])) {
  44. curl_setopt($curl,CURLOPT_PROXY,$opt['proxy']);
  45. curl_setopt($curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
  46. } elseif (isset($opt['socks4-proxy'])) {
  47. curl_setopt($curl,CURLOPT_PROXY,$opt['socks4-proxy']);
  48. curl_setopt($curl,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS4);
  49. } elseif (isset($opt['socks5-proxy'])) {
  50. curl_setopt($curl,CURLOPT_PROXY,$opt['socks5-proxy']);
  51. curl_setopt($curl,CURLOPT_PROXYTYPE,CURLPROXY_SOCKS5);
  52. }
  53. }
  54. if ($followlocation) {
  55. curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
  56. }
  57. if (!$get_effective_url) {
  58. $data=curl_exec($curl);
  59. } else {
  60. curl_exec($curl);
  61. $data=curl_getinfo($curl,CURLINFO_EFFECTIVE_URL);
  62. }
  63. curl_close($curl);
  64. if (!$data) {
  65. if ($retry < 3) {
  66. $retry++;
  67. echo "Error:Can't Connect To URL,Retry:$retry.\n";
  68. goto retry;
  69. }
  70. return 0;
  71. }
  72. return $data;
  73. }
  74. function getfile($url) {
  75. global $opt;
  76. $without_cookie=isset($opt['downcookie']) ? $opt['downcookie'] : 1;
  77. return curl($url,0,1,0,1,$without_cookie,1,1,1,0,0,0);
  78. }
  79. function getdlink($did) {
  80. global $opt;
  81. $without_proxy=isset($opt['without-proxy-getdownlink']) ? 1 : 0;
  82. if (!file_exists('cookie.txt')) {
  83. getcookie();
  84. }
  85. $location=curl("https://osu.ppy.sh/d/$did",1,1,1,1,0,1,'cookie.txt',1,1,1,$without_proxy);
  86. if ($location === 'https://ripple.moe/login') {
  87. return 0;
  88. } else {
  89. return $location;
  90. }
  91. }
  92. function getcookie() {
  93. global $opt;
  94. global $userinfo;
  95. $without_proxy=isset($opt['without-proxy-getdownlink']) ? 1 : 0;
  96. curl('https://osu.ppy.sh/forum/ucp.php?mode=login',0,0,0,'redirect=%2F&username='.urlencode($userinfo['username']).'&password='.urlencode($userinfo['password']).'&autologin=on&login=login',0,'cookie.txt',1,1,1,1,$without_proxy);
  97. }
  98. function set($t,$r) {
  99. global $opt;
  100. global $$t;
  101. switch ($opt['m']) {
  102. case 0:
  103. case 2:
  104. ${$t}['size']=isset($r[0]) ? $r[0] : 0;
  105. ${$t}['approach']=isset($r[1]) ? $r[1] : 0;
  106. ${$t}['overall']=isset($r[2]) ? $r[2] : 0;
  107. ${$t}['drain']=isset($r[3]) ? $r[3] : 0;
  108. ${$t}['stars']=isset($r[4]) ? $r[4] : 0;
  109. break;
  110. case 1:
  111. ${$t}['size']=0;
  112. ${$t}['approach']=0;
  113. ${$t}['overall']=isset($r[0]) ? $r[0] : 0;
  114. ${$t}['drain']=isset($r[1]) ? $r[1] : 0;
  115. ${$t}['stars']=isset($r[2]) ? $r[2] : 0;
  116. break;
  117. case 3:
  118. ${$t}['size']=isset($r[0]) ? $r[0] : 0;
  119. ${$t}['approach']=0;
  120. ${$t}['overall']=isset($r[1]) ? $r[1] : 0;
  121. ${$t}['drain']=isset($r[2]) ? $r[2] : 0;
  122. ${$t}['stars']=isset($r[3]) ? $r[3] : 0;
  123. break;
  124. }
  125. }
  126. if (!isset($opt['m']) || !is_numeric($opt['m']) || $opt['m'] < 0 || $opt['m'] > 3) {
  127. $opt['m']=0;
  128. }
  129. if (!isset($opt['l']) || !is_numeric($opt['l']) || $opt['l'] < 0) {
  130. $opt['l']=0;
  131. }
  132. if (!is_numeric($opt['d']) || !$opt['d']) {
  133. die("Usage:php bot.php -d [Before Days] [-v/--version Version] [-f Full Filename] [-l Limit] [-m Mode(0:STD[Default],1:Taiko,2:CTB,3:osu!mania)] [--only] [--without-proxy-getdownlink] [--rlt/rgt=Requirement(CS:AR:OD:HP:Stars)(For Mania:CS=Keys)] [--reapilink=Replace-API-Link] [--redownlink=Replace-Download-Link] [--downcookie=Download-Cookie] [--downreferer=Download-Referer] [--downuseragent=Download-UserAgent] [--proxy=HTTP/HTTPS Proxy Address] [--socks4-proxy=Socks4 Proxy Address] [--socks5-proxy=Socks5 Proxy Address].\n");
  134. }
  135. echo "Enter Your osu! Username:";
  136. $userinfo['username']=trim(fgets(STDIN));
  137. if (empty($userinfo['username'])) {
  138. die("\nPlease Enter Your osu! Username.\n");
  139. }
  140. echo "Enter Your osu! Password:";
  141. $userinfo['password']=trim(fgets(STDIN));
  142. if (empty($userinfo['password'])) {
  143. die("\nPlease Enter Your osu! Password.\n");
  144. }
  145. echo "Enter Your osu! APIKey:";
  146. $userinfo['apikey']=trim(fgets(STDIN));
  147. if (empty($userinfo['apikey'])) {
  148. die("\nPlease Enter Your osu! APIKey.\n");
  149. }
  150. echo "Enter Your Save Dir:";
  151. $userinfo['savedir']=trim(fgets(STDIN));
  152. if (empty($userinfo['savedir'])) {
  153. die("\nPlease Enter Your Save Dir.\n");
  154. }
  155. if (!is_dir($userinfo['savedir']) && !mkdir($userinfo['savedir'])) {
  156. die("Error:Can't Create Dir.\n");
  157. }
  158. $limit=1;
  159. $apilink=isset($opt['reapilink']) ? $opt['reapilink'] : 'https://osu.ppy.sh/api/';
  160. for ($a=$opt['d'];$a>0;$a--) {
  161. $beatmaps=[];
  162. $date=date("Y-m-d",strtotime("-$a day"));
  163. $args='k='.$userinfo['apikey'].'&m='.$opt['m']."&since=$date";
  164. echo $date.":\n";
  165. $beatmaps_json=json_decode(curl($apilink."get_beatmaps?$args",0,0,0,1,1,1,1,1,1,1,0));
  166. if (!is_array($beatmaps_json) || !isset($beatmaps_json[1])) {
  167. die("Error:Can't Connect osu!API Or Haven't Beatmap.\n");
  168. }
  169. if (isset($opt['rlt'])) {
  170. set('rlt',explode(':',$opt['rlt']));
  171. }
  172. if (isset($opt['rgt'])) {
  173. set('rgt',explode(':',$opt['rgt']));
  174. }
  175. for ($i=0;$i<count($beatmaps_json);$i++) {
  176. $rltyes=0;
  177. $rgtyes=0;
  178. if (isset($rlt)) {
  179. if ((!$rlt['size'] || $beatmaps_json[$i]->diff_size < $rlt['size']) && (!$rlt['approach'] || $beatmaps_json[$i]->diff_approach < $rlt['approach']) && (!$rlt['overall'] || $beatmaps_json[$i]->diff_overall < $rlt['overall']) && (!$rlt['drain'] || $beatmaps_json[$i]->diff_drain < $rlt['drain']) && (!$rlt['stars'] || $beatmaps_json[$i]->diff_difficultyrating < $rlt['stars'])) {
  180. $rltyes=1;
  181. }
  182. } else {
  183. $rltyes=1;
  184. }
  185. if (isset($rgt)) {
  186. if ((!$rgt['size'] || $beatmaps_json[$i]->diff_size > $rgt['size']) && (!$rgt['approach'] || $beatmaps_json[$i]->diff_approach > $rgt['approach']) && (!$rgt['overall'] || $beatmaps_json[$i]->diff_overall > $rgt['overall']) && (!$rgt['drain'] || $beatmaps_json[$i]->diff_drain > $rgt['drain']) && (!$rgt['stars'] || $beatmaps_json[$i]->diff_difficultyrating > $rgt['stars'])) {
  187. $rgtyes=1;
  188. }
  189. } else {
  190. $rgtyes=1;
  191. }
  192. if ($rltyes && $rgtyes) {
  193. $beatmaps[$i]=$beatmaps_json[$i]->beatmapset_id.' '.$beatmaps_json[$i]->artist.' - '.$beatmaps_json[$i]->title;
  194. }
  195. unset($rltyes,$rgtyes);
  196. }
  197. $beatmaps=array_merge(array_unique($beatmaps,SORT_NUMERIC));
  198. for ($i=0;$i<count($beatmaps);$i++) {
  199. if ($opt['l'] && $limit > $opt['l']) {
  200. die("Download Completed!\n");
  201. }
  202. $filename=$beatmaps[$i];
  203. $did=explode(' ',$beatmaps[$i])[0];
  204. $filename=(!isset($opt['f']) && is_numeric($did)) ? $did.'.osz' : str_replace(['/','\\',':','*','"','<','>','|','?','~'],'-',$filename).'.osz';
  205. if (!file_exists($userinfo['savedir'].'/'.$filename)) {
  206. if ($link=getdlink($did)) {
  207. if (isset($opt['redownlink'])) {
  208. $link=preg_replace('/http(s?):\/\/bm(\d).ppy.sh\/d\//',$opt['redownlink'],$link);
  209. }
  210. $file=getfile($link);
  211. if (!empty($file) && strlen($file) > 20480) {
  212. if (file_put_contents($userinfo['savedir'].'/'.$filename,$file,LOCK_EX)) {
  213. $limit++;
  214. echo "Downloaded:$filename.\n";
  215. } else {
  216. echo "Error:Can't Save $filename.\n";
  217. unlink($userinfo['savedir'].'/'.$filename);
  218. }
  219. } else {
  220. echo "Error:Can't Download $filename.\n";
  221. }
  222. } else {
  223. echo "Error:Can't Get Download Link.\n";
  224. unlink('cookie.txt');
  225. }
  226. }
  227. unset($did,$file,$link,$filename);
  228. }
  229. if (isset($opt['only'])) {
  230. break;
  231. }
  232. unset($args,$date,$beatmaps,$beatmaps_json);
  233. }
  234. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement