Download & Extend

Retain Details of Source File After Transcoding

Project:Video
Version:6.x-3.4
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

When a video file is saved, the field stores a filename, filepath, filemime, and filesize for that file. When the file is transcoded, all these details are replaced with those of the transcoded file and effectively lost. But those details may still be important. For example, I'm playing the transcoded video in a Flash player, but I'm linking to the original Mp4 to download. Presently I have to write my own logic to find the source file based on the path of its "replacement" (a process not only laborious but prone to error). I think this information should be stored in the field where I can just read and print it. Thanks!

Comments

#1

You can find that informtion in data of upload field's databse. there i will store the old file id so you can get it.

#2

I'm sorry; that's not fully clear to me. Can you explain how I would go about accessing that information then?

#3

I'm trying to do the same exact thing as TravisCardin.

Travis, can you elaborate on how you are using php to manipulate the file path at the moment?

#4

Sure, kevin riggen. Here's the basic PHP I'm using in my theme's template.php. Basically it just tests the filefield file path to see if it ends with ".flv". If it does, it puts that value in a variable $video_flv_filepath, and then it strips off the ".flv" extension and stores the result in $video_source_filepath. If the filepath doesn't end in ".flv", it sets $video_flv_filepath to FALSE so you can test against it in your theme. The code, as it stands, doesn't test to make sure the file at $video_source_filpath actually exists. Most of the time it's safe to assume that it does, but if you've previously removed a file in the filefield and re-uploaded a new one and you're using certain file renaming patterns, this logic will be inadequate. See the bug filed at #698528: Deleting Node Removes Pre-Transcoded Video, but Just Removing the Upload Doesn't. Here's the code:

<?php
/**
* Override or insert variables into the node templates.
*
* @param $vars
*   An array of variables to pass to the theme template.
* @param $hook
*   The name of the template being rendered ("node" in this case.)
*/
function YOURTHEMENAME_preprocess_node(&$vars, $hook) {
 
$node = &$vars['node'];
  if (
$node->field_video[0]['filepath']) {
   
$video = $node->field_video[0];
   
// Break up file path around periods
   
$parts = explode('.', $node->field_video[0]['filepath']);
   
// Last piece is the file extension
   
$ext = $parts[sizeof($parts) - 1];
    if (
$ext == 'flv') {
     
// Video has been transcoded
     
$video_flv_filepath = $video['filepath'];
     
$video_source_filepath = substr($video_flv_filepath, 0, strlen($video_source_filepath) - 4);
    } else {
     
// Video has not been transcoded
     
$video_flv_filepath = FALSE;
     
$video_source_filepath = $video['filepath'];
    }
   
$vars['video_flv_filepath'] = $video_flv_filepath;
   
$vars['video_source_filepath'] = $video_source_filepath;
  }
}
?>

#5

Thank you. This worked beautifully.

For anyone else interested, here are the things I had to learn before implementing the above:

1) Some themes already have the above function YOURTHEMENAME_preprocess_node within template.php. For instance, the zen theme uses it in the zen subfolder (not your sub theme folder). In that case, just paste the above code within whatever is already in that function.

2) Within the function, make sure that "field_video" is renamed to whatever you named your CCK Video field to. For instance, mine was field_video_upload.

3) After this is finished, you can do something like this within your node-video.tpl.php file:

<?php print "<a href=/" . $video_source_filepath . ">Download .mp4 video</a>" ?>

#6

In regards to JKProduktion's message to me

Hi,

i just wrote this Text because I need your help.
My english isn´t the best and so i don´t realy understand this post:

http://drupal.org/node/700048

I want to ask whether you can explain to me, how I could post automaticly a simple donwload link into the nodes, which are created by the upload form. I just want to give users the possibilty to download the files which are played in the player. I don´t convert the videos, so I just want to build a link with the path of the file. But where should I save this, or which file I have to edit.

Hope you undertand me an will help me ;)

Greetings from Germany, JKProduktion.

1) Create a function in template.php called YOURTHEME_preprocess_node. See #4
This might already be created in template.php. If so, just add to it.

2) Change YOURTHEME to the name of your them (i.e. Zen theme would be "zen_preprocess_node")

3) Change field_video[0] to "your_video_field"[0]

4) In your node-YOURNODETYPE.tpl.php, add the following link where you want the link to appear:

<?php
print "<a href=/" . $video_source_filepath . ">Download video</a>"
?>

#7

Thanks for your help,
but I still don´t get trough it.
I´m using the standard garland theme.
So i openende the template.php in the garland folder, edited it and add at the end the whole code from post #4.

I changed YOURTHEME in garland.
Changed field_video three times in field_footage (my field type in cck).

Then I edited the note.tpl.php in the garland theme folder and added the code.

When I open the site, I see the link, but it always links to the start page...

Pls help me :)

#8

Can you copy the source of the node page with Firebug or something? I want to see how the $video_source_filepath is printing out for you. Also post your node.tpl.php please.

#9

Okay, thanks for your help...

This is my node.tpl.php in the garland folder. (btw. if I add the download link, it´s on every normal node site also)

<?php
// $Id: node.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">

<?php print $picture ?>

<?php if ($page == 0): ?>
  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>

  <?php if ($submitted): ?>
    <span class="submitted"><?php print $submitted; ?></span>
  <?php endif; ?>

  <div class="content clear-block">
    <?php print $content ?>
  </div>


// Download Link
<?php
print "<a href=/" . $video_source_filepath . ">Download video</a>"
?>


  <div class="clear-block">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>

</div>

I don´t understand the firebug code, but this is an example site:
http://footage.square7.de/?q=node/5

Maybe you could help me now?

:)

#10

1) If you don't want it to show up on every node, you need to copy node.tpl.php into a file called node-YOUR_NODE.tpl.php

2) It seems like the code from #4 is working for you, but the filepath is getting truncated for some reason. Can you post the exact name of your file?

3) Maybe try this :

<?php print "<a href=/'" . $video_source_filepath . "'>Download video</a>"; ?>

That should surround your file path with a ' ' and possibly fix the situation.

Also put a semicolon at the end of your print statement.

#11

All right!
Very big Thanks!
It works!

but now just some adjustments ;-)

1. If I have spaces in the file name, the download link ist only printed to the first space.
2. Would it be very difficult to enable the download link only for registert users.
3. What do I have to do with my changed node. I copied the node.tpl.php and named it footage.tpl.php

A thousand thanks!!!

#12

1. Spaces in the filename need to be addressed by adding the single quotes i mentioned in my previous post. I would avoid spaces to be honest.

2. To only show the link to registered users wrap the code in a PHP If statement like this :

//script to show something to registered users only
if ( $user->uid ) {
        print "<a href=/'" . $video_source_filepath . "'>Download video</a>";
}

3. You don't name it footage.tpl.php, you name it node-footage.tpl.php

#13

FANTASTIC!
Now everything works fine, except the rpoblem with spaces.
If I use single quotes, the whole downloading doesn´t work. But maybe I just have to tell my users to don´t use spaces in the file name.

VERY BIG THANKS again. What a great helping community!
If there´s something I could do for you... ;)

#14

@JKProduktion: Spaces in URLs need to be encoded (as %20, incidentally). Normally you would accomplish this with PHP's urlencode function, but Drupal will do it for you if you use the built-in l (link) function:

<?php
// Show to registered users only
if ($user->uid) {
  print
l('Download video', $video_source_filepath);
}
?>

#15

To the powers that be: Is there any word yet on how to ("correctly") retrieve the original file details from the database?

#16

Now it makes a perfect link, but there´s a ?q= in it.

For example:
http://website.com/?q=sites/default/files/footage/Du%20bist%20der%20deut...

But it only works with:
http://website.com/sites/default/files/footage/Du%20bist%20der%20deutsch...

If have to remove ?q=

Is there still a possibility ;)?

#17

@JKProduktion: Do you plan to turn on clean URLs? You probably should if you can. If you do, it will eliminate the problem with the ?q= both here and everywhere.

#18

WOW!
Finaly everything runs nicely.
Again big thanks! Great community, thanks Kevin Riggen!

Last adjustment would be to place the video player only in the read on section? ;P

#19

<?php if ($page): ?>
  <!-- Put anything you only want to display on the full node view in here -->
<?php endif; ?>

If you have any more questions, @JKProduktion, you should probably post them to the forum, ask them on IRC, or, if appropriate, open a new issue and categorize it "support request". This issue is really about adding a feature to the module, as opposed to using it. We're glad we could help, though. :)

#20

Okay,
but I wanted to know, where I have to edit which file, with this PHP tag you posted in #19 :P Im a noob!

#21

@JKProduktion, if you'll create a post in the form and send me a link to it I'll gladly help you there, but this issue isn't the place for support. (The people for whom it was originally posted probably started ignoring it a long time ago for the noise.)

#22

Sounds overly complicated to get the original video. The video module transcodes this video, makes perfect sense to replace (in theory). Sometimes there's a time to have the original on hand, and I agree. How about this (for now). Create two CCK fields. One for the original, and one for the Conversion... easy button.

#23

Thank you, @iLLin. So are you suggesting as an interim solution that we (site builders) create two separate filefields, upload the original video file to both of them, and have only one of them transcoded? This could possibly provide a temporary solution for some, but it results in two copies of the original video file on the server, which could be a huge cost in disk space for some. I don't know how to program CCK yet, but I assumed it was be fairly trivial to just add another attribute to the field to store the original filename and filepath. Do you think we could shoot for that in the long term?

#24

Well it backs everything up now into a serialized object in the video_rendering table. Stores the old fid information. I have to admit when I first saw how this module was doing that, I was like WTF!? What happens if I want to re-transcode it? When i was using the flashvideo module, it had to be re-transcoded to create a new thumbnail. Well this module recreates everytime you view so I ignored it during my rebuild.

What is the goal of the original file? It seemed you just wanted a way to allow users to download the original as it was, so I figured that was a good solution. I have to get back in there anyway to make sure the files are being deleted correctly (not sure if they are) so I might as well re-evaluate what's going on with the original and the newly created file.

As far as being trivial. It sorta is if you just want to store data, but if you want that data usable, thats another matter. It just depends on what the end game here is. Let me know and we can start working on getting this fixed.

#25

Thank you, @iLLin. My personal need for the original file is, as you say, just to make it available to download in its original format. My scenario is a media vault where the user can watch the transcoded video in a Flash player but may want to download in MP4 for their iPod or what have you. Thanks for looking into this with me. As to deleting files, you might want to check out #698528: Deleting Node Removes Pre-Transcoded Video, but Just Removing the Upload Doesn't, which I posted around the same time as this issue. Thanks!

#26

Status:active» fixed

Big update to 4.x-dev: http://drupal.org/cvs?commit=366886
Keeps original and deletes everything correctly. Thumbnails are deleted too. Cleanup should be good now!

#27

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here