]> git.bitcoin.ninja Git - youtube-dl/commitdiff
corrected -U to support new zipfile and exe (#153) formats
authorFilippo Valsorda <filippo.valsorda@gmail.com>
Fri, 30 Mar 2012 23:19:30 +0000 (01:19 +0200)
committerFilippo Valsorda <filippo.valsorda@gmail.com>
Fri, 30 Mar 2012 23:19:30 +0000 (01:19 +0200)
build_exe.py
youtube-dl
youtube-dl.exe [new file with mode: 0644]
youtube_dl/__init__.py

index 4cf064e83ff1b7349f16233f379c0d11a2e3b92b..338c10f66e6f73fde1f2dcec6cdc1710c8cd2caf 100644 (file)
@@ -1,11 +1,12 @@
 from distutils.core import setup
 import py2exe
-import sys
+import sys, os
 
 # If run without args, build executables
 if len(sys.argv) == 1:
     sys.argv.append("py2exe")
 
+os.chdir(os.path.dirname(sys.argv[0]))
 sys.path.append('./youtube_dl')
 
 options = {
@@ -21,10 +22,23 @@ console = [{
     "dest_base": "youtube-dl",
 }]
 
-setup(
-    console = console,
-    options = {"py2exe": options},
-    zipfile = None,
+init_file = open('./youtube_dl/__init__.py')
+for line in init_file.readlines():
+    if line.startswith('__version__'):
+        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
index d088bd9532507833210d3d04f20f7216fbf62b4b..7e4640c66d20f715a1f98766cc466a5dfab2d037 100755 (executable)
Binary files a/youtube-dl and b/youtube-dl differ
diff --git a/youtube-dl.exe b/youtube-dl.exe
new file mode 100644 (file)
index 0000000..29e2219
Binary files /dev/null and b/youtube-dl.exe differ
index 6d2b0ce8552734cee8d9aa1c0b9a01c4f70f82e3..6e6946fdaf3b2eb121043928c09c14a8f5cf2970 100644 (file)
@@ -22,6 +22,8 @@ __license__ = 'Public Domain'
 __version__ = '2012.02.27'
 
 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
@@ -44,33 +46,62 @@ from PostProcessing import *
 def updateSelf(downloader, filename):
        ''' Update the program file with the latest version from the repository '''
        # Note: downloader only used for options
+       
        if not os.access(filename, os.W_OK):
                sys.exit('ERROR: no write permissions on %s' % filename)
 
        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:
                        urlh = urllib2.urlopen(UPDATE_URL)
                        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()
-       except (IOError, OSError), err:
-               sys.exit('ERROR: unable to download latest version')
+               except (IOError, OSError), err:
+                       sys.exit('ERROR: unable to download latest version')
 
-       try:
-               outf = open(filename, 'wb')
                try:
-                       outf.write(newcontent)
-               finally:
-                       outf.close()
-       except (IOError, OSError), err:
-               sys.exit('ERROR: unable to overwrite current version')
+                       outf = open(filename, 'wb')
+                       try:
+                               outf.write(newcontent)
+                       finally:
+                               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.')