Python youtube-dl recompile
Asked Answered
M

1

4

The old youtube-dl use to be just one file so it was easy for me to edit. The new version has multiple files inside of it. To get it to work on my server I needed to extract the files and change the python path. Now how do I put it back together? The youtube-dl site says make compile.

youtube-dl contains main.py, init.py, FileDownloader.py, InfoExtractors.py, PostProcessor.py, utils.py

I need to put those scripts back into a single youtube-dl file. I'm running CentOS.

Thanks for your help!

Massacre answered 2/10, 2012 at 1:50 Comment(4)
Why do you need a single file? Can't you use the package?Undersexed
So I can move the single file to /usr/bin and run the script via the youtube-dl command.Massacre
Actually, if all you needed was to change the Python path, then you could've just edited the hashbang line without extracting the whole thing.Undersexed
Awesome!! Will try it here in a minute. :)Massacre
U
5

If all you want is to change the interpreter line (the hashbang), you should edit the file.

Since it's a binary file, you can't use a normal text editor. I'd recommend just editing it with a Python script:

with open('youtube-dl', 'rb') as f:
    header = f.readline()
    zipfile = f.read()

with open('youtube-dl-new', 'wb') as f:
    print >> f, '#!/your/new/hashbang/line'
    f.write(zipfile)

In Python 3:

with open('youtube-dl', 'rb') as f:
    header = f.readline()
    zipfile = f.read()

with open('youtube-dl-new', 'wb') as f:
    print('#!/your/new/hashbang/line', file=f)
    f.write(zipfile)
Undersexed answered 2/10, 2012 at 2:41 Comment(5)
I guess what he is looking for, is to have youtube-dl on system path.Win
Maybe both, but he specifically mentioned, that he wants to put everything back to /usr/bin. So I guess, that's how he ran it before, and what he wants to do again.Win
youtube-dl is a zipfile with a hashbang header. This answer just shows how to edit the hashbang header without having to rebuild the embedded zipfile. Then youtube-dl-new could be copied to /usr/bin/youtube-dl.Undersexed
I am also trying to use this script to replace the hashbang header in youtube-dl, so I added your script to a file called rename.py and changed its permissions to 755 ran it and get this error: TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.BufferedWriter' can you help me?Vivavivace
@Llewellyn: Seems you are using Python 3. I will update the answer.Undersexed

© 2022 - 2024 — McMap. All rights reserved.