Skip to content

Commit

Permalink
Beta Fix #2
Browse files Browse the repository at this point in the history
Made the scripts work with channels with less than 25 images/videos on them.
  • Loading branch information
KimChoJapFan committed Apr 8, 2018
1 parent 2c69b0a commit f197baa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ Let the script run (it may take a while to finish) the beta version of this scri

# Changelog (DD-MM-YYYY)

02-21-2018 - Beta Update #1:
07-04-2018 - Beta Fix #2:
* Fixed problems when downloading from channels with less than 25 images/videos as the older scripts assumed more than 25 images/videos in the channel.
* I will incorporate a better method of grabbing images where there's less corruptions and less missing photos.

21-02-2018 - Beta Update #1:
* Updated this readme to include warning information
* Created a version for those running Python 3
* Updated the Python 2 version to match the Python 3 version with threading support
Expand Down
4 changes: 2 additions & 2 deletions python2_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def __init__(self):
self.channel = '<CHANNEL ID>'
self.query = 'has=image&has=video&include_nsfw=true'

def grabJSON(self, page=1):
def grabJSON(self, page=0):
url, opener = 'https://discordapp.com/api/v6/guilds/{}/messages/search?{}&channel_id={}&offset={}'.format(self.server, self.query, self.channel, page * 25), urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.300 Chrome/56.0.2924.87 Discord/1.6.15 Safari/537.36'), ('authorization', self.token)]
urllib2.install_opener(opener)
Expand All @@ -33,7 +33,7 @@ def saveFile(self, fileUrl, dataPath):
dataPath = os.path.join(os.getcwd(), folderName)
if not os.path.exists(dataPath): os.mkdir(dataPath)

for i in range(1, numPages + 1):
for i in range(numPages):
jsonData = discord.grabJSON(i)

for messages in jsonData['messages']:
Expand Down
4 changes: 2 additions & 2 deletions python3_discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self):
self.channel = '<CHANNEL ID>'
self.query = 'has=image&has=video&include_nsfw=true'

def grabJSON(self, page=1):
def grabJSON(self, page=0):
url, header = 'https://discordapp.com/api/v6/guilds/{}/messages/search?{}&channel_id={}&offset={}'.format(self.server, self.query, self.channel, page * 25), {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.300 Chrome/56.0.2924.87 Discord/1.6.15 Safari/537.36', 'authorization': self.token}
jsonContents = requests.get(url, headers=header, verify=False, allow_redirects=False)

Expand All @@ -34,7 +34,7 @@ def saveFile(self, fileUrl, dataPath):
dataPath = os.path.join(os.getcwd(), folderName)
if not os.path.exists(dataPath): os.mkdir(dataPath)

for i in range(1, numPages + 1):
for i in range(numPages):
jsonData = discord.grabJSON(i)

for messages in jsonData['messages']:
Expand Down

0 comments on commit f197baa

Please sign in to comment.