mirror of
https://github.com/l1ving/youtube-dl
synced 2024-12-30 22:12:52 +08:00
corrected -U to support new zipfile and exe (#153) formats
This commit is contained in:
parent
303692b5ed
commit
53e893615d
24
build_exe.py
24
build_exe.py
@ -1,11 +1,12 @@
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
import py2exe
|
import py2exe
|
||||||
import sys
|
import sys, os
|
||||||
|
|
||||||
# If run without args, build executables
|
# If run without args, build executables
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
sys.argv.append("py2exe")
|
sys.argv.append("py2exe")
|
||||||
|
|
||||||
|
os.chdir(os.path.dirname(sys.argv[0]))
|
||||||
sys.path.append('./youtube_dl')
|
sys.path.append('./youtube_dl')
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
@ -21,10 +22,23 @@ console = [{
|
|||||||
"dest_base": "youtube-dl",
|
"dest_base": "youtube-dl",
|
||||||
}]
|
}]
|
||||||
|
|
||||||
setup(
|
init_file = open('./youtube_dl/__init__.py')
|
||||||
console = console,
|
for line in init_file.readlines():
|
||||||
options = {"py2exe": options},
|
if line.startswith('__version__'):
|
||||||
zipfile = None,
|
version = line[11:].strip(" ='\n")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
version = ''
|
||||||
|
|
||||||
|
setup(name='youtube-dl',
|
||||||
|
version=version,
|
||||||
|
description='Small command-line program to download videos from YouTube.com and other video sites',
|
||||||
|
url='https://github.com/rg3/youtube-dl',
|
||||||
|
packages=['youtube_dl'],
|
||||||
|
|
||||||
|
console = console,
|
||||||
|
options = {"py2exe": options},
|
||||||
|
zipfile = None,
|
||||||
)
|
)
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
BIN
youtube-dl
BIN
youtube-dl
Binary file not shown.
BIN
youtube-dl.exe
Normal file
BIN
youtube-dl.exe
Normal file
Binary file not shown.
@ -22,6 +22,8 @@ __license__ = 'Public Domain'
|
|||||||
__version__ = '2012.02.27'
|
__version__ = '2012.02.27'
|
||||||
|
|
||||||
UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
|
UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
|
||||||
|
UPDATE_URL_VERSION = 'https://raw.github.com/rg3/youtube-dl/master/LATEST_VERSION'
|
||||||
|
UPDATE_URL_EXE = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl.exe'
|
||||||
|
|
||||||
|
|
||||||
import cookielib
|
import cookielib
|
||||||
@ -44,33 +46,62 @@ from PostProcessing import *
|
|||||||
def updateSelf(downloader, filename):
|
def updateSelf(downloader, filename):
|
||||||
''' Update the program file with the latest version from the repository '''
|
''' Update the program file with the latest version from the repository '''
|
||||||
# Note: downloader only used for options
|
# Note: downloader only used for options
|
||||||
|
|
||||||
if not os.access(filename, os.W_OK):
|
if not os.access(filename, os.W_OK):
|
||||||
sys.exit('ERROR: no write permissions on %s' % filename)
|
sys.exit('ERROR: no write permissions on %s' % filename)
|
||||||
|
|
||||||
downloader.to_screen(u'Updating to latest version...')
|
downloader.to_screen(u'Updating to latest version...')
|
||||||
|
|
||||||
try:
|
urlv = urllib2.urlopen(UPDATE_URL_VERSION)
|
||||||
|
newversion = urlv.read().strip()
|
||||||
|
if newversion == __version__:
|
||||||
|
downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
|
||||||
|
return
|
||||||
|
urlv.close()
|
||||||
|
|
||||||
|
if hasattr(sys, "frozen"): #py2exe
|
||||||
|
directory = os.path.dirname(filename)
|
||||||
|
exe = os.path.abspath(filename)
|
||||||
|
if not os.access(directory, os.W_OK):
|
||||||
|
sys.exit('ERROR: no write permissions on %s' % directory)
|
||||||
|
|
||||||
|
try:
|
||||||
|
urllib.urlretrieve(UPDATE_URL_EXE, exe + '.new')
|
||||||
|
except (IOError, OSError), err:
|
||||||
|
sys.exit('ERROR: unable to download latest version')
|
||||||
|
|
||||||
|
try:
|
||||||
|
bat = os.path.join(directory, 'youtube-dl-updater.bat')
|
||||||
|
b = open(bat, 'w')
|
||||||
|
|
||||||
|
print >> b, """
|
||||||
|
timeout /t 5 /nobreak
|
||||||
|
move /Y "%s.new" "%s"
|
||||||
|
del "%s"
|
||||||
|
""" %(exe, exe, bat)
|
||||||
|
|
||||||
|
b.close()
|
||||||
|
|
||||||
|
os.startfile(bat)
|
||||||
|
except (IOError, OSError), err:
|
||||||
|
sys.exit('ERROR: unable to overwrite current version')
|
||||||
|
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
urlh = urllib2.urlopen(UPDATE_URL)
|
urlh = urllib2.urlopen(UPDATE_URL)
|
||||||
newcontent = urlh.read()
|
newcontent = urlh.read()
|
||||||
|
|
||||||
vmatch = re.search("__version__ = '([^']+)'", newcontent)
|
|
||||||
if vmatch is not None and vmatch.group(1) == __version__:
|
|
||||||
downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
|
|
||||||
return
|
|
||||||
finally:
|
|
||||||
urlh.close()
|
urlh.close()
|
||||||
except (IOError, OSError), err:
|
except (IOError, OSError), err:
|
||||||
sys.exit('ERROR: unable to download latest version')
|
sys.exit('ERROR: unable to download latest version')
|
||||||
|
|
||||||
try:
|
|
||||||
outf = open(filename, 'wb')
|
|
||||||
try:
|
try:
|
||||||
outf.write(newcontent)
|
outf = open(filename, 'wb')
|
||||||
finally:
|
try:
|
||||||
outf.close()
|
outf.write(newcontent)
|
||||||
except (IOError, OSError), err:
|
finally:
|
||||||
sys.exit('ERROR: unable to overwrite current version')
|
outf.close()
|
||||||
|
except (IOError, OSError), err:
|
||||||
|
sys.exit('ERROR: unable to overwrite current version')
|
||||||
|
|
||||||
downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.')
|
downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user