mirror of
https://github.com/instaloader/instaloader.git
synced 2024-09-11 16:22:24 +02:00
Fix Windows Unicode Problems
Closes #11. instaloader now tries to use win-unicode-console when recognizing windows.
This commit is contained in:
parent
82ef71836f
commit
dd383d8887
@ -7,6 +7,9 @@ Simple downloader to fetch all Instagram pictures and captions from a given prof
|
|||||||
Ensure having [Python](https://www.python.org/) (at least version 3.3) and
|
Ensure having [Python](https://www.python.org/) (at least version 3.3) and
|
||||||
[python3-requests](https://pypi.python.org/pypi/requests/) installed.
|
[python3-requests](https://pypi.python.org/pypi/requests/) installed.
|
||||||
|
|
||||||
|
If you intend to use this tool under Windows, it is highly recommended to first install
|
||||||
|
[win-unicode-console](https://github.com/Drekin/win-unicode-console).
|
||||||
|
|
||||||
After having [downloaded instaloader.py](https://github.com/Thammus/instaloader/releases), you invoke it with
|
After having [downloaded instaloader.py](https://github.com/Thammus/instaloader/releases), you invoke it with
|
||||||
```
|
```
|
||||||
./instaloader.py profile [profile ...]
|
./instaloader.py profile [profile ...]
|
||||||
|
@ -3,6 +3,15 @@
|
|||||||
import re, json, datetime, shutil, os, time, random, sys, pickle, getpass, tempfile
|
import re, json, datetime, shutil, os, time, random, sys, pickle, getpass, tempfile
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import requests, requests.utils
|
import requests, requests.utils
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
try:
|
||||||
|
import win_unicode_console
|
||||||
|
except ImportError:
|
||||||
|
WINUNICODE = False
|
||||||
|
else:
|
||||||
|
win_unicode_console.enable()
|
||||||
|
WINUNICODE = True
|
||||||
|
|
||||||
class InstaloaderException(Exception):
|
class InstaloaderException(Exception):
|
||||||
"""Base exception for this script"""
|
"""Base exception for this script"""
|
||||||
@ -153,11 +162,15 @@ def download_pic(name, url, date_epoch, outputlabel=None, quiet=False):
|
|||||||
def save_caption(name, date_epoch, caption, quiet=False):
|
def save_caption(name, date_epoch, caption, quiet=False):
|
||||||
filename = name.lower() + '/' + epoch_to_string(date_epoch) + '.txt'
|
filename = name.lower() + '/' + epoch_to_string(date_epoch) + '.txt'
|
||||||
pcaption = caption.replace('\n', ' ').strip()
|
pcaption = caption.replace('\n', ' ').strip()
|
||||||
output = '[' + ((pcaption[:26]+"…") if len(pcaption)>28 else pcaption) + ']'
|
caption = caption.encode("UTF-8")
|
||||||
|
if os.name in ['nt', 'ce'] and not WINUNICODE:
|
||||||
|
output = str()
|
||||||
|
else:
|
||||||
|
output = '[' + ((pcaption[:26]+"…") if len(pcaption)>28 else pcaption) + ']'
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
with open(filename, 'r') as file:
|
with open(filename, 'rb') as file:
|
||||||
file_caption = file.read()
|
file_caption = file.read()
|
||||||
if file_caption == caption:
|
if file_caption.replace(b'\r\n', b'\n') == caption.replace(b'\r\n', b'\n'):
|
||||||
output = output + ' unchanged'
|
output = output + ' unchanged'
|
||||||
log(output, end=' ', flush=True, quiet=quiet)
|
log(output, end=' ', flush=True, quiet=quiet)
|
||||||
return None
|
return None
|
||||||
@ -173,8 +186,8 @@ def save_caption(name, date_epoch, caption, quiet=False):
|
|||||||
output = output + ' updated'
|
output = output + ' updated'
|
||||||
log(output, end=' ', flush=True, quiet=quiet)
|
log(output, end=' ', flush=True, quiet=quiet)
|
||||||
os.makedirs(name.lower(), exist_ok=True)
|
os.makedirs(name.lower(), exist_ok=True)
|
||||||
with open(filename, 'w') as text_file:
|
with open(filename, 'wb') as text_file:
|
||||||
text_file.write(caption)
|
shutil.copyfileobj(BytesIO(caption), text_file)
|
||||||
os.utime(filename, (datetime.datetime.now().timestamp(), date_epoch))
|
os.utime(filename, (datetime.datetime.now().timestamp(), date_epoch))
|
||||||
|
|
||||||
def download_profilepic(name, url, quiet=False):
|
def download_profilepic(name, url, quiet=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user