Grab youtube cache and save as MP4

Discussion in 'iOS Jailbreak & Cydia' started by entmike, Oct 22, 2007.

  1. entmike

    entmike New Member

    Joined:
    Sep 21, 2007
    Messages:
    39
    Likes Received:
    0
    Work in progress, but here's what I've done so far:

    Sample script (youtube.sh):

    Code:
    media=$(ls -lart /tmp/MediaCache | grep CachedMedia | awk '{print $9}')
    dd if=/tmp/MediaCache/${media} of=${media}.mp4 ibs=4096 skip=1
    
    Running this will strip the first 4096 bytes from the first cache file it finds in /tmp/MediaCache and save it as the same name with a .mp4 suffix to your current directory. Then, using SCP or whatever method to transfer off your iPod, the file will open and play in Quicktime successfully.

    My problem lies in that once taking this file and copying it to the iPod via iTunes, it only plays the first few seconds before stopping. Maybe I'm truncating too much (4096 bytes) from the beginning. I'm sure others have tried this, but Google turned up nothing. Any help/advice would be appreciated.

    If I can get this working 100%, I'd like to script it where it saves the MP4 for you automatically to whatever directory it's supposed to be in without the need of using a PC to do so.
  2. Andy Huang

    Andy Huang Retired Moderator

    Joined:
    Oct 5, 2007
    Messages:
    968
    Likes Received:
    5
    Device:
    iPhone 4 (Black)
    Interesting hack... why truncate 4kb at the front though? Headers aren't that big if I'm not mistaken...
  3. music4life

    music4life Active Member

    Joined:
    Sep 17, 2007
    Messages:
    816
    Likes Received:
    39
    So this will save youtube videos directly off the iPod with the cache? Woah, I don't really get it, but it sounds amazing, keep up the good work!
  4. RazerM

    RazerM New Member

    Joined:
    Oct 4, 2007
    Messages:
    279
    Likes Received:
    5
    This sounds interesting, I will need to try this. Why did you choose to take four Kb off from beginning? I doubt any header would be that large.
  5. moveteam

    moveteam New Member

    Joined:
    Sep 16, 2007
    Messages:
    123
    Likes Received:
    0
    Change it to 100 kb?

    Hope you get it working

    Please Register or Log in to view images

  6. entmike

    entmike New Member

    Joined:
    Sep 21, 2007
    Messages:
    39
    Likes Received:
    0
    It seemed that the first 4kb was just XML data. You can see this for yourself to see what I mean if you more the file, i.e:
    Code:
    more /tmp/Media/Cache/CachedMedia1234abc
    There seemed to be a lot of XML but not ever more that 4096 bytes of it with what appears to be padding data after it. This was me just eyeballing it, but if I did something like 4080, it was not enough, etc. I didn't even load the file in a hex editor, I just kept slicing chunks using the dd command and looking at it with vi, cat, or more. LOL, it was late at night when I thought about it. I should have just grabbed the whole file with SCP and loaded it in a hex editor to find the offset of the actual MP4 header. Oh, well, it gives me something to do tonight after work.

    Please Register or Log in to view images

  7. RazerM

    RazerM New Member

    Joined:
    Oct 4, 2007
    Messages:
    279
    Likes Received:
    5
    I've looked at the file in hex editor and 4096 looks right, there are three bytes 00 00 00, the identifier for a mp4 file. Although the file plays there must be a slightly different file spec.
  8. Rallos

    Rallos New Member

    Joined:
    Oct 12, 2007
    Messages:
    126
    Likes Received:
    0
    The files that the youtube app is playing are probably a little different and that's why they don't work. When you say they only play for a few seconds is that on your PC or your iPod?
  9. entmike

    entmike New Member

    Joined:
    Sep 21, 2007
    Messages:
    39
    Likes Received:
    0
    It plays fine on the PC, the iPod bombs the video after about 5 seconds.
  10. Andy Huang

    Andy Huang Retired Moderator

    Joined:
    Oct 5, 2007
    Messages:
    968
    Likes Received:
    5
    Device:
    iPhone 4 (Black)
    00 00 00 is just three null bytes, not mp4... MP4 is a container type, so it will have some of its own headers; and then the 4cc markers for its contained contents...

    My guess is that PC is making guess of the video format based on the first little bit, and then maybe extra buffering content messed it up there after...

Share This Page