Skip to content

Commit

Permalink
Version 1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ARTEZON committed Feb 3, 2023
1 parent ec2337f commit 8837e11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
25 changes: 20 additions & 5 deletions TGIDownloader_EN.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from time import sleep
import threading
import mimetypes
import imghdr
import re
import os

Expand Down Expand Up @@ -155,7 +154,23 @@ def validName(name):
return name


def print_percent(last_percent=-1):
def guessImageType(content):
if content[6:10] in (b'JFIF', b'Exif'):
return 'jpg'
if content.startswith(b'\211PNG\r\n\032\n'):
return 'png'
if content[:6] in (b'GIF87a', b'GIF89a'):
return 'gif'
if content[:2] in (b'MM', b'II'):
return 'tiff'
if content.startswith(b'BM'):
return 'bmp'
if content.startswith(b'RIFF') and h[8:12] == b'WEBP':
return 'webp'
return 'unknown'


def printPercentage(last_percent=-1):
global this_successful, this_failed, this_skipped, this_count
global stop
while not stop:
Expand Down Expand Up @@ -198,7 +213,7 @@ def download(imgNumber, imgUrl):
errorCode = 'Connection failed or timed out. If source image site is blocked in your country, enable VPN and run the script again'
success = False
raise ValueError()
extension = imghdr.what(file=None, h=temp_imgData.content)
extension = guessImageType(temp_imgData.content)

retries = 0
timedOutError = False
Expand Down Expand Up @@ -400,7 +415,7 @@ def main():

this_count = len(imgs)
stop = False
threading.Thread(target=print_percent).start()
threading.Thread(target=printPercentage).start()

imgNumber = 0
for imgUrl in imgs:
Expand Down Expand Up @@ -451,7 +466,7 @@ def main():
main()
print('\nPress Enter to continue.')
wait_for_enter_key('')
except KeyboardInterrupt:
except (KeyboardInterrupt, EOFError):
print('\nProgram was terminated by user.')
os._exit(0)
except:
Expand Down
25 changes: 20 additions & 5 deletions TGIDownloader_RU.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from time import sleep
import threading
import mimetypes
import imghdr
import re
import os

Expand Down Expand Up @@ -155,7 +154,23 @@ def validName(name):
return name


def print_percent(last_percent=-1):
def guessImageType(content):
if content[6:10] in (b'JFIF', b'Exif'):
return 'jpg'
if content.startswith(b'\211PNG\r\n\032\n'):
return 'png'
if content[:6] in (b'GIF87a', b'GIF89a'):
return 'gif'
if content[:2] in (b'MM', b'II'):
return 'tiff'
if content.startswith(b'BM'):
return 'bmp'
if content.startswith(b'RIFF') and h[8:12] == b'WEBP':
return 'webp'
return 'unknown'


def printPercentage(last_percent=-1):
global this_successful, this_failed, this_skipped, this_count
global stop
while not stop:
Expand Down Expand Up @@ -198,7 +213,7 @@ def download(imgNumber, imgUrl):
errorCode = 'Не удалось установить соединение или время на подключение истекло. Если сайт с исходным изображением заблокирован в вашей стране, включите VPN и запустите скрипт ещё раз'
success = False
raise ValueError()
extension = imghdr.what(file=None, h=temp_imgData.content)
extension = guessImageType(temp_imgData.content)

retries = 0
timedOutError = False
Expand Down Expand Up @@ -400,7 +415,7 @@ def main():

this_count = len(imgs)
stop = False
threading.Thread(target=print_percent).start()
threading.Thread(target=printPercentage).start()

imgNumber = 0
for imgUrl in imgs:
Expand Down Expand Up @@ -451,7 +466,7 @@ def main():
main()
print('\nДля продолжения нажмите Enter.')
wait_for_enter_key('')
except KeyboardInterrupt:
except (KeyboardInterrupt, EOFError):
print('\nПрограмма была завершена пользователем.')
os._exit(0)
except:
Expand Down

0 comments on commit 8837e11

Please sign in to comment.