sonata-project / SonataMediaBundle

Symfony SonataMediaBundle
https://docs.sonata-project.org/projects/SonataMediaBundle
MIT License
451 stars 495 forks source link

Can´t add a youtube video #759

Closed bnd170 closed 9 years ago

bnd170 commented 9 years ago

When I try to add a new video from youtube, form returns me two errors:

This value should not be null This value should not be empty

This is a screenshot of the error: http://i.gyazo.com/776749c3f8a819b8a0a49160ea28323b.png

Im using:

    "sonata-project/admin-bundle": "dev-master",
    "sonata-project/core-bundle": "dev-master",
    "sonata-project/doctrine-orm-admin-bundle": "*",
    "sonata-project/jquery-bundle": "dev-master",
    "sonata-project/formatter-bundle": "dev-master",
    "sonata-project/media-bundle": "dev-master",
    "sonata-project/intl-bundle": "dev-master",
    "sonata-project/datagrid-bundle": "dev-master",
    "sonata-project/user-bundle": "dev-master",
    "sonata-project/classification-bundle": "dev-master",
Guillaume-Rossignol commented 9 years ago

For me :

$mediaManager = $this->getMediaManager();
$youtube = $mediaManager->create();
$youtube->setBinaryContent('https://www.youtube.com/watch?v=wwwww');
$youtube->setEnabled(true);
$youtube->setName('presentation');
$mediaManager->save($youtube, 'default', 'sonata.media.provider.youtube');

And the result :

    [exec]   [Buzz\Exception\RequestException]
     [exec]   file_get_contents(https://i.ytimg.com/vi/EQwX4VodyjM/hqdefault.jpg): failed to open stream: operation failed
     [exec] 
     [exec] 
     [exec] 
     [exec] Exception trace:
     [exec]  () at /home/guillaume/PhpstormProjects/axiona/vendor/kriswallsmith/buzz/lib/Buzz/Client/FileGetContents.php:64
     [exec]  Buzz\Client\FileGetContents->send() at /home/guillaume/PhpstormProjects/axiona/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php:130
     [exec]  Buzz\Browser->send() at /home/guillaume/PhpstormProjects/axiona/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php:82
     [exec]  Buzz\Browser->call() at /home/guillaume/PhpstormProjects/axiona/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php:31
     [exec]  Buzz\Browser->get() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Provider/BaseVideoProvider.php:77
     [exec]  Sonata\MediaBundle\Provider\BaseVideoProvider->getReferenceFile() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Thumbnail/FormatThumbnail.php:65                                                                                                                                                                         
     [exec]  Sonata\MediaBundle\Thumbnail\FormatThumbnail->generate() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Provider/BaseProvider.php:106
     [exec]  Sonata\MediaBundle\Provider\BaseProvider->generateThumbnails() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Provider/BaseVideoProvider.php:159                                                                                                                                                                          
     [exec]  Sonata\MediaBundle\Provider\BaseVideoProvider->postPersist() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Listener/BaseMediaEventSubscriber.php:114                                                                                                                                                                     
     [exec]  Sonata\MediaBundle\Listener\BaseMediaEventSubscriber->postPersist() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php:61                                                                                                                                                      
     [exec]  Symfony\Bridge\Doctrine\ContainerAwareEventManager->dispatchEvent() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/orm/lib/Doctrine/ORM/Event/ListenersInvoker.php:117                                                                                                                                                                       
     [exec]  Doctrine\ORM\Event\ListenersInvoker->invoke() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:985
     [exec]  Doctrine\ORM\UnitOfWork->executeInserts() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:335
     [exec]  Doctrine\ORM\UnitOfWork->commit() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:389
     [exec]  Doctrine\ORM\EntityManager->flush() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/core-bundle/Model/BaseManager.php:121
     [exec]  Sonata\CoreBundle\Model\BaseManager->save() at /home/guillaume/PhpstormProjects/axiona/vendor/sonata-project/media-bundle/Entity/MediaManager.php:41
     [exec]  Sonata\MediaBundle\Entity\MediaManager->save() at /home/guillaume/PhpstormProjects/axiona/src/Axiona/DataBundle/DataFixtures/ORM/LoadProductData.php:55
     [exec]  Sonata\Bundle\DemoBundle\DataFixtures\ORM\LoadProductData->load() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php:121                                                                                                                                            
     [exec]  Doctrine\Common\DataFixtures\Executor\AbstractExecutor->load() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:83                                                                                                                                                     
     [exec]  Doctrine\Common\DataFixtures\Executor\ORMExecutor->Doctrine\Common\DataFixtures\Executor\{closure}() at n/a:n/a
     [exec]  call_user_func() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:243
     [exec]  Doctrine\ORM\EntityManager->transactional() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:85                                                                                                                                                                        
     [exec]  Doctrine\Common\DataFixtures\Executor\ORMExecutor->execute() at /home/guillaume/PhpstormProjects/axiona/vendor/doctrine/doctrine-fixtures-bundle/Doctrine/Bundle/FixturesBundle/Command/LoadDataFixturesDoctrineCommand.php:106                                                                                                                          
     [exec]  Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:244                                                                                                                                                
     [exec]  Symfony\Component\Console\Command\Command->run() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:900
     [exec]  Symfony\Component\Console\Application->doRunCommand() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
     [exec]  Symfony\Component\Console\Application->doRun() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
     [exec]  Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/guillaume/PhpstormProjects/axiona/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
     [exec]  Symfony\Component\Console\Application->run() at /home/guillaume/PhpstormProjects/axiona/app/console:27

The same video with a simple file_get_contents('http://...') can be DL.

Daherak commented 9 years ago

Same bug for me. Can't upload youtube videos anymore.

ternel commented 9 years ago

Workaround: you can use the curl connector, works for me.

sonata_media:
    buzz:
        connector:  sonata.media.buzz.connector.curl
mrpdean commented 9 years ago

@ternel thanks for the workaround.

Saved me a lot of grief :)

catchamonkey commented 9 years ago

Is this at all related to any recent Youtube API changes?

Uriziel commented 9 years ago

It is. Youtube is now using https by default in their API. If you update your php version though (and openssl?) it should work again. It's not sonata's fault, it's your php's.

catchamonkey commented 9 years ago

Hmmm not sure there @Uriziel

I'm running PHP 5.5.22 (Latest), and Open SSL 1.0.1 so both are up to date (save a couple of small minors), yet the problem persists.

Uriziel commented 9 years ago

@catchamonkey I had the problem on 5.5, currently running 5.6.7-1, openssl 1.0.2a and ssl-cert 1.0.36. Everything works.

catchamonkey commented 9 years ago

I'll try something else, moving to 5.6 on an existing server seems overkill a change in the short term for this.

Cheers.

Uriziel commented 9 years ago

Yeah, I'm running it on Debian testing, on a test server. Try to update ssl-cert (or equivalent), as the error is associated with youtube certificate being rejected.

bnd170 commented 9 years ago

cURL solution works for me. Thanks alot.

fundup commented 9 years ago

I can't install a certificate. So curl connectors works fine but not fix this correctly. Maybe an option: use_https:true/false to get thumbnails on different uri could fix this ? (why should we use https to get an image ?)

Uriziel commented 9 years ago

I think taking any action here would be just a hack in bundle unrelated to the problem.

rande commented 9 years ago

Here a complete extract of the current issue:

$context = [
    'http' => [
        'method' => 'GET',
        'header' => null,
        'content' => null,
        'protocol_version' => 1,
        'ignore_errors' => 1,
        'follow_location' => 1,
        'max_redirects' => 6,
        'timeout' => 5,
    ],
    'ssl' => [
        'verify_peer' => 1
    ]
];

$content = file_get_contents("https://i.ytimg.com/vi/3Daw0vxENCU/hqdefault.jpg", 0, stream_context_create($context));

The error:

PHP Warning:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /vagrant/php/sonata-sandbox-2-4-develop/youtube.php on line 20
PHP Warning:  file_get_contents(): Failed to enable crypto in /vagrant/php/sonata-sandbox-2-4-develop/youtube.php on line 20
PHP Warning:  file_get_contents(https://i.ytimg.com/vi/3Daw0vxENCU/hqdefault.jpg): failed to open stream: operation failed in /vagrant/php/sonata-sandbox-2-4-develop/youtube.php on line 20
rande commented 9 years ago

to fix the issue, the ssl option: capath must be set a valid folder, ie /etc/ssl/certs on debian

rande commented 9 years ago

The current issue cannot be solve in this bundle. The issue is part of the Buzz library which does not accept a capath argument. So, if you want to use file_get_contents, you need to use php 5.6 which include a runtime configuration openssl.capath which can be used to set the path or use curl.

We are going to change the default service to curl for now on this bundle.

mdford commented 9 years ago

For those of you who had success with the curl connector, what version of media bundle are you using? I made the changes to use curl, but I still get same error. Yes, I have cleared cache, restarted server, etc. I just upgraded to media bundle version 2.3.1 (from 2.2.8) and still have the same issue. So, I am not sure why changing to curl does not work for me. Any other suggestions, ideas?

Update:

Instead of going through admin, I created the following quick test:

    /**
     * @Route("/testcurl", name="test_curl")
     */
    public function testCurlAction()
    {

        $mm = $this->get('sonata.media.manager.media');

        /** @var Media $media */
        $media = $mm->create();
        $media->setDescription('description');
        $media->setName('mediaName');
        $media->setBinaryContent('https://www.youtube.com/watch?v=JVkb7ulSnjA');
        $media->setEnabled(1);

        $mm->save($media, 'default', 'sonata.media.provider.youtube');

        $status = array(
            'status' => 200,
            'message' => ''
        );

        return new Response(json_encode($status), 200, array('Content-Type' => 'application/json'));
    }

I now get the following exception:

<url> malformed
500 Internal Server Error - RequestException 

Stack Trace
in /vagrant/vendor/kriswallsmith/buzz/lib/Buzz/Client/Curl.php at line 29   -
            $errorMsg = curl_error($this->lastCurl);
            $errorNo  = curl_errno($this->lastCurl);
            $e = new RequestException($errorMsg, $errorNo);
            $e->setRequest($request);
            throw $e;
at Curl ->send (object(Request), object(Response)) 
in /vagrant/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php at line 130   + 
at Browser ->send (object(Request)) 
in /vagrant/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php at line 82   + 
at Browser ->call (null, 'GET', array()) 
in /vagrant/vendor/kriswallsmith/buzz/lib/Buzz/Browser.php at line 31   + 
at Browser ->get (null) 
in /var/cache/symfony/dev/classes.php at line 16167   + 
at BaseVideoProvider ->getReferenceFile (object(Media)) 
in /var/cache/symfony/dev/classes.php at line 17345   + 
at FormatThumbnail ->generate (object(YouTubeProvider), object(Media)) 
in /var/cache/symfony/dev/classes.php at line 16028   + 
at BaseProvider ->generateThumbnails (object(Media)) 
in /var/cache/symfony/dev/classes.php at line 16218   + 
at BaseVideoProvider ->postPersist (object(Media)) 
in /vagrant/vendor/sonata-project/media-bundle/Listener/BaseMediaEventSubscriber.php at line 114   + 
at BaseMediaEventSubscriber ->postPersist (object(LifecycleEventArgs)) 
in /vagrant/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php at line 63   + 
at ContainerAwareEventManager ->dispatchEvent ('postPersist', object(LifecycleEventArgs)) 
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 953   + 
at UnitOfWork ->executeInserts (object(ClassMetadata)) 
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php at line 318   + 
at UnitOfWork ->commit (null) 
in /vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php at line 355   + 
at EntityManager ->flush (null) 
in /var/cache/symfony/dev/jms_diextra/doctrine/EntityManager_555b82d289159.php at line 362   + 
at EntityManager ->flush () 
in /vagrant/vendor/sonata-project/core-bundle/Model/BaseManager.php at line 121   + 
at BaseManager ->save (object(Media), true) 
in /vagrant/vendor/sonata-project/media-bundle/Entity/MediaManager.php at line 41   + 
at MediaManager ->save (object(Media), 'default', 'sonata.media.provider.youtube') 
in /vagrant/src/Thorlos/AppBundle/Controller/DefaultController.php at line 546   + 
at DefaultController ->testCurlAction () 
at call_user_func_array (array(object(DefaultController), 'testCurlAction'), array()) 
in kernel.root_dir/bootstrap.php.cache at line 1077   + 
at HttpKernel ->handleRaw (object(Request), '1') 
in kernel.root_dir/bootstrap.php.cache at line 1051   + 
at HttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 1180   + 
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) 
in kernel.root_dir/bootstrap.php.cache at line 459   + 
at Kernel ->handle (object(Request)) 
in /vagrant/web/app_dev.php at line 44   + 
anton-kasperovich commented 9 years ago

Helped :+1:

buzz:
     connector:  sonata.media.buzz.connector.curl

I use (lines from composer.lock):

            "name": "sonata-project/media-bundle",
            "version": "2.3.0",
            "source": {
                "type": "git",
                "url": "https://github.com/sonata-project/SonataMediaBundle.git",
                "reference": "1a1e89f5a6daf586969be210ed41e1b38aba7ac2"
            },
adyballa commented 9 years ago

If you use your own Provider you can cancel verification via

->browser->getClient()->setVerifyPeer(false);

I think it is okay with Youtube and this Provider since it was not made for SSL.