Jump to content
opiumhautopium1

php function --> Delphi ?

Recommended Posts

hello guys i need your help

i have a php script and i need some of the functions in delphi

functions like login... rename, move, fileinfo...... are okay and work in delphi

now i want to "translate" this

/**
 * Importiert eine oder mehrere URLs
 * 
 * @param string|array $url
 * 
 * @return array
 */
public function add_import($url)
{
	$url  = urlencode(implode("\n", (array)$url));
	$return = array();

	$json = $this->get_curl('http://uploaded.net/io/import', "urls=".$url);		
	$json = preg_split('#}([,])#', $json, 0, PREG_SPLIT_NO_EMPTY);

	foreach($json as $j)
	{
		$return[] = json_decode(preg_replace('/([{,])(\s*)([^"]+?)\s*','$1"$3":',$j.'}'));
	}

	return $return;


protected function get_curl($url, $post = null, $cookie = true, $header = false, $opt = null, $info = false)
{
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer: http://uploaded.net/upload'));

	if($post !== null)
	{
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);	
	}

	if($cookie)
		curl_setopt($ch, CURLOPT_COOKIE, $this->cookie_str);

	if($header)
		curl_setopt($ch, CURLOPT_HEADER, true);

	if($opt !== null)
	{
		curl_setopt_array($ch, $opt);
	}

	$res = curl_exec($ch);

	if($info === true) 
	{
		$r['res'] = $res;
		$r['info'] = curl_getinfo($ch);
		$res = $r;
	}

	curl_close($ch);

	return $res;
}

 

if u need more code

https://github.com/patschi/uploaded.net-direct-premium-downloader/blob/master/inc/Uploaded.php

 

but how to do that in delphi ?

i try

try
  sList:=TStringList.Create;
  sList.Add('urls=http://uploaded.net/file/h4nhiaux');
  Memo6.Text:=Http.Post('http://uploaded.net/io/import',sList );
 finally
   sList.Free;
 end;  

but don't work.... hope somebody can help me :-)

thx

Link to comment
Share on other sites

If you're using XE or up, you can use the built-in regular expressions library. To interact with the werbserver, I'd suggest the Indy socket library that also comes with Delphi.

 

Check out these links for examples and information:

Delphi Regular Expressions Classes

Chau Chee Yang Technical Blog: Using Indy HTTPS client to consume Google API service

Link to comment
Share on other sites

hi Freddy

i try my best with xe3

i learned a lot of regualar expressions in the last 2 month that 's ok

at the moment

this part is my problem

$json = $this->get_curl('http://uploaded.net/io/import', "urls=".$url);    

it should add the file to my account.....

but if i try it with delphi

  sList:=TStringList.Create;
  sList.Add('urls=http://uploaded.net/file/h4nhiaux');
  Memo6.Text:=Http.Post('http://uploaded.net/io/import',sList );

no file is added ... and i dont know why

Link to comment
Share on other sites

I don't see that working in any way. You are requesting a file from a website which requires you to have JS running, and which uses that JS to force a "wait-time", not all sites allows you to request files directly... As you are trying to download a file, right?

 

If however you have a premium account, I can see that working, as long as there is not requred JS, but that would require you to save a cookie with you userdata for that website / aka you need to be logged in.

 

If you find that you don't need to grab a file from a site that requires JS you can do some simple testing to get it all started:

Set up a simple WAMP/XAMPP-server, and put a file in you local-docs, and request it with http://127.0.0.1/myfile.rar (or whatever you would call it). Then you know if your script is working.

 

 

Freddy, there is a POST-request there, it's just hidden behind a rewrite-rule, but you might be refering to something else?

Edited by slacky
Link to comment
Share on other sites

uploaded is a filehoster and i have a premim acc

i dont want to download a file ... i want to import/Mirror a file from uploaded acc 1 to uploaded acc no 2 .... there are no captures or wait times... on the webside i mirror up to 200 files per minute no problem

and a lot of functions (translate from the php to delphi )like the logg in,cookies .... rename files (in uploaded acc) move files.... work pretty good (all with post)

example

 

//change filename
try
  sList:=TStringList.Create;
  sList.Add('value=' + NewFileName);
  sList.Add('&editorId=');
  Memo6.Text:=Http.Post('http://uploaded.net/io/me/files/' +FileID +'/set/title',sList );
 finally
   sList.Free;
 end;  

work

but not the import.....

Edited by opiumhautopium1
Link to comment
Share on other sites

Freddy, there is a POST-request there, it's just hidden behind a rewrite-rule, but you might be refering to something else?

 

No, I missed the code for get_curl there.

 

@opiumhautopium1: So you want to copy a file from one account to another by downloading it and uploading it again?

Link to comment
Share on other sites

no ..

no downloading and no upload

it is only a copy inside uploaded from one account to a second acc ... no trafic

first i logg in

with

try
  sList:=TStringList.Create;
  http.AllowCookies:=True;
  sList.Add('id=xxx');
  sList.Add('pw=xxx');
  Memo6.Text:=Http.Post('http://uploaded.net/io/login',sList);
 finally
   sList.Free;
 end; 

then check with regex if login is okay

after that things like move files to a folder (all with post) rename ...work

in delph i have no get_curl function....

Link to comment
Share on other sites

You can easly use the stored logincookie to check if you are logged in. If it's empty then you are logged out, if it's set/user-identification is stored there then you are logged in. No need to use RegEx when you already have your answer.

Edited by slacky
Link to comment
Share on other sites

jep but i get the return when i logg in so i see if i logged in or get errorcode ... it is easier for me

A lot of people do what you do. But that is an improper way of doing it, it's not uniform in any way. By just checking the cookie you can get it working at MANY websites out of the box. It should be just as easy, actually easier to check if the cookie-jar is empty or not.

 

Anyway: How is it coming / where R U at?

Edited by slacky
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...