def download_albums(self, numbers_albums, path): dl = downloads.Downloader(path) albums = [self._albums[i - 1] for i in numbers_albums] path.append(None) for item, album in enumerate(albums): photos = self._vk.photos.get(owner_id=self._id, album_id=album['aid']) title_album = others.scrape(album['title']) path[-1] = title_album dl.set_path(path) if dl.create_dir(): print('The album {} already exist'.format(title_album)) time.sleep(1) elif album['size'] == 0: print('The album {} is empty'.format(title_album)) time.sleep(1) else: for photo in others.ProgressBar( '({}/{}). {} is downloading'.format( item + 1, len(albums), title_album), photos): dl.download_photo(photo, str(photo['pid'])) print('The album {} is downloaded'.format(title_album))
def download_videos(self, videos, path): dl = downloads.Downloader(path) dl.create_dir() number = len(videos) for item, video in enumerate(videos): title = others.scrape(video['title']) print('({}/{}) {} is downloading...'.format( item + 1, number, title)) dl.download_video(video['player'], title) print('{} is downloaded'.format(title))
def show_info(self): fields = {} fields['Name'] = others.scrape(self._name) fields['Count members'] = str(self._group['members_count']) fields['Type'] = self._group['type'] fields['Description'] = self._group['description'] if len( self._group['description']) != 0 else 'No description' if self._group['counters'] is not None: for key, value in self._group['counters'].items(): fields[key.capitalize()] = str(value) for key, value in fields.items(): print(key + ': ' + value)
def __init__(self, ID): try: self._vk = Auth().get_session() self._user = self._vk.users.get( user_ids=ID, fields='sex,city,country,bdate,about,activities, \ books,education,games,contacts,country,interests,counters,tv,followers_count,movies,music' )[0] self._id = self._user['uid'] self._name = others.scrape(self._user['first_name'] + ' ' + self._user['last_name']) except VkAPIError: raise NoUserError
def download_videos(self): vk_videos = self.VideosCommunity(self._id) videos = vk_videos.get_videos() if len(videos) == 0: print('No videos available') return print(others.scrape(self._name)) print( 'Select the numbers of the available videos you want to download.\n0 - to download all. -1 - back' ) echo_com_videos = menu.show_dict(videos, 'title') vk_videos.download_videos([videos[i - 1] for i in echo_com_videos], [Community.get_name(self._id[1:]), 'Videos'])
def show_dict(d, key): while True: for i, value in enumerate(d): print('{}. {}'.format(i + 1, others.scrape(value[key]))) answer = input('>> ') if answer == '-1': return if answer == '0': return [i for i in range(1, len(d) + 1)] numbers = re.findall(r'\d+', answer) if len(numbers) == 0: print('There are no digits, try again') continue for i in range(len(numbers)): numbers[i] = int(numbers[i]) if numbers[i] < 1 or numbers[i] > len(d): print('There are digits out of range, try again') break else: return list(set(numbers))
def get_name(cls, ID): return others.scrape(cls(ID).get('name'))
def get_name(cls, ID): return others.scrape( cls(ID).get('first_name') + ' ' + cls(ID).get('last_name'))