Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
- imports fix
- attachments_video fix
  • Loading branch information
hikiko4ern committed Mar 26, 2019
1 parent d05eed9 commit 575fdee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
22 changes: 9 additions & 13 deletions dump.py
Expand Up @@ -21,7 +21,7 @@
from youtube_dl import YoutubeDL

NAME = 'VK Dump Tool'
VERSION = '0.9.2'
VERSION = '0.9.3'
API_VERSION = '5.92'


Expand Down Expand Up @@ -484,6 +484,7 @@ class Dumper:
__modules = None

_AVAILABLE_THREADS = os.cpu_count()
_OSNAME = os.name

_settings = {
'REPLACE_SPACES': False, # заменять пробелы на _
Expand Down Expand Up @@ -575,14 +576,11 @@ def _download(dmp, obj, folder, **kwargs):
"""
dmp: Dumper class
"""
# import ipdb
# ipdb.set_trace()
from os import name as osname
if osname == 'nt':
import os
import os.path
import requests
# import shutil
# if dmp._OSNAME == 'nt':
import os
import os.path
import requests
import shutil

if not obj:
return False
Expand Down Expand Up @@ -637,10 +635,8 @@ def _download_video(dmp, v, folder):
"""
dmp: Dumper class
"""
from os import name as osname
if osname == 'nt':
from urllib.request import urlopen
from re import search as research
from urllib.request import urlopen
from re import search as research

if 'platform' in v:
return dmp._download_external(v['player'], folder)
Expand Down
18 changes: 17 additions & 1 deletion modules/attachments.py
Expand Up @@ -135,6 +135,22 @@ def dump_attachments_only(dmp):
video = get_attachments(dmp._vk, did, 'video')

if video['count'] > 0:
video_ids = []
for v in video['items']:
video_ids.append('{oid}_{id}{access_key}'.format(
oid=v['attachment']['video']['owner_id'],
id=v['attachment']['video']['id'],
access_key=('_'+v['attachment']['video']['access_key'] if 'access_key' in v['attachment']['video'] else '')
))
video = dmp._vk_tools.get_all(
method='video.get',
max_count=200,
values={
'videos': ','.join(video_ids),
'extended': 1
}
)

af = os.path.join(at_folder, 'Видео')
os.makedirs(af, exist_ok=True)

Expand All @@ -145,7 +161,7 @@ def dump_attachments_only(dmp):
with Pool(dmp._AVAILABLE_THREADS if dmp._settings['LIMIT_VIDEO_PROCESSES'] else dmp._settings['POOL_PROCESSES']) as pool:
res = pool.starmap(copy_func(dmp._download_video),
zip(itertools.repeat(dmp.__class__),
map(lambda t: t['attachment']['video'], video['items']),
video['items'],
itertools.repeat(af)))
print('\x1b[2K {}/{} (total: {})'.format(sum(filter(None, res)),
len(video['items']),
Expand Down
11 changes: 5 additions & 6 deletions modules/messages.py
Expand Up @@ -148,7 +148,7 @@ def message_handler(dmp, msg, **kwargs):
r['attachments']['video_ids'].append('{oid}_{id}{access_key}'.format(
oid=at[tp]['owner_id'],
id=at[tp]['id'],
access_key='_' + (at[tp]['access_key'] if 'access_key' in at[tp] else '')
access_key=('_'+at[tp]['access_key'] if 'access_key' in at[tp] else '')
))
elif tp == 'audio':
r['messages'].append('[аудио: {artist} - {title}]'.format(
Expand Down Expand Up @@ -549,12 +549,11 @@ def sortById(msg):
zip(itertools.repeat(dmp.__class__),
videos['items'],
itertools.repeat(af)))
print('\x1b[2K {}/{} (total: {})'.format(sum(filter(None, res)),
len(videos['items']),
len(next(os.walk(af))[2])))
except MaybeEncodingError:
None

print('\x1b[2K {}/{} (total: {})'.format(sum(filter(None, res)),
len(videos['items']),
len(next(os.walk(af))[2])))
print('\x1b[2K ???/{} (total: {})'.format(len(videos['items']), len(next(os.walk(af))[2])))

if attachments['docs']:
af = os.path.join(at_folder, 'Документы')
Expand Down

0 comments on commit 575fdee

Please sign in to comment.