Dear all,
Every times I try to delete a youtube video from media list (I check the video from media list, then Delete from drop down list), I reveive this error message:
The file was not deleted due to an error

Looking at the recent logs, I can find the error detail:

Type	file
Date	Monday, August 1, 2011 - 17:28
User	xxx
Location	http://lnx.canottaggiotv.it/?q=admin%2Fcontent%2Fmedia%2Fthumbnails&page=1&render=overlay&render=overlay&render=overlay
Referrer	http://lnx.canottaggiotv.it/?q=admin%2Fcontent%2Fmedia%2Fthumbnails&page=1&render=overlay&render=overlay
Message	The file youtube://v/KLVj3A_F9Yw is not of a recognized type so it was not deleted.
Severity	error

The only way to delete a video is to delete it directly from the database.
Is there a way to fix this problem?

Thanks
Davide Taibi

Comments

davide.taibi’s picture

I temporarily solved this issue in a quick and dirty way by modifying directly the file_delete() function in /includes/file.inc
and I added the following code

 if(strcmp($file->filemime, "video/youtube") == 0 ){
  	db_delete('file_managed')->condition('fid', $file->fid)->execute();
    db_delete('file_usage')->condition('fid', $file->fid)->execute();
    return TRUE;
  }

in line 1253

I hope to find a better solution in the future...

Davide Taibi
www.taibi.it

kreynen’s picture

What version of the Media module are you using?

byrond’s picture

I experience the same problem using either Media version 1.0-beta5 or 1.x-dev (Aug 4, 2011 release). file_entity_file_delete() is calling field_attach_delete() to delete the asset. Seems like this needs to be addressed in the Media module, but I'm not sure how.

byrond’s picture

This is also an issue when attempting to delete a Flickr asset from the media library. Same error message.

byrond’s picture

StatusFileSize
new2.13 KB

This should fix the issue without having to hack core. I'm sure it needs work to make things more applicable to other environments. It should probably find its way into the Media module (perhaps media_internet.module)? Maybe that module could implement a stream wrapper that both Media:Youtube and Media:Flickr modules could use. Of course, I may be way off base in how to correct the issue, as I don't know much about any of the Media modules.

byrond’s picture

Status: Active » Needs review
effulgentsia’s picture

Version: 7.x-1.0-alpha5 » 7.x-1.x-dev

What happened was a Drupal core fix (#1083982-36: Fix support for remote streamwrappers) that went in a couple weeks ago broke some (incomplete) remote stream wrappers like this one.

The YouTube stream wrapper in particular is tricky in that the video URI dereferences to a remote video on YouTube's server, while image thumbnails are local (within the 'public' scheme), but image_style_path() requires the original and the derivatives to be in the same scheme, so the stream wrapper needs to manage that.

#5 gets at the right direction of this (thanks, @byrond), but is incomplete in that its new functions handle the image derivatives only, and don't consider that those methods also get called for the original video.

Here's an improved version. It could still use some comments, but I think handles all the needed cases. It may make sense to eventually move some of this into media_internet, but I also think we may want to revisit how we manage image style derivatives of remote images, and possibly redesign that workflow.

effulgentsia’s picture

Oops. Hit "Save" above before uploading the patch.

pwolanin’s picture

Glad you got this working - what's the trick for getting is_file() to be true?

Also, looking at:

$local_path = 'public://media-youtube/' . check_plain($parts['v']) . '.jpg';

Seems like that's not quite right - you might want to urlencode the path parts (I think we did that with file paths in core)?

e2thex’s picture

This is the same patch as #8, but it will work with drush make

dboulet’s picture

Same issue here, subscribe.

jimmynash’s picture

I applied the patch in #8 to my installation of media_youtube version 7.x-1.0-alpha5 and it solved the issue for me.
Modules:
media 7.x-2.x-dev
file_entity 7.x-1.x-dev
media_youtube 7.x-1.0-alpha5

rwohleb’s picture

Patch in #8 confirmed to work with:
media 7.x-1.0-beta5
media_youtube 7.x-1.0-alpha5

effulgentsia’s picture

By the way, I moved the part of #8 that isn't YouTube specific to #1277228: Remote files can't be deleted with Drupal 7.6 and later.

TimelessDomain’s picture

applying patch from link in #14 fixed this error for me (no need to apply any other patches)

ddanier’s picture

subscribing

yogurtur’s picture

I try to apply #8 on my local media_youtube folder but I'm getting a error
1 out of 1 hunk FAILED -- saving rejects to file media_youtube.module.rej

When y do

patch -p0 media_youtube.module < media_youtube-file-not-deleted-1235852-7.patch
Something I must be doing wrong :-(
Abel

byrond’s picture

The patch is against MediaYouTubeStreamWrapper.inc and is not a '-p0' patch. If you remove 'media_youtube.module', use '-p1', and run the command while in the 'media_youtube' module directory, it should work.

RobW’s picture

Status: Needs review » Closed (fixed)

I'm going to trust #15 and say that this was fixed in Media.