Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function handle()
- {
- Log::useFiles(storage_path("/logs/iTunes_description.log"));
- Log::info('Debug');
- $context = stream_context_create();
- stream_context_set_params($context, array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0'));
- $shows = itunesshows::where("sitesid", "=", 26)->whereNull("description")->inRandomOrder()->take(1000)->get();
- foreach($shows as $show){
- try{
- $raw = file_get_contents($show->rss_url,0, $context);
- $xml = str_get_html($raw);
- }catch(\ErrorException $e){
- print_r($e->getMessage());
- unset ($e);
- continue;
- }
- echo $show->rss_url . "\n";
- try{
- $xml = $xml->find("channel")[0];
- }catch(\Error $e){
- if (str_contains($e->getMessage(), "Call to a member function find() on boolean")){
- unset($e);
- continue;
- }
- }catch(\ErrorException $e){
- if (str_contains($e->getMessage(), "Undefined offset: 0")){
- unset($e);
- continue;
- }
- }
- if(count($xml->find("description")) == 0){
- $xml2 = str_replace("itunes:summary", "itunes_summary", $xml);
- $xml2 = str_get_html($xml2);
- if(count($xml2->find("itunes_summary"))==0){
- }else{
- $show->description = utf8_encode($this->strip_cdata($xml2->find("itunes_summary")[0]->innertext));
- }
- }else{
- $show->description = utf8_encode($this->strip_cdata($xml->find("description")[0]->innertext));
- }
- if(count($xml->find("language")) == 0) {
- $show->country = "Unknown";
- }else{
- $show->country = $this->strip_cdata($xml->find("language")[0]->innertext);
- }
- $show->save();
- }
- }
- function strip_cdata($string)
- { preg_match_all('/<!\[cdata\[(.*?)\]\]>/is', $string, $matches);
- return str_replace($matches[0], $matches[1], $string);
- }
Add Comment
Please, Sign In to add comment