def Download(self): if self.m_url == "": return False if os.path.isfile(self.m_filename): return True partName = self.m_filename + ".part" with open(partName, 'ab') as f: headers = {} pos = f.tell() if pos: headers['Range'] = 'bytes={0}-'.format(pos) logger.Print("Getting headers ...") response = requests.get(self.m_url, headers=headers, stream=True, timeout=60) total_size = int(response.headers.get('content-length')) if total_size < 512: return False logger.Print("Getting content ...") with tqdm(total=total_size + pos, initial=pos, unit_scale=True, unit='B') as pbar: for data in response.iter_content(chunk_size=self.m_chunk): f.write(data) pbar.update(self.m_chunk) os.rename(partName, self.m_filename) return True
def countdown(t): while t: mins, secs = divmod(t, 60) timeformat = '{:02d}:{:02d}'.format(mins, secs) logger.Print(timeformat, end='\r') time.sleep(1) t -= 1 print('', end='\r')
def Grab(self, epNum): logger.Print("Getting URL ... ") pageResponse = self.__get_episode_page(epNum) if pageResponse: epUrl = self.__get_episode_download_url(pageResponse) epName = self.__get_episode_name(epNum, epUrl) return epUrl, epName return "", ""
def get_user_selection(self, animeSet): cnt = 0 for name in animeSet: if cnt > 4: break cnt += 1 logger.Print("{0}) {1}".format(cnt, name)) while True: try: inp = input("Select (s to skip): ") if inp == 's': return -1 sel = int(inp) if sel < 1 or sel > cnt: raise ValueError return sel except ValueError: logger.Print("Invalid selection.")
def Grab(self, epNum): logger.Print("Getting URL ... ") epUrl = "" pageResponse = self.__get_episode_page(epNum) if pageResponse: pageUrl = pageResponse.url epUrl = self.__get_episode_download_url(pageResponse) while epUrl == "": pageResponse = self.__get_episode_alt_page(pageUrl) if not pageResponse: break epUrl = self.__get_episode_download_url(pageResponse) epName = self.get_episode_name(epNum, epUrl) return epUrl, epName