def getCompleteList(self, opt, ui, progress, tmp_dir, hist_folder): m = ["Not Able To Open"] if opt == "Open": MainWindow = QtWidgets.QWidget() item, ok = QtWidgets.QInputDialog.getText( ui, "Input Dialog", "Enter Torrent Url or Magnet Link or local torrent file path", ) if ok and item: if item.startswith("http") or (os.path.isfile(item) and item.endswith(".torrent")): home = hist_folder name1 = os.path.basename(item).replace(".torrent", "") torrent_dest1 = os.path.join(tmp_dir, name1 + ".torrent") if not os.path.exists(torrent_dest1): if item.startswith("http"): ccurl(item + "#" + "-o" + "#" + torrent_dest1) else: shutil.copy(item, torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = os.path.join(home, name + ".torrent") shutil.copy(torrent_dest1, torrent_dest) m = [name] elif item.startswith("magnet:"): torrent_handle, stream_session, info = get_torrent_info_magnet( item, tmp_dir, ui, progress, tmp_dir) torrent_file = lt.create_torrent(info) home = hist_folder name = info.name() torrent_dest = os.path.join(home, name + ".torrent") with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() m = [name] m.append(1) return m
def getCompleteList(self, opt, ui): m = ['Not Able To Open'] if opt == 'Open': MainWindow = QtGui.QWidget() item, ok = QtGui.QInputDialog.getText( MainWindow, 'Input Dialog', 'Enter Torrent Url or Magnet Link or local torrent file path') if ok and item: if (item.startswith('http') or item.startswith('/')) and item.endswith('.torrent'): home = os.path.expanduser( '~') + '/.config/AnimeWatch/History/Torrent/' name1 = item.split('/')[-1].replace('.torrent', '') torrent_dest1 = '/tmp/AnimeWatch/' + name1 + '.torrent' if not os.path.exists(torrent_dest1): if item.startswith('http'): ccurl(item + '#' + '-o' + '#' + torrent_dest1) else: shutil.copy(item, torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = home + name + '.torrent' shutil.copy(torrent_dest1, torrent_dest) m = [name] elif item.startswith('magnet:'): torrent_handle, stream_session, info = get_torrent_info_magnet( item, '/tmp/AnimeWatch', ui) torrent_file = lt.create_torrent(info) home = os.path.expanduser( '~') + '/.config/AnimeWatch/History/Torrent/' name = info.name() torrent_dest = home + name + '.torrent' with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() m = [name] return m
def getCompleteList(self, opt, ui, progress, tmp_dir, hist_folder): m = ['Not Able To Open'] if opt == 'Open': MainWindow = QtWidgets.QWidget() item, ok = QtWidgets.QInputDialog.getText( MainWindow, 'Input Dialog', 'Enter Torrent Url or Magnet Link or local torrent file path') if ok and item: if (item.startswith('http') or (os.path.isfile(item) and item.endswith('.torrent'))): home = hist_folder name1 = os.path.basename(item).replace('.torrent', '') torrent_dest1 = os.path.join(tmp_dir, name1 + '.torrent') if not os.path.exists(torrent_dest1): if item.startswith('http'): ccurl(item + '#' + '-o' + '#' + torrent_dest1) else: shutil.copy(item, torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = os.path.join(home, name + '.torrent') shutil.copy(torrent_dest1, torrent_dest) m = [name] elif item.startswith('magnet:'): torrent_handle, stream_session, info = get_torrent_info_magnet( item, tmp_dir, ui, progress, tmp_dir) torrent_file = lt.create_torrent(info) home = hist_folder name = info.name() torrent_dest = os.path.join(home, name + '.torrent') with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() m = [name] m.append(1) return m
def getCompleteList(self,opt,ui): m = ['Not Able To Open'] if opt == 'Open': MainWindow = QtGui.QWidget() item, ok = QtGui.QInputDialog.getText(MainWindow, 'Input Dialog', 'Enter Torrent Url or Magnet Link or local torrent file path') if ok and item: if (item.startswith('http') or item.startswith('/')) and item.endswith('.torrent'): home = os.path.expanduser('~')+'/.config/AnimeWatch/History/Torrent/' name1 = item.split('/')[-1].replace('.torrent','') torrent_dest1 = '/tmp/AnimeWatch/'+name1+'.torrent' if not os.path.exists(torrent_dest1): if item.startswith('http'): ccurl(item+'#'+'-o'+'#'+torrent_dest1) else: shutil.copy(item,torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = home+name+'.torrent' shutil.copy(torrent_dest1,torrent_dest) m = [name] elif item.startswith('magnet:'): torrent_handle,stream_session,info = get_torrent_info_magnet(item,'/tmp/AnimeWatch',ui) torrent_file = lt.create_torrent(info) home = os.path.expanduser('~')+'/.config/AnimeWatch/History/Torrent/' name = info.name() torrent_dest = home+name+'.torrent' with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() m = [name] return m
def getCompleteList(self,opt,ui,progress,tmp_dir,hist_folder): m = ['Not Able To Open'] if opt == 'Open': MainWindow = QtWidgets.QWidget() item, ok = QtWidgets.QInputDialog.getText(MainWindow, 'Input Dialog', 'Enter Torrent Url or Magnet Link or local torrent file path') if ok and item: if (item.startswith('http') or item.startswith('/')) and item.endswith('.torrent'): home = hist_folder name1 = os.path.basename(item).replace('.torrent','') torrent_dest1 = os.path.join(tmp_dir,name1+'.torrent') if not os.path.exists(torrent_dest1): if item.startswith('http'): ccurl(item+'#'+'-o'+'#'+torrent_dest1) else: shutil.copy(item,torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = os.path.join(home,name+'.torrent') shutil.copy(torrent_dest1,torrent_dest) m = [name] elif item.startswith('magnet:'): torrent_handle,stream_session,info = get_torrent_info_magnet(item,tmp_dir,ui,progress,tmp_dir) torrent_file = lt.create_torrent(info) home = hist_folder name = info.name() torrent_dest = os.path.join(home,name+'.torrent') with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() m = [name] return m
def record_torrent(self, item, hist_folder): tmp_dir = TMPDIR name = '' if not os.path.exists(hist_folder): os.makedirs(hist_folder) if item.startswith('http') or os.path.isfile(item): home = hist_folder name1 = os.path.basename(item).replace('.torrent', '') torrent_dest1 = os.path.join(tmp_dir, name1+'.torrent') if not os.path.exists(torrent_dest1): if item.startswith('http'): ccurl(item+'#'+'-o'+'#'+torrent_dest1) else: shutil.copy(item, torrent_dest1) if os.path.exists(torrent_dest1): info = lt.torrent_info(torrent_dest1) name = info.name() torrent_dest = os.path.join(home, name+'.torrent') shutil.copy(torrent_dest1, torrent_dest) logger.info(name) elif item.startswith('magnet:'): torrent_handle, stream_session, info = get_torrent_info_magnet( item, tmp_dir, self, ui.progress, tmp_dir) torrent_file = lt.create_torrent(info) home = hist_folder name = info.name() torrent_dest = os.path.join(home, name+'.torrent') with open(torrent_dest, "wb") as f: f.write(lt.bencode(torrent_file.generate())) torrent_handle.pause() stream_session.pause() ui.stop_torrent_forcefully() if name: torrent_dest = os.path.join(home, name+'.torrent') info = lt.torrent_info(torrent_dest) file_arr = [] for f in info.files(): file_path = f.path file_path = os.path.basename(file_path) file_arr.append(file_path) if file_arr: hist_path = os.path.join(home, 'history.txt') if not os.path.isfile(hist_path): hist_dir, last_field = os.path.split(hist_path) if not os.path.exists(hist_dir): os.makedirs(hist_dir) f = open(hist_path, 'w').close() if os.path.isfile(hist_path): if (os.stat(hist_path).st_size == 0): write_files(hist_path, name, line_by_line=True) else: lines = open_files(hist_path, True) line_list = [] for i in lines: i = i.strip() line_list.append(i) if name not in line_list: write_files(hist_path, name, line_by_line=True) hist_site = os.path.join(hist_folder, name) if not os.path.exists(hist_site): try: os.makedirs(hist_site) hist_epn = os.path.join(hist_site, 'Ep.txt') write_files(hist_epn, file_arr, line_by_line=True) except Exception as e: print(e) return name