def handleLogin(self): self.hide() text_val = self.text_name.text() pass_val = self.text_pass.text() self.auth_info = text_val+':'+pass_val url = self.server_ip.text() if url: if not url.endswith('/'): url = url+'/' if not url.startswith('http'): send_notification('Enter full IP address starting with http/https properly') else: content = ccurl( '{0}get_all_category.htm#-c#{1}'.format(url, self.server.cookie_file), user_auth=self.auth_info, verify_peer=False ) print(content, '>>>>>') if ('Access Not Allowed, Authentication Failed' in content or 'You are not authorized to access the content' in content): self.server.login_success = False send_notification('Authentication Failed. Either Username or Password is incorrect') elif not content: send_notification('Curl failure: may be server is not running or misconfigured') else: self.server.passwd = self.auth_info self.server.url = url self.server.login_success = True send_notification('Login Success. Now click on Login Again') with open(self.server.server_list, 'w') as f: f.write(self.server.url) self.server.server_name = url else: send_notification('Server IP Address Needed')
def yt_sub_finished(): global name_epn, dest_dir_sub, tmp_dir_sub, TMPFILE name = name_epn dest_dir = dest_dir_sub dir_name, sub_name = os.path.split(TMPFILE) #print(dir_name, sub_name) m = os.listdir(dir_name) new_name = name.replace('/', '-') if new_name.startswith('.'): new_name = new_name[1:] sub_avail = False sub_ext = '' txt_notify = 'No Subtitle Found' for i in m: #j = os.path.join(dir_name, i) src_path = os.path.join(dir_name, i) if (i.startswith(sub_name) and i.endswith('.vtt') and os.stat(src_path).st_size != 0): k1 = i.rsplit('.', 2)[1] k2 = i.rsplit('.', 2)[2] ext = k1+'.'+k2 sub_ext = ext+', '+sub_ext dest_name = new_name + '.'+ ext #print(dest_name) dest_path = os.path.join(dest_dir, dest_name) #print(src_path, dest_path) if os.path.exists(src_path): shutil.copy(src_path, dest_path) os.remove(src_path) sub_avail = True if sub_avail: txt_notify = "External Subtitle "+ sub_ext+" Available\nPress Shift+J to load" if os.path.exists(TMPFILE): os.remove(TMPFILE) send_notification(txt_notify)
def get_correct_mirror(self,m,mirrorNo): length = len(m) j = 1 final = '' while (j <= length): mirrorNo = mirrorNo - 1 msg = "Total " + str(len(m)) + " Mirrors, Selecting Mirror "+str(mirrorNo + 1) #subprocess.Popen(["notify-send",msg]) send_notification(msg) src = m[mirrorNo] print(src) if 'vidcrazy' in src or 'uploadcrazy' in src: final = uploadcrazy(src) elif 'vidkai' in src: final = findurl(src) elif 'mp4star' in src or 'justmp4' in src: try: final = newMp4star(src) except Exception as e: print(e,'getting next link') print(final,'--final--') if final and final.startswith('http'): break j = j + 1 mirrorNo = j return final
def run(self): global httpd, ui_player print('starting server...') server_address = ('', self.port) server_start = False try: httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) if self.https_allow and self.cert_file: if os.path.exists(self.cert_file): httpd.socket = ssl.wrap_socket( httpd.socket, certfile=self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1_2) server_start = True except Exception as err: print(err, '----->error') txt = 'Your local IP changed..or port is blocked\n..Trying to find new IP' send_notification(txt) self.ip = get_lan_ip() txt = 'Your New Address is ' + self.ip + '\n Please restart the player' send_notification(txt) if server_start: print('running server...at..' + self.ip + ':' + str(self.port)) httpd.serve_forever() else: print('server..not..started..')
def handleSsl(self): if self.pass_phrase.text() == self.repeat_phrase.text(): self.hide() pass_word = self.pass_phrase.text() if len(pass_word) >= 8: my_ip = str(self.ui.local_ip_stream) server_key = os.path.join(self.tmpdir, 'server.key') server_csr = os.path.join(self.tmpdir, 'server.csr') server_crt = os.path.join(self.tmpdir, 'server.crt') cn = '/CN=' + my_ip if self.ui.my_public_ip and self.ui.access_from_outside_network: my_ip = str(self.ui.my_public_ip) try: subprocess.call([ 'openssl', 'genrsa', '-des3', '-passout', 'pass:'******'-out', server_key, '2048' ]) print('key--generated') subprocess.call([ 'openssl', 'rsa', '-in', server_key, '-out', server_key, '-passin', 'pass:'******'next') subprocess.call([ 'openssl', 'req', '-sha256', '-new', '-key', server_key, '-out', server_csr, '-subj', cn ]) print('req') subprocess.call([ 'openssl', 'x509', '-req', '-sha256', '-days', '365', '-in', server_csr, '-signkey', server_key, '-out', server_crt ]) print('final') f = open(self.ssl_cert, 'w') content1 = open(server_crt).read() content2 = open(server_key).read() f.write(content1 + '\n' + content2) f.close() print('ssl generated') send_notification( "Certificate Successfully Generated.\nNow Start Media Server Again." ) except Exception as e: print(e) send_notification( "Error in Generating SSL Certificate. Either 'openssl' or 'openssl.cnf' is not available in system path! Create 'cert.pem' manually, and keep it in Kawaii-Player config directory." ) else: self.pass_phrase.clear() self.repeat_phrase.clear() self.pass_phrase.setPlaceholderText( 'Length of password less than 8 characters, Make it atleast 8' ) self.show() else: self.pass_phrase.clear() self.repeat_phrase.clear() self.pass_phrase.setPlaceholderText('Wrong Values Try again') self.show()
def get_correct_mirror(self, m, mirrorNo): length = len(m) j = 1 final = '' while (j <= length): mirrorNo = mirrorNo - 1 msg = "Total " + str( len(m)) + " Mirrors, Selecting Mirror " + str(mirrorNo + 1) #subprocess.Popen(["notify-send",msg]) send_notification(msg) src = m[mirrorNo] print(src) if 'vidcrazy' in src or 'uploadcrazy' in src: final = uploadcrazy(src) elif 'vidkai' in src: final = findurl(src) elif 'mp4star' in src or 'justmp4' in src: try: final = newMp4star(src) except Exception as e: print(e, 'getting next link') print(final, '--final--') if final and final.startswith('http'): break j = j + 1 mirrorNo = j return final
def run(self): global httpd print('starting server...') server_address = (self.ip, self.port) server_start = False try: httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) if self.https_allow and self.cert_file: if os.path.exists(self.cert_file): httpd.socket = ssl.wrap_socket( httpd.socket, certfile=self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1_2) server_start = True except: txt = 'Your local IP changed..or port is blocked\n..Trying to find new IP' #subprocess.Popen(['notify-send', txt]) send_notification(txt) self.ip = get_ip() txt = 'Your New Address is ' + self.ip + '\n Please restart the player' #subprocess.Popen(['notify-send', txt]) send_notification(txt) change_config_file(self.ip, self.port) server_address = (self.ip, self.port) self.ui.local_ip = self.ip #httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) if server_start: print('running server...at..' + self.ip + ':' + str(self.port)) httpd.serve_forever() else: print('server..not..started..')
def handle_login(self, server_name=None): if os.path.isfile(self.server_list) and not server_name: with open(self.server_list, 'r') as f: self.server_name = f.read() elif server_name: self.server_name = server_name if not self.url: self.login_widget = LoginWidget(server=self) self.login_widget.show() #self.login_widget.setWindowModality(QtCore.Qt.WindowModal) else: content = ccurl( '{0}get_all_category.htm#-c#{1}'.format(self.url, self.cookie_file), user_auth=self.passwd, verify_peer=False ) print(content, '>>>>>') if ('Access Not Allowed, Authentication Failed' in content or 'You are not authorized to access the content' in content): self.login_success = False self.login_widget = LoginWidget(server=self) self.login_widget.show() elif not content: send_notification('Curl failure: may be server is not running or misconfigured') else: self.login_success = True
def getFinalUrl(self,name,epn,mirror,quality): if '--' in name and 'id=' in name: name = name.split('--')[0] url = 'http://kissanime.ru/Anime/' + name + '/' + epn print(url) sd = '' hd = '' sd480 = '' full_hd = '' """ content = self.ccurlN(url) soup = BeautifulSoup(content,'lxml') m = soup.findAll('select',{'id':'slcQualix'}) print(m) if not m: content = self.ccurlN(url+'&s=beta') soup = BeautifulSoup(content,'lxml') m = soup.findAll('select',{'id':'slcQualix'}) print(m) arr = [] """ lnk_file = os.path.join(self.tmp_dir,'lnk.txt') if os.path.exists(lnk_file): os.remove(lnk_file) #if quality == 'best': # quality = 'best' #if not os.path.isfile('/tmp/AnimeWatch/kcookieD.txt'): if mirror == 2: url = url+'&s=beta' cloudfare(url,quality,self.cookie_file) if os.path.exists(lnk_file): link = open(lnk_file).readlines() if len(link) == 1: final = link[0] elif len(link) == 2: final = [] final.append(link[0].strip()) final.append(link[1].strip()) final.append('referer sent') print(link) print(final) else: final = '' msg = 'No Link Available. Try Clearing Cache or select Alternate Mirror by pressing keys 1 or 2' send_notification(msg) if final and final is not list and mirror == 2: new_final = [] new_final.append(final) new_final.append(url) new_final.append('referer sent') return new_final else: return final """
def getFinalUrl(self, name, epn, mirror, quality): if '--' in name and 'id=' in name: name = name.split('--')[0] url = 'http://kissanime.ru/Anime/' + name + '/' + epn print(url) sd = '' hd = '' sd480 = '' full_hd = '' """ content = self.ccurlN(url) soup = BeautifulSoup(content,'lxml') m = soup.findAll('select',{'id':'slcQualix'}) print(m) if not m: content = self.ccurlN(url+'&s=beta') soup = BeautifulSoup(content,'lxml') m = soup.findAll('select',{'id':'slcQualix'}) print(m) arr = [] """ lnk_file = os.path.join(self.tmp_dir, 'lnk.txt') if os.path.exists(lnk_file): os.remove(lnk_file) #if quality == 'best': # quality = 'best' #if not os.path.isfile('/tmp/AnimeWatch/kcookieD.txt'): if mirror == 2: url = url + '&s=beta' cloudfare(url, quality, self.cookie_file) if os.path.exists(lnk_file): link = open(lnk_file).readlines() if len(link) == 1: final = link[0] elif len(link) == 2: final = [] final.append(link[0].strip()) final.append(link[1].strip()) final.append('referer sent') print(link) print(final) else: final = '' msg = 'No Link Available. Try Clearing Cache or select Alternate Mirror by pressing keys 1 or 2' send_notification(msg) if final and final is not list and mirror == 2: new_final = [] new_final.append(final) new_final.append(url) new_final.append('referer sent') return new_final else: return final """
def handleLogin(self): self.hide() text_val = self.text_name.text() pass_val = self.text_pass.text() self.auth_info = text_val + ":" + pass_val url = self.server_ip.text() if url: if not url.endswith("/"): url = url + "/" if not url.startswith("http"): send_notification( "Enter full IP address starting with http/https properly") else: content = ccurl( "{0}get_all_category.htm#-c#{1}".format( url, self.server.cookie_file), user_auth=self.auth_info, verify_peer=False, ) print(content, ">>>>>") if ("Access Not Allowed, Authentication Failed" in content or "You are not authorized to access the content" in content): self.server.login_success = False send_notification( "Authentication Failed. Either Username or Password is incorrect" ) elif not content: send_notification( "Curl failure: may be server is not running or misconfigured" ) else: self.server.passwd = self.auth_info self.server.url = url self.server.login_success = True send_notification( "Login Success. Now click on Login Again") with open(self.server.server_list, "w") as f: f.write(self.server.url) self.server.server_name = url else: send_notification("Server IP Address Needed")
def alter_table_and_update(self, version): if version <= (2, 0, 0, 0) and version > (0, 0, 0, 0): msg = "Video Database Updating. Please Wait!" send_notification(msg) conn = sqlite3.connect( os.path.join(self.home, "VideoDB", "Video.db")) cur = conn.cursor() try: cur.execute("ALTER TABLE Video ADD COLUMN Category integer") conn.commit() conn.close() conn = sqlite3.connect( os.path.join(self.home, "VideoDB", "Video.db")) cur = conn.cursor() cur.execute("SELECT Path FROM Video") rows = cur.fetchall() for i in rows: self.logger.info( "Databse Schema Changed updating Entries::{0}".format( i)) if i: path = i[0].lower() di, na = os.path.split(i[0]) if "movie" in di.lower(): category = self.ui.category_dict["movies"] elif "anime" in di.lower(): category = self.ui.category_dict["anime"] elif "cartoon" in di.lower(): category = self.ui.category_dict["cartoons"] elif "tv shows" in di.lower( ) or "tv-shows" in di.lower(): category = self.ui.category_dict["tv shows"] else: category = self.ui.category_dict["others"] qr = "Update Video Set Category=? Where Path=?" cur.execute(qr, (category, i[0])) except Exception as err: print(err, "Column Already Exists") conn.commit() conn.close()
def alter_table_and_update(self, version): if version <= (2, 0, 0, 0) and version > (0, 0, 0, 0): msg = 'Video Database Updating. Please Wait!' send_notification(msg) conn = sqlite3.connect( os.path.join(self.home, 'VideoDB', 'Video.db')) cur = conn.cursor() try: cur.execute('ALTER TABLE Video ADD COLUMN Category integer') conn.commit() conn.close() conn = sqlite3.connect( os.path.join(self.home, 'VideoDB', 'Video.db')) cur = conn.cursor() cur.execute('SELECT Path FROM Video') rows = cur.fetchall() for i in rows: self.logger.info( 'Databse Schema Changed updating Entries::{0}'.format( i)) if i: path = i[0].lower() di, na = os.path.split(i[0]) if 'movie' in di.lower(): category = self.ui.category_dict['movies'] elif 'anime' in di.lower(): category = self.ui.category_dict['anime'] elif 'cartoon' in di.lower(): category = self.ui.category_dict['cartoons'] elif 'tv shows' in di.lower( ) or 'tv-shows' in di.lower(): category = self.ui.category_dict['tv shows'] else: category = self.ui.category_dict['others'] qr = 'Update Video Set Category=? Where Path=?' cur.execute(qr, (category, i[0])) except Exception as err: print(err, 'Column Already Exists') conn.commit() conn.close()
def run(self): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) port = str(ui.local_port_stream) print(ui.local_ip_stream, '-----ip--', ui.local_port_stream) msg = 'this is kawaii-player At: port={} https={} msg={}'.format( port, ui.https_media_server, ui.broadcast_message) msg = bytes(msg, 'utf-8') if ui.https_media_server: https_val = 'https' else: https_val = 'http' subnet_mask = ui.local_ip_stream.rsplit('.', 1)[0] + '.255' notify_msg = '{0}://{1}:{2} started broadcasting. Now Clients can Discover it'.format( https_val, ui.local_ip_stream, ui.local_port_stream) send_notification(notify_msg) print(subnet_mask) while ui.broadcast_server: s.sendto(msg, (subnet_mask, 12345)) time.sleep(1) send_notification('Broadcasting Stopped')
def get_correct_mirror(self,m,mirrorNo): length = len(m) j = 1 final = '' while (j <= length): mirrorNo = mirrorNo - 1 msg = "Total " + str(len(m)) + " Mirrors, Selecting Mirror "+str(mirrorNo + 1) #subprocess.Popen(["notify-send",msg]) send_notification(msg) if mirrorNo < len(m): src = m[mirrorNo] else: src = m[0] print(src) if 'vidcrazy' in src or 'uploadcrazy' in src: final = uploadcrazy(src) elif 'vidkai' in src: final = findurl(src) elif 'mp4star' in src or 'justmp4' in src: try: content = ccurlNew(src) content = content.replace('\\\\','') print('????????????????????????????') print(content) print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') final = mp4starUrl(content,'mp4star') except Exception as e: print(e,'getting next link') elif 'mp4buddy' in src or 'mp4upload' in src: final = findurl(src) print(final,'--final--') if final and final.startswith('http'): break j = j + 1 mirrorNo = j return final
def run(self): global httpd print('starting server...') server_address = (self.ip,self.port) try: httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) if self.https_allow and self.cert_file: if os.path.exists(self.cert_file): httpd.socket = ssl.wrap_socket( httpd.socket,certfile=self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1_1) except: txt = 'Your local IP changed..or port is blocked\n..Trying to find new IP' #subprocess.Popen(['notify-send',txt]) send_notification(txt) self.ip = get_ip() txt = 'Your New Address is '+self.ip + '\n Please restart the player' #subprocess.Popen(['notify-send',txt]) send_notification(txt) change_config_file(self.ip,self.port) server_address = (self.ip,self.port) httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) print('running server...at..'+self.ip+':'+str(self.port)) httpd.serve_forever()
def run(self): print('hello world---server discovery') s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(('', 12345)) s.settimeout(60) port_val = '' https_val = '' msg_val = '' send_notification('Started Process of Discovering') self.clear_list.emit('start') while ui.discover_server: try: m = s.recvfrom(1024) val = str(m[0], 'utf-8') server = str(m[1][0]) if val.lower().startswith('this is kawaii-player at:'): val_string = (val.split(':')[1]).strip() val_arr = val_string.split(' ') for i in val_arr: if i.startswith('port='): port_val = i.split('=')[1] elif i.startswith('https='): https_status = i.split('=')[1] if https_status == 'True': https_val = 'https' else: https_val = 'http' msg_val = re.search('msg=[^"]*', val_string).group() msg_val = msg_val.replace('msg=', '', 1) server_val = '{0}://{1}:{2}/\t{3}'.format( https_val, server, port_val, msg_val) if server_val not in ui.broadcast_server_list: ui.broadcast_server_list.append(server_val) self.discover_signal.emit(server_val) time.sleep(1) except Exception as e: print('timeout', e) break if not ui.broadcast_server_list: send_notification('No Server Found') self.clear_list.emit('no server') else: send_notification('Stopped Discovering: found {} servers'.format( len(ui.broadcast_server_list)))
def broadcast_server_signal(val): send_notification(val)
def yt_sub_started(): print('Getting Sub') txt_notify = "Trying To Get External Subtitles Please Wait!" send_notification(txt_notify)
You should have received a copy of the GNU General Public License along with kawaii-player. If not, see <http://www.gnu.org/licenses/>. """ import os import shutil from PyQt5 import QtWidgets from player_functions import send_notification, ccurl try: import libtorrent as lt from stream import ThreadServer, TorrentThread, get_torrent_info, get_torrent_info_magnet except Exception as err: print(err, '--29--') notify_txt = 'python3 bindings for libtorrent are broken\nTorrent Streaming feature will be disabled' send_notification(notify_txt) class Torrent(): def __init__(self, tmp): self.tmp_dir = tmp def getOptions(self): criteria = ['Open', 'History', 'LocalStreaming', 'newversion'] return criteria def search(self, name): m = ['Not Available'] return m def getCompleteList(self, opt, ui, progress, tmp_dir, hist_folder):
def download(self, url, option, copy_summary=None): if option.lower() == "play with kawaii-player": final_url = "" self.ui.epn_name_in_list = self.title_page self.ui.logger.info(self.ui.epn_name_in_list) if self.ui.mpvplayer_val.processId() > 0: self.ui.mpvplayer_val.kill() self.ui.mpvplayer_started = False if "youtube.com" in url or "ytimg.com" in url: pass else: url = "ytdl:" + url self.ui.get_final_link( url, self.ui.quality_val, self.ui.ytdl_path, self.ui.logger, self.ui.epn_name_in_list, self.hdr, ) elif option.lower() in ["cast this item", "cast queue"]: if option.lower() == "cast queue": self.ui.list2.process_browser_based_url( copy_summary, url, "queue") else: self.ui.list2.process_browser_based_url( copy_summary, url, "single") elif option.lower() == "add as local playlist": self.get_playlist = True if self.playlist_dict: self.ui.logger.info(self.get_playlist, "=get_playlist") self.add_playlist(self.playlist_name) elif option.lower() == "download": if self.ui.quality_val == "sd480p": txt = "Video can't be saved in 480p, Saving in either HD or SD" send_notification(txt) quality = "hd" else: quality = self.ui.quality_val finalUrl = self.ui.yt.get_yt_url(url, quality, self.ui.ytdl_path, self.ui.logger, mode="offline") finalUrl = finalUrl.replace("\n", "") title = self.title_page + ".mp4" title = title.replace('"', "") title = title.replace("/", "-") if os.path.exists(self.ui.default_download_location): title = os.path.join(self.ui.default_download_location, title) else: title = os.path.join(self.ui.tmp_download_folder, title) command = wget_string(finalUrl, title, self.ui.get_fetch_library) self.ui.logger.debug(command) self.ui.infoWget(command, 0) elif option.lower() == "queue item": file_path = os.path.join(self.home, "Playlists", "Queue") if not os.path.exists(file_path): f = open(file_path, "w") f.close() if not self.ui.queue_url_list: self.ui.list6.clear() title = self.title_page.replace("/", "-") if title.startswith("."): title = title[1:] r = title + " " + url + " " + "NONE" self.ui.queue_url_list.append(r) self.ui.list6.addItem(title) write_files(file_path, r, line_by_line=True) elif option.lower() == "season episode link": if self.site != "Music" and self.site != "PlayLists": my_copy = self.ui.epn_arr_list.copy() r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) video_dir = None if self.site.lower() == "video": video_dir = self.ui.original_path_name[r].split("\t")[-1] elif self.site.lower() in ["playlists", "none", "music"]: pass else: video_dir = self.ui.original_path_name[r] self.ui.posterfound_new( name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=False, get_sum=True, video_dir=video_dir, ) elif (option.lower() == "artist link" or option.lower() == "series link" or option.lower() == "series/movie link"): r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new( name=nm, site=self.site, url=url, direct_url=True, copy_summary=True, copy_poster=True, copy_fanart=True, ) elif option.lower() == "copy summary": self.ui.copySummary(copy_sum=copy_summary) else: if not url: url = self.media_url self.ui.logger.debug("{}--{}--media-url--".format( url, self.media_url)) if url: t_content = ccurl(url, curl_opt="-I") if "image/jpeg" in t_content and not "Location:" in t_content: pass elif "image/jpeg" in t_content and "Location:" in t_content: m = re.findall("Location: [^\n]*", t_content) found = re.sub("Location: |\r", "", m[0]) url = found elif self.media_url: url = self.media_url else: return 0 if option.lower() == "download as fanart": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) print(option, "----") self.ui.posterfound_new( name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=True, ) elif option.lower() == "download as cover": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new( name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=True, copy_fanart=False, )
def download(self, url, option, copy_summary=None): if option.lower() == 'play with kawaii-player': final_url = '' self.ui.epn_name_in_list = self.title_page self.ui.logger.info(self.ui.epn_name_in_list) if self.ui.mpvplayer_val.processId() > 0: self.ui.mpvplayer_val.kill() final_url = get_yt_url(url, self.ui.quality_val, self.ui.ytdl_path, self.ui.logger) if final_url: self.ui.watchDirectly(final_url, self.ui.epn_name_in_list, 'no') self.ui.tab_5.show() self.ui.frame1.show() self.ui.tab_2.setMaximumWidth(400) elif option.lower() == 'add as local playlist': self.get_playlist = True if self.playlist_dict: self.ui.logger.info(self.get_playlist, '=get_playlist') self.add_playlist(self.playlist_name) elif option.lower() == 'download': if self.ui.quality_val == 'sd480p': txt = "Video can't be saved in 480p, Saving in either HD or SD" send_notification(txt) quality = 'hd' else: quality = self.ui.quality_val finalUrl = get_yt_url(url, quality, self.ui.ytdl_path, self.ui.logger) finalUrl = finalUrl.replace('\n', '') title = self.title_page + '.mp4' title = title.replace('"', '') title = title.replace('/', '-') if os.path.exists(self.ui.default_download_location): title = os.path.join(self.ui.default_download_location, title) else: title = os.path.join(self.ui.tmp_download_folder, title) command = wget_string(finalUrl, title, self.ui.get_fetch_library) print(command) self.ui.infoWget(command, 0) elif option.lower() == 'get subtitle (if available)': self.ui.epn_name_in_list = self.title_page self.ui.logger.info(self.ui.epn_name_in_list) get_yt_sub(url, self.ui.epn_name_in_list, self.yt_sub_folder, self.ui.tmp_download_folder, self.ui.ytdl_path, self.ui.logger) elif option.lower() == 'queue item': file_path = os.path.join(self.home, 'Playlists', 'Queue') if not os.path.exists(file_path): f = open(file_path, 'w') f.close() if not self.ui.queue_url_list: self.ui.list6.clear() title = self.title_page.replace('/', '-') if title.startswith('.'): title = title[1:] r = title + ' ' + url + ' ' + 'NONE' self.ui.queue_url_list.append(r) self.ui.list6.addItem(title) print(self.ui.queue_url_list) write_files(file_path, r, line_by_line=True) elif option.lower() == 'season episode link': if self.site != "Music" and self.site != "PlayLists": self.ui.getTvdbEpnInfo(url) elif option.lower() == 'artist link' or option.lower( ) == 'series link': r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=True, copy_poster=True, copy_fanart=True) elif option.lower() == 'copy summary': self.ui.copySummary(copy_sum=copy_summary) else: if not url: url = self.media_url print(url, self.media_url, '--media--url--') if url: t_content = ccurl(url + '#' + '-I') if 'image/jpeg' in t_content and not 'Location:' in t_content: pass elif 'image/jpeg' in t_content and 'Location:' in t_content: m = re.findall('Location: [^\n]*', t_content) found = re.sub('Location: |\r', '', m[0]) url = found elif self.media_url: url = self.media_url else: return 0 if option.lower() == "download as fanart": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) print(option, '----') self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=True) elif option.lower() == "download as cover": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=True, copy_fanart=False)
def get_yt_url(self, url, quality, ytdl_path, logger, mode=None, reqfrom=None): final_url = "" url = url.replace('"', "") m = [] home_dir = self.ui.home_folder ytdl_stamp = os.path.join(home_dir, "tmp", "ytdl_update_stamp.txt") yt_sub_folder = os.path.join(home_dir, "External-Subtitle") if ytdl_path: if ytdl_path == "default": if os.name == "nt": youtube_dl = "youtube-dl.exe" else: youtube_dl = "youtube-dl" else: if os.path.exists(ytdl_path): youtube_dl = ytdl_path else: if ytdl_path.endswith("ytdl") or ytdl_path.endswith("ytdl.exe"): send_notification("Please Wait! Getting Latest youtube-dl") youtube_dl = ytdl_path if ytdl_path.endswith("ytdl"): ccurl( "https://yt-dl.org/downloads/latest/youtube-dl" + "#-o#" + ytdl_path ) subprocess.Popen(["chmod", "+x", ytdl_path]) else: ccurl( "https://yt-dl.org/latest/youtube-dl.exe" + "#-o#" + ytdl_path ) update_time = str(int(time.time())) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, "w") f.write(update_time) f.close() else: send_notification("youtube-dl path does not exists!") youtube_dl = "youtube-dl" else: youtube_dl = "youtube-dl" logger.info(youtube_dl) ytdl_extra = False if "/watch?" in url and "youtube.com" in url: a = url.split("?")[-1] b = a.split("&") if b: for i in b: j = i.split("=") k = (j[0], j[1]) m.append(k) else: j = a.split("=") k = (j[0], j[1]) m.append(k) d = dict(m) logger.info("----dict--arguments---generated---{0}".format(d)) try: url = "https://www.youtube.com/watch?v=" + d["v"] except: pass elif url.startswith("ytdl:"): url = url.replace("ytdl:", "", 1) ytdl_extra = True else: ytdl_extra = True try: if mode == "TITLE": if os.name == "posix": final_url = subprocess.check_output([youtube_dl, "-e", url]) else: final_url = subprocess.check_output( [youtube_dl, "-e", url], shell=True ) final_url = str(final_url, "utf-8") final_url = final_url.replace(" - YouTube", "", 1) else: if quality == "sd": res = 360 elif quality == "hd": res = 720 elif quality == "sd480p": res = 480 else: res = 4000 if ( quality == "best" and ytdl_path == "default" and (reqfrom is None or reqfrom == "desktop") and not self.ui.gapless_network_stream ): if ytdl_extra: final_url = "ytdl:" + url else: final_url = url time.sleep(1) else: final_url = self.get_final_for_resolution( url, youtube_dl, logger, ytdl_extra, resolution=res, mode=mode, sub_folder=yt_sub_folder, ) if not final_url: final_url = url except Exception as e: logger.error("--error in processing youtube url--{0}".format(e)) txt = "Please Update youtube-dl" send_notification(txt) final_url = "" updated_already = False if ytdl_path.endswith("ytdl") or ytdl_path.endswith("ytdl.exe"): if os.path.exists(ytdl_stamp): content = open(ytdl_stamp, "r").read() try: old_time = int(content) except Exception as e: logger.info(e) old_time = int(time.time()) - 3600 cur_time = int(time.time()) if cur_time - old_time < 24 * 3600: updated_already = True if not updated_already: send_notification("Please Wait! Getting Latest youtube-dl") if ytdl_path.endswith("ytdl"): ccurl( "https://yt-dl.org/downloads/latest/youtube-dl" + "#-o#" + ytdl_path ) subprocess.Popen(["chmod", "+x", ytdl_path]) else: ccurl( "https://yt-dl.org/latest/youtube-dl.exe" + "#-o#" + ytdl_path ) send_notification( "Updated youtube-dl, Now Try Playing Video Again!" ) update_time = str(int(time.time())) if os.path.exists(ytdl_stamp): os.remove(ytdl_stamp) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, "w") f.write(update_time) f.close() else: send_notification("youtube-dl is already newest version") logger.debug("yt-link:>>{0}".format(final_url)) if mode == "TITLE" and not final_url: final_url = url.split("/")[-1] elif not final_url: final_url = url return final_url
def download(self, url,option): if option.lower() == 'play with animewatch': final_url = '' self.ui.epn_name_in_list = self.title_page print(self.ui.epn_name_in_list) if self.ui.mpvplayer_val.processId() > 0: self.ui.mpvplayer_val.kill() final_url = get_yt_url(url.toString(),self.ui.quality_val,self.ui.ytdl_path,self.ui.logger) if final_url: self.ui.watchDirectly(final_url,self.ui.epn_name_in_list,'no') self.ui.tab_5.show() self.ui.frame1.show() self.ui.tab_2.setMaximumWidth(self.ui.width_allowed+50) elif option.lower() == 'add as local playlist': self.get_playlist = True if self.playlist_dict: print(self.get_playlist,'=get_playlist') self.add_playlist(self.playlist_name) elif option.lower() == 'download': if self.ui.quality_val == 'sd480p': txt = "Video can't be saved in 480p, Saving in either HD or SD" send_notification(txt) quality = 'hd' else: quality = self.ui.quality_val finalUrl = get_yt_url(url.toString(),quality,self.ui.ytdl_path,self.ui.logger) finalUrl = finalUrl.replace('\n','') title = self.title_page+'.mp4' title = title.replace('"','') title = title.replace('/','-') if os.path.exists(self.ui.default_download_location): title = os.path.join(self.ui.default_download_location,title) else: title = os.path.join(self.ui.tmp_download_folder,title) command = wget_string(finalUrl,title,self.ui.get_fetch_library) print (command) self.ui.infoWget(command,0) elif option.lower() == 'get subtitle (if available)': self.ui.epn_name_in_list = self.title_page print(self.ui.epn_name_in_list) get_yt_sub(url.toString(),self.ui.epn_name_in_list, self.yt_sub_folder,self.ui.tmp_download_folder, self.ui.ytdl_path,self.ui.logger) elif option.lower() == 'queue item': file_path = os.path.join(self.home,'Playlists','Queue') if not os.path.exists(file_path): f = open(file_path,'w') f.close() if not self.ui.queue_url_list: self.ui.list6.clear() title = self.title_page.replace('/','-') if title.startswith('.'): title = title[1:] r = title + ' '+url.toString()+' '+'NONE' self.ui.queue_url_list.append(r) self.ui.list6.addItem(title) print (self.ui.queue_url_list) write_files(file_path,r,line_by_line=True) elif option.lower() == 'season episode link': if self.site != "Music" and self.site != "PlayLists": self.ui.getTvdbEpnInfo(url.toString()) elif option.lower() == 'artist link' or option.lower() == 'series link': url = url.toString() r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new( name=nm,site=self.site,url=url,direct_url=True, copy_summary=True,copy_poster=True,copy_fanart=True) else: url = url.toString() if url: t_content = ccurl(url+'#'+'-I') if 'image/jpeg' in t_content and not 'Location:' in t_content: pass elif 'image/jpeg' in t_content and 'Location:' in t_content: m = re.findall('Location: [^\n]*',t_content) found = re.sub('Location: |\r','',m[0]) url = found elif not self.img_url.isEmpty(): url = self.img_url.toString() else: return 0 if option.lower() == "download as fanart": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) print(option,'----') self.ui.posterfound_new( name=nm,site=self.site,url=url,direct_url=True, copy_summary=False,copy_poster=False,copy_fanart=True) elif option.lower() == "download as cover": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new( name=nm,site=self.site,url=url,direct_url=True, copy_summary=False,copy_poster=True,copy_fanart=False)
import pycurl from io import StringIO,BytesIO import re import random import subprocess from subprocess import check_output from bs4 import BeautifulSoup import os.path from subprocess import check_output from player_functions import send_notification,ccurl try: import libtorrent as lt from stream import ThreadServer,TorrentThread,get_torrent_info,get_torrent_info_magnet except: notify_txt = 'python3 bindings for libtorrent are broken\nTorrent Streaming feature will be disabled' send_notification(notify_txt) from PyQt5 import QtWidgets import shutil class Torrent(): def __init__(self,tmp): self.hdr = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:45.0) Gecko/20100101 Firefox/45.0' self.tmp_dir = tmp def getOptions(self): criteria = ['Open','History','LocalStreaming'] return criteria def search(self,name): m = ['Not Available']
import os import re import imp import shutil import hashlib from player_functions import open_files, write_files, ccurl, send_notification try: import libtorrent as lt from stream import get_torrent_info_magnet except Exception as err: print(err, '--11--') notify_txt = 'python3 bindings for libtorrent are broken\ Torrent Streaming feature will be disabled' send_notification(notify_txt, code=0) class ServerLib: def __init__(self, ui_widget=None, hm=None, base=None, tmp=None, logr=None): global ui, home, TMPDIR, BASEDIR, logger ui = ui_widget home = hm BASEDIR = base TMPDIR = tmp logger = logr def get_file_name_from_bookmark(self, site, site_option, name, row, epnArrList): file_name_mkv = '' file_name_mp4 = ''
def get_yt_url(self, url, quality, ytdl_path, logger, mode=None, reqfrom=None): final_url = '' url = url.replace('"', '') m = [] home_dir = self.ui.home_folder ytdl_stamp = os.path.join(home_dir, 'tmp', 'ytdl_update_stamp.txt') yt_sub_folder = os.path.join(home_dir, 'External-Subtitle') if ytdl_path: if ytdl_path == 'default': youtube_dl = 'youtube-dl' else: if os.path.exists(ytdl_path): youtube_dl = ytdl_path else: if ytdl_path.endswith('ytdl') or ytdl_path.endswith('ytdl.exe'): send_notification('Please Wait! Getting Latest youtube-dl') youtube_dl = ytdl_path if ytdl_path.endswith('ytdl'): ccurl('https://yt-dl.org/downloads/latest/youtube-dl'+'#-o#'+ytdl_path) subprocess.Popen(['chmod', '+x', ytdl_path]) else: ccurl('https://yt-dl.org/latest/youtube-dl.exe'+'#-o#'+ytdl_path) update_time = str(int(time.time())) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, 'w') f.write(update_time) f.close() else: send_notification('youtube-dl path does not exists!') youtube_dl = 'youtube-dl' else: youtube_dl = 'youtube-dl' logger.info(youtube_dl) ytdl_extra = False if '/watch?' in url and 'youtube.com' in url: a = url.split('?')[-1] b = a.split('&') if b: for i in b: j = i.split('=') k = (j[0], j[1]) m.append(k) else: j = a.split('=') k = (j[0], j[1]) m.append(k) d = dict(m) logger.info('----dict--arguments---generated---{0}'.format(d)) try: url = 'https://www.youtube.com/watch?v='+d['v'] except: pass elif url.startswith('ytdl:'): url = url.replace('ytdl:', '', 1) ytdl_extra = True else: ytdl_extra = True try: if mode == 'TITLE': if os.name == 'posix': final_url = subprocess.check_output([youtube_dl, '-e', url]) else: final_url = subprocess.check_output([youtube_dl, '-e', url], shell=True) final_url = str(final_url, 'utf-8') final_url = final_url.replace(' - YouTube', '', 1) else: if quality == 'sd': res = 360 elif quality == 'hd': res = 720 elif quality == 'sd480p': res = 480 else: res = 4000 if (quality == 'best' and ytdl_path == 'default' and (reqfrom is None or reqfrom == 'desktop')): if ytdl_extra: final_url = 'ytdl:' + url else: final_url = url time.sleep(1) else: final_url = self.get_final_for_resolution( url, youtube_dl, logger, ytdl_extra, resolution=res, mode=mode, sub_folder=yt_sub_folder ) if not final_url: final_url = url except Exception as e: logger.error('--error in processing youtube url--{0}'.format(e)) txt = 'Please Update youtube-dl' send_notification(txt) final_url = '' updated_already = False if ytdl_path.endswith('ytdl') or ytdl_path.endswith('ytdl.exe'): if os.path.exists(ytdl_stamp): content = open(ytdl_stamp, 'r').read() try: old_time = int(content) except Exception as e: logger.info(e) old_time = int(time.time()) - 3600 cur_time = int(time.time()) if (cur_time - old_time < 24*3600): updated_already = True if not updated_already: send_notification('Please Wait! Getting Latest youtube-dl') if ytdl_path.endswith('ytdl'): ccurl('https://yt-dl.org/downloads/latest/youtube-dl'+'#-o#'+ytdl_path) subprocess.Popen(['chmod', '+x', ytdl_path]) else: ccurl('https://yt-dl.org/latest/youtube-dl.exe'+'#-o#'+ytdl_path) send_notification('Updated youtube-dl, Now Try Playing Video Again!') update_time = str(int(time.time())) if os.path.exists(ytdl_stamp): os.remove(ytdl_stamp) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, 'w') f.write(update_time) f.close() else: send_notification('youtube-dl is already newest version') logger.debug('yt-link:>>{0}'.format(final_url)) if mode == 'TITLE' and not final_url: final_url = url.split('/')[-1] return final_url
def download(self, url, option): if option.lower() == 'play with kawaii-player': final_url = '' self.ui.epn_name_in_list = self.title_page print(self.ui.epn_name_in_list) if self.ui.mpvplayer_val.processId() > 0: self.ui.mpvplayer_val.kill() self.ui.mpvplayer_started = False if 'youtube.com' in url.toString() or 'ytimg.com' in url.toString( ): final_url = url.toString() else: final_url = 'ytdl:' + url.toString() self.ui.get_final_link(final_url, self.ui.quality_val, self.ui.ytdl_path, self.ui.logger, self.ui.epn_name_in_list, self.hdr) elif option.lower() == 'add as local playlist': self.get_playlist = True if self.playlist_dict: print(self.get_playlist, '=get_playlist') self.add_playlist(self.playlist_name) elif option.lower() == 'download': if self.ui.quality_val == 'sd480p': txt = "Video can't be saved in 480p, Saving in either HD or SD" send_notification(txt) quality = 'hd' else: quality = self.ui.quality_val finalUrl = get_yt_url(url.toString(), quality, self.ui.ytdl_path, self.ui.logger, mode='offline') finalUrl = finalUrl.replace('\n', '') title = self.title_page + '.mp4' title = title.replace('"', '') title = title.replace('/', '-') if os.path.exists(self.ui.default_download_location): title = os.path.join(self.ui.default_download_location, title) else: title = os.path.join(self.ui.tmp_download_folder, title) command = wget_string(finalUrl, title, self.ui.get_fetch_library) print(command) self.ui.infoWget(command, 0) elif option.lower() == 'get subtitle (if available)': self.ui.epn_name_in_list = self.title_page print(self.ui.epn_name_in_list) get_yt_sub(url.toString(), self.ui.epn_name_in_list, self.yt_sub_folder, self.ui.tmp_download_folder, self.ui.ytdl_path, self.ui.logger) elif option.lower() == 'queue item': file_path = os.path.join(self.home, 'Playlists', 'Queue') if not os.path.exists(file_path): f = open(file_path, 'w') f.close() if not self.ui.queue_url_list: self.ui.list6.clear() title = self.title_page.replace('/', '-') if title.startswith('.'): title = title[1:] r = title + ' ' + url.toString() + ' ' + 'NONE' self.ui.queue_url_list.append(r) self.ui.list6.addItem(title) print(self.ui.queue_url_list) write_files(file_path, r, line_by_line=True) elif option.lower() == 'season episode link': if self.site != "Music" and self.site != "PlayLists": my_copy = self.ui.epn_arr_list.copy() r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.metaengine.getTvdbEpnInfo(url.toString(), site=self.site, epn_arr=my_copy, name=nm, row=r) elif (option.lower() == 'artist link' or option.lower() == 'series link' or option.lower() == 'series/movie link'): url = url.toString() r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=True, copy_poster=True, copy_fanart=True) else: url = url.toString() if url: t_content = ccurl(url, curl_opt='-I') if 'image/jpeg' in t_content and not 'Location:' in t_content: pass elif 'image/jpeg' in t_content and 'Location:' in t_content: m = re.findall('Location: [^\n]*', t_content) found = re.sub('Location: |\r', '', m[0]) url = found elif not self.img_url.isEmpty(): url = self.img_url.toString() else: return 0 if '#' in url: url = url.split('#')[0] if option.lower() == "download as fanart": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) print(option, '----') self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=True) elif option.lower() == "download as cover": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=True, copy_fanart=False)
def get_yt_url(url, quality, ytdl_path, logger, mode=None): final_url = '' url = url.replace('"', '') m = [] home_dir = get_home_dir() ytdl_stamp = os.path.join(home_dir, 'tmp', 'ytdl_update_stamp.txt') if ytdl_path: if ytdl_path == 'default': youtube_dl = 'youtube-dl' else: if os.path.exists(ytdl_path): youtube_dl = ytdl_path else: if ytdl_path.endswith('ytdl') or ytdl_path.endswith('ytdl.exe'): send_notification('Please Wait! Getting Latest youtube-dl') youtube_dl = ytdl_path if ytdl_path.endswith('ytdl'): ccurl('https://yt-dl.org/downloads/latest/youtube-dl'+'#-o#'+ytdl_path) subprocess.Popen(['chmod', '+x', ytdl_path]) else: ccurl('https://yt-dl.org/latest/youtube-dl.exe'+'#-o#'+ytdl_path) update_time = str(int(time.time())) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, 'w') f.write(update_time) f.close() else: send_notification('youtube-dl path does not exists!') youtube_dl = 'youtube-dl' else: youtube_dl = 'youtube-dl' logger.info(youtube_dl) if '/watch?' in url: a = url.split('?')[-1] b = a.split('&') if b: for i in b: j = i.split('=') k = (j[0], j[1]) m.append(k) else: j = a.split('=') k = (j[0], j[1]) m.append(k) d = dict(m) logger.info('----dict--arguments---generated---{0}'.format(d)) try: url = 'https://m.youtube.com/watch?v='+d['v'] except: pass try: if mode == 'TITLE': if os.name == 'posix': final_url = subprocess.check_output([youtube_dl, '-e', url]) else: final_url = subprocess.check_output([youtube_dl, '-e', url], shell=True) final_url = str(final_url, 'utf-8') final_url = final_url.replace(' - YouTube', '', 1) else: if mode == 'music': quality = 'best' if os.name == 'posix': if quality == 'sd480p': if mode: if mode == 'offline': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') elif mode == 'music' or (mode == 'a+v' and ytdl_path != 'default'): final_url = subprocess.check_output( [youtube_dl, '-f', 'bestvideo[height<=480]+bestaudio', '-g', url]) final_url = str(final_url, 'utf-8') final_url = final_url.strip() logger.info(final_url) if '\n' in final_url: vid, aud = final_url.split('\n') final_url = vid+'::'+aud else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') elif quality == 'sd': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') elif quality == 'best': if mode: if mode == 'offline': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') elif mode == 'music' or (mode == 'a+v' and ytdl_path != 'default'): final_url = subprocess.check_output( [youtube_dl, '-g', url]) final_url = str(final_url, 'utf-8') final_url = final_url.strip() logger.info(final_url) if '\n' in final_url: vid, aud = final_url.split('\n') final_url = vid+'::'+aud else: if ytdl_path == 'default': final_url = url else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') else: if ytdl_path == 'default': final_url = url else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') elif quality == 'hd': try: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '22', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') except: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url]) final_url = str(final_url, 'utf-8') else: if quality == 'sd480p': if mode: if mode == 'offline': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') elif mode == 'music' or (mode == 'a+v' and ytdl_path != 'default'): final_url = subprocess.check_output( [youtube_dl, '-f', 'bestvideo[height<=480]+bestaudio', '-g', url], shell=True) final_url = str(final_url, 'utf-8') final_url = final_url.strip() logger.info(final_url) if '\n' in final_url: vid, aud = final_url.split('\n') final_url = vid+'::'+aud else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') else: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') elif quality == 'sd': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') elif quality == 'best': if mode: if mode == 'offline': final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', 'best', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') elif mode == 'music' or (mode == 'a+v' and ytdl_path != 'default'): final_url = subprocess.check_output( [youtube_dl, '-g', url], shell=True) final_url = str(final_url, 'utf-8') final_url = final_url.strip() logger.info(final_url) if '\n' in final_url: vid, aud = final_url.split('\n') final_url = vid+'::'+aud else: final_url = url else: final_url = url elif quality == 'hd': try: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '22', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') except: final_url = subprocess.check_output( [youtube_dl, '--youtube-skip-dash-manifest', '-f', '18', '-g', '--playlist-end', '1', url], shell=True) final_url = str(final_url, 'utf-8') except Exception as e: logger.info('--error in processing youtube url--{0}'.format(e)) txt = 'Please Update youtube-dl' send_notification(txt) final_url = '' updated_already = False if ytdl_path.endswith('ytdl') or ytdl_path.endswith('ytdl.exe'): if os.path.exists(ytdl_stamp): content = open(ytdl_stamp, 'r').read() try: old_time = int(content) except Exception as e: log.info(e) old_time = int(time.time()) - 3600 cur_time = int(time.time()) if (cur_time - old_time < 24*3600): updated_already = True if not updated_already: send_notification('Please Wait! Getting Latest youtube-dl') if ytdl_path.endswith('ytdl'): ccurl('https://yt-dl.org/downloads/latest/youtube-dl'+'#-o#'+ytdl_path) subprocess.Popen(['chmod', '+x', ytdl_path]) else: ccurl('https://yt-dl.org/latest/youtube-dl.exe'+'#-o#'+ytdl_path) send_notification('Updated youtube-dl, Now Try Playing Video Again!') update_time = str(int(time.time())) if os.path.exists(ytdl_stamp): os.remove(ytdl_stamp) if not os.path.exists(ytdl_stamp): f = open(ytdl_stamp, 'w') f.write(update_time) f.close() else: send_notification('youtube-dl is already newest version') logger.debug('yt-link:>>{0}'.format(final_url)) return final_url
def getFinalUrl(self,siteName,name,epn,mirrorNo,quality): global qualityVideo,mirror_number mirror_number = mirrorNo qualityVideo = quality final = '' if siteName == "Cartoon-World" or siteName == "Cartoon-World-Cartoon" or siteName == "Cartoon-World-Movies": if ' ' in epn: epn = epn.split(' ')[1] url = "http://allmyanime.io" + epn content = ccurlNew(url) print(url) m = [] soup = BeautifulSoup(content,'lxml') link = soup.findAll('iframe') print(link) for i in link: if 'vidcrazy' in i['src'] or 'uploadcrazy' in i['src'] or 'mp4star' in i['src'] or 'justmp4' in i['src'] or 'gotvb8' in i['src'] or 'vidkai' in i['src'] or 'mp4buddy' in i['src'] or 'mp4upload' in i['src']: m.append(i['src']) print(m) final = self.get_correct_mirror(m,mirrorNo) elif siteName == "Animetycoon": url = "http://www.animetycoon.org/" + epn + "/" content = ccurlNew(url) print(url) final = "" m = re.findall('http://[^"]*uploadcrazy[^"]*|http://[^"]*vidkai[^"]*|http://[^"]*justmp4[^"]*|http://[^"]*mp4star[^"]*',content) print(m) arr = [] for i in m: if i.endswith('.jpg') or i.endswith('.jpeg'): pass else: arr.append(i) final = self.get_correct_mirror(arr,mirrorNo) elif siteName == "Dubcrazy": url = "http://www.dubbedanimeon.me/" + epn + "/" content = ccurlNew(url) print(url) m = [] n =[] soup = BeautifulSoup(content,'lxml') m = re.findall('http://[^"]*embed[^"]*',content) final = self.get_correct_mirror(m,mirrorNo) elif siteName == "AniDub": url = "https://www.watchcartoononline.io/" + epn print(url) content = ccurlNew(url) m = re.findall('["]https://[^"]*embed[^"]*',content) print(m) n = [] for i in m: j= i[1:] print(j) replc = {' ':'%20', '[':'%5B', ']':'%5D','!':'%21'} #j = str(urllib.parse.unquote(j)) n.append(j) print(n) post = 'confirm="Click+Here+to+Watch+Free!!"' for i in n: content = ccurlNew(i+'#'+'-d'+'#'+post) #print(content) m = re.findall('file: "http[^"]*',content) print(m) if m: final1 = re.findall('http://[^"]*',m[0]) if final1: print(final1[0],'++++++++++++++++++++++') k = final1[0] replc = {' ':'%20', '[':'%5B', ']':'%5D','!':'%21'} k = re.sub('\n','',k) content = ccurlNew(k+'#'+'-I') print(content,'-------------ccurlNew--------') n = re.findall('Location: [^\n]*',content) if n: final = re.sub('Location: |\r','',n[-1]) else: final = k print(final) final = re.sub(' ','%20',final) if final: break elif siteName == "AnimeStatic": url = "http://www.animestatic.co/" + epn + '/' print(url) content = ccurlNew(url) m = re.findall('["]http://[^"]*embed[^"]*',content) print(m) n = [] for i in m: j= i[1:] n.append(j) print(n) mirrorNo = mirrorNo -1 for i in n: url = n[mirrorNo] final = findurl(url) if final: break mirrorNo = mirrorNo + 1 elif siteName == "CartoonMax": final = '' url = "http://gogocartoon.us/" + epn print(url,'----------') content = ccurlNew(url) soup = BeautifulSoup(content,'lxml') #link = soup.find('div',{'class':'anime_video_body_watch'}) #if not link: #link = soup.find('div',{'class':'anime_video_body_watch_items_2'}) link = soup.find('div',{'class':'main-video'}) #print(link) sd = '' hd = '' sd480 = '' if link: link2 = link.find('iframe') print(link2) if link2: if 'src' in str(link2): link1 = link2['src'] print(link1,'---') if link1: if ' ' in str(link1): link1 = re.sub(' ','%20',str(link1)) print(link1) content1 = ccurlNew(link1) soup = BeautifulSoup(content1,'lxml') links = soup.findAll('source') for i in links: if 'src' in str(i): j = i['src'] if 'itag=22' in j: hd = j elif 'itag=18' in j: sd = j elif 'itag=59' in j: sd480 = j elif 'itag=43' in j: sd = j print (sd) print(sd480) print(hd) if not sd and not hd and not sd480: soup = BeautifulSoup(content,'lxml') link = soup.find('select',{'id':'selectQuality'}) if link: link1 = link.findAll('option') for i in link1: j = i['value'] if 'itag=18' in j: sd = j elif 'itag=22' in j: hd = j elif 'itag=37' in j: full_hd = j elif '=m18' in j: sd = j elif '=m22' in j: hd = j final_cnt = 0 final_quality = '' if sd: final_cnt = final_cnt+1 final_quality = final_quality + 'SD ' if sd480: final_cnt = final_cnt+1 final_quality = final_quality + '480P ' if hd: final_cnt = final_cnt+1 final_quality = final_quality + 'HD ' msg = "Total " + str(final_cnt) + " Quality Video Available "+final_quality+" Selecting "+str(quality) + " Quality" #subprocess.Popen(["notify-send",msg]) send_notification(msg) if quality == "sd": final_q = sd elif quality == 'sd480p': final_q = sd480 elif quality == 'hd': final_q = hd if not final_q and sd: final_q = sd print(final_q) if final_q: #content = (subprocess.check_output(['curl','-L','-I','-A',self.hdr,final_q])) #content = self.getContent(content) content = ccurlNew(final_q+'#'+'-I') print(content) m = re.findall('Location: https[^\n]*', content) #print(m if m: #print(m final = m[0] final = re.sub('Location: |\r', '', final) else: final = '' return final
def get_yt_sub_(url, name, dest_dir, tmp_dir, ytdl_path, log): global name_epn, dest_dir_sub, tmp_dir_sub, TMPFILE, logger logger = log if not ytdl_path: youtube_dl = 'youtube-dl' name_epn = name dest_dir_sub = dest_dir tmp_dir_sub = tmp_dir final_url = '' url = url.replace('"', '') m = [] if '/watch?' in url: a = url.split('?')[-1] b = a.split('&') if b: for i in b: j = i.split('=') k = (j[0], j[1]) m.append(k) else: j = a.split('=') k = (j[0], j[1]) m.append(k) d = dict(m) print(d, '----dict--arguments---generated---') try: url = 'https://m.youtube.com/watch?v='+d['v'] except: pass fh, TMPFILE = mkstemp(suffix=None, prefix='youtube-sub') dir_name, sub_name = os.path.split(TMPFILE) logger.info("TMPFILE={0};Output-dest={1};dir_name={2};sub_name={3}".format(TMPFILE, dest_dir_sub, dir_name, sub_name)) if ytdl_path == 'default': youtube_dl = 'youtube-dl' else: youtube_dl = ytdl_path command = [youtube_dl, "--all-sub", "--skip-download", "--output", TMPFILE, url] logger.info(command) if os.name == 'posix': subprocess.call(command) else: subprocess.call(command, shell=True) name = name_epn dest_dir = dest_dir_sub dir_name, sub_name = os.path.split(TMPFILE) m = os.listdir(dir_name) new_name = name.replace('/', '-') if new_name.startswith('.'): new_name = new_name[1:] sub_avail = False sub_ext = '' txt_notify = 'No Subtitle Found' for i in m: #j = os.path.join(dir_name, i) src_path = os.path.join(dir_name, i) if (i.startswith(sub_name) and i.endswith('.vtt') and os.stat(src_path).st_size != 0): k1 = i.rsplit('.', 2)[1] k2 = i.rsplit('.', 2)[2] ext = k1+'.'+k2 sub_ext = ext+', '+sub_ext dest_name = new_name + '.'+ ext #print(dest_name) dest_path = os.path.join(dest_dir, dest_name) #print(src_path, dest_path) if os.path.exists(src_path): shutil.copy(src_path, dest_path) os.remove(src_path) sub_avail = True if sub_avail: txt_notify = "External Subtitle "+ sub_ext+" Available\nPress Shift+J to load" if os.path.exists(TMPFILE): os.remove(TMPFILE) send_notification(txt_notify)
def download(self, url, option, copy_summary=None): if option.lower() == 'play with kawaii-player': final_url = '' self.ui.epn_name_in_list = self.title_page self.ui.logger.info(self.ui.epn_name_in_list) if self.ui.mpvplayer_val.processId() > 0: self.ui.mpvplayer_val.kill() self.ui.mpvplayer_started = False if 'youtube.com' in url or 'ytimg.com' in url: pass else: url = 'ytdl:' + url self.ui.get_final_link(url, self.ui.quality_val, self.ui.ytdl_path, self.ui.logger, self.ui.epn_name_in_list, self.hdr) elif option.lower() in ["cast this item", "cast queue"]: if option.lower() == "cast queue": self.ui.list2.process_browser_based_url( copy_summary, url, "queue") else: self.ui.list2.process_browser_based_url( copy_summary, url, "single") elif option.lower() == 'add as local playlist': self.get_playlist = True if self.playlist_dict: self.ui.logger.info(self.get_playlist, '=get_playlist') self.add_playlist(self.playlist_name) elif option.lower() == 'download': if self.ui.quality_val == 'sd480p': txt = "Video can't be saved in 480p, Saving in either HD or SD" send_notification(txt) quality = 'hd' else: quality = self.ui.quality_val finalUrl = self.ui.yt.get_yt_url(url, quality, self.ui.ytdl_path, self.ui.logger, mode='offline') finalUrl = finalUrl.replace('\n', '') title = self.title_page + '.mp4' title = title.replace('"', '') title = title.replace('/', '-') if os.path.exists(self.ui.default_download_location): title = os.path.join(self.ui.default_download_location, title) else: title = os.path.join(self.ui.tmp_download_folder, title) command = wget_string(finalUrl, title, self.ui.get_fetch_library) self.ui.logger.debug(command) self.ui.infoWget(command, 0) elif option.lower() == 'queue item': file_path = os.path.join(self.home, 'Playlists', 'Queue') if not os.path.exists(file_path): f = open(file_path, 'w') f.close() if not self.ui.queue_url_list: self.ui.list6.clear() title = self.title_page.replace('/', '-') if title.startswith('.'): title = title[1:] r = title + ' ' + url + ' ' + 'NONE' self.ui.queue_url_list.append(r) self.ui.list6.addItem(title) write_files(file_path, r, line_by_line=True) elif option.lower() == 'season episode link': if self.site != "Music" and self.site != "PlayLists": my_copy = self.ui.epn_arr_list.copy() r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) video_dir = None if self.site.lower() == 'video': video_dir = self.ui.original_path_name[r].split('\t')[-1] elif self.site.lower() in ['playlists', 'none', 'music']: pass else: video_dir = self.ui.original_path_name[r] self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=False, get_sum=True, video_dir=video_dir) elif (option.lower() == 'artist link' or option.lower() == 'series link' or option.lower() == 'series/movie link'): r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=True, copy_poster=True, copy_fanart=True) elif option.lower() == 'copy summary': self.ui.copySummary(copy_sum=copy_summary) else: if not url: url = self.media_url self.ui.logger.debug('{}--{}--media-url--'.format( url, self.media_url)) if url: t_content = ccurl(url, curl_opt='-I') if 'image/jpeg' in t_content and not 'Location:' in t_content: pass elif 'image/jpeg' in t_content and 'Location:' in t_content: m = re.findall('Location: [^\n]*', t_content) found = re.sub('Location: |\r', '', m[0]) url = found elif self.media_url: url = self.media_url else: return 0 if option.lower() == "download as fanart": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) print(option, '----') self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=False, copy_fanart=True) elif option.lower() == "download as cover": r = self.ui.list1.currentRow() nm = self.ui.get_title_name(r) self.ui.posterfound_new(name=nm, site=self.site, url=url, direct_url=True, copy_summary=False, copy_poster=True, copy_fanart=False)