def startMuxing(): mkvtoolnix.removeFolders() mkv = mkvtoolnix.getEpisodesList() if not mkv: print('\nPrima devi scaricare degli episodi') for episode in mkv: file = os.path.basename(episode) match = re.search(r'.+\.S[0-9][0-9]E[0-9]+', file).group(0) name, ep = match.split('.S') subprocess.call('RMDIR /S /Q '+setup.getSetting('subtitles'), shell=True) print('\nScarico sottotitoli per', name.replace('.', ' '), ep) if itasa.downloadSub(episode): itaSub = setup.getSetting('subtitles')+'ita.srt' newFile = mkvtoolnix.getNewFilePath(name, ep) mkvmerge = mkvtoolnix.getMkvmergePath()+' -o ' for ch in SPECIAL: newFile = newFile.replace(ch, '') cmd = mkvmerge+'"'+newFile+'" "'+episode+'" "'+itaSub+'"' if subprocess.call(cmd, shell=True) == 0: print('Muxing completato per', os.path.basename(newFile)) else: print('Muxing fallito per', os.path.basename(newFile)) try: os.remove(itaSub) except: pass else: print('Sottotitoli non ancora disponibili')
def getEpisodesList(): result = [] downloadsDir = setup.getSetting('downloads') for root, dirs, files in os.walk(downloadsDir): for filename in fnmatch.filter(files, '*E[0-9][0-9]*.m??'): episode = os.path.join(root, filename) result.append(episode) return result
def updateSerie(name, page): source = kat.getSource(page) episodes = kat.getEpisodes(source) season = kat.getSeasons(source) if name == 'Castle': name = 'Castle 2009' if name == 'The Flash': name = 'The Flash 2014' # Crea cartelle e sottocartelle ogni stagione della serie newFilePath = setup.getSetting('location', name) for ch in SPECIAL: name = name.replace(ch, '') path = os.path.join(newFilePath+name+'\\') if not os.path.isdir(path): os.makedirs(path) for i in range(season): pathSeason = ''.join(path+str(i+1)+'° Stagione') if not os.path.isdir(pathSeason): os.mkdir(pathSeason) # Aggiorna o crea file serie TV newFile = '' path = 'serieTV\\'+name+'.txt' try: file = open(path, 'r') for i in range(len(episodes)): line = file.readline() if line != episodes[i] and line[-2] == 'x': newFile += ''.join(name.title()+' '+episodes[i]+'x\n') else: newFile += line file.close() except: for element in episodes: if kat.compareDate(element): newFile += ''.join(name.title()+' '+element+'v\n') else: newFile += ''.join(name.title()+' '+element+'x\n') file = open(path, 'w') file.write(html.unescape(newFile)) file.close() # Aggiorno preferiti.txt if not os.path.exists('preferiti.txt'): file = open('preferiti.txt', 'w') file.write(name+';'+page+'\n') file.close() else: file = open('preferiti.txt', 'r+') content = file.read() if not re.search(name, content): file.write(name+';'+page+'\n') file.close()
def itasaLogin(): with open('impostazioni.txt', 'r') as file: content = file.read() file.close() user = setup.getSetting('itasaUser') passwd = setup.getSetting('itasaPass') if not user or not passwd: user = input('Username Itasa: -> ') passwd = input('Password Itasa: -> ') newContent = content + '\nitasaUser='******'\nitasaPass='******'impostazioni.txt', 'w') as file: content = file.write(newContent) file.close() url = URL + 'users/login?username='******'&password='******'&apikey=' + APIKEY source = getSource(url) xmldoc = minidom.parseString(source) status = xmldoc.getElementsByTagName('status')[0].firstChild.data if status == 'success': #userId = xmldoc.getElementsByTagName('id')[0].firstChild.data #name = xmldoc.getElementsByTagName('name')[0].firstChild.data #username = xmldoc.getElementsByTagName('username')[0].firstChild.data #email = xmldoc.getElementsByTagName('email')[0].firstChild.data #lastVisit = xmldoc.getElementsByTagName('last_visit')[0].firstChild.data authcode = xmldoc.getElementsByTagName('authcode')[0].firstChild.data #hasMyItasa = xmldoc.getElementsByTagName('has_myitasa')[0].firstChild.data #registerDate = xmldoc.getElementsByTagName('register_date')[0].firstChild.data #gender = xmldoc.getElementsByTagName('gender')[0].firstChild.data #birthdate = xmldoc.getElementsByTagName('birthdate')[0].firstChild.data #location = xmldoc.getElementsByTagName('location')[0].firstChild.data #website = xmldoc.getElementsByTagName('website_url')[0].firstChild.data #unreadMessages = xmldoc.getElementsByTagName('unread_message')[0].firstChild.data #karmaBad = xmldoc.getElementsByTagName('karma_bad')[0].firstChild.data #karmaGood = xmldoc.getElementsByTagName('karma_good')[0].firstChild.data return authcode else: print('Errore nel login') error = xmldoc.getElementsByTagName('error')[0].firstChild.data print(error)
def delSerie(): showFavourite() canc = input('\nNome seire TV da eliminare: -> ').title() # Rimuovo serie file path = ''.join('serieTV\\'+canc+'.txt') if os.path.exists(path): os.remove(path) print('Rimossa lista episodi per ', canc) else: print('Lista episodi inesistente per ', canc) # Rimuovo serie da preferiti if os.path.exists('preferiti.txt'): file = open('preferiti.txt', 'r') content = file.read() file.close() match = re.search(canc+'.+\n', content) try: with open('preferiti.txt', 'w') as file: content = content.replace(match.group(0), '') file.write(content) file.close() print(canc, 'rimosso dai preferiti') except: print(canc, 'non presente in preferiti') # Rimuovo episodi se richiesto answer = input('Vuoi cancellare anche gli episodi? (s/n)-> ').lower() if answer == 's': newFilePath = setup.getSetting('location') try: subprocess.call('RMDIR /S /Q '+newFilePath+canc) print('Episodi', canc, 'rimossi con successo') except: print('Non avevi episodi per', canc) else: print('Episodi non rimossi') # Rimuovo da myItasa se richiesto answer = input('Vuoi cancellare da myItasa? (s/n)-> ').lower() if answer == 's': itasaShowId = itasa.getShowBySearch(canc) itasa.removeFromMyItasa(itasaShowId) else: print('Serie TV non rimossa da myItasa')
def getNewFilePath(name, episode): ## file = open('serieTV/' + name.replace('.', ' ') + '.txt') content = file.read() file.close() # Trovo nome episodio da serie.txt match = re.search(r'.+' + episode[:2] + 'x' + episode[3:] + '.+;', content).group(0) fileName = match.replace(';', '.mkv').replace(episode[:2], str(int(episode[:2]))) muxedPath = setup.getSetting('location') if name == 'Castle.2009': name = 'Castle' if name == 'The.Flash.2014': name = 'The.Flash' path = muxedPath + name.replace('.', ' ') + '\\' + str(int( episode[:2])) + '° Stagione\\' + fileName return path
def removeFolders(): downloadsDir = setup.getSetting('downloads') # Estrare episodi da cartelle e filtra sample for root, dirs, files in os.walk(downloadsDir): for filename in fnmatch.filter(files, '*[0-9][0-9]E[0-9][0-9]*.m??'): episode = os.path.join(root, filename) match = re.search(r'sample', episode) if not match: try: shutil.move(episode, downloadsDir) except: pass # Elimina cartelle for folder in dirs: if re.search(r'S[0-9]+E[0-9]+', folder): try: os.system('RMDIR /S /Q ' + root + folder) except: pass
def downloadEpisode(episode): episode = episode.replace(' ', '-') match = re.search(r'.+x[0-9][0-9]', episode).group(0) episode = match[:len(match) - 5] + 's' + match[len(match) - 5:].replace( 'x', 'e') quality = setup.getSetting('quality') print('Scarico ->', episode) try: # Cerco file in hourlydump.txt (KickAss API) with open('hourlydump.txt', encoding='utf8') as file: content = file.read() file.close() pattern = ''.join('http://kat.ph/' + episode + '.+' + quality + '.+x264\S+html') torrent = re.search(pattern, content) source = getSource(torrent.group(0)) magnet = getMagnet(source) os.startfile(magnet) return True except: # Se non lo trovo cerco online episode = episode.replace('-', '%20') url = ''.join('http://kat.ph/usearch/' + episode + '%20' + quality + '%20HDTV%20x264') source = getSource(url) if not re.search(r'did not match any documents', source): magnet = getMagnet(source) os.startfile(magnet) return True else: print('File non trovato') return False
def downloadSub(filePath): subPath = setup.getSetting('subtitles') if not os.path.isdir(subPath): os.makedirs(subPath) # Determino serie, ep, itasaShowId e itasaSubId file = os.path.basename(filePath) match = re.search(r'.+\.S[0-9][0-9]E[0-9]+', file).group(0) name, ep = match.split('.S') name = name.replace('.', ' ') ep = str(int(ep[:2])) + 'x' + ep[3:] if name == 'Castle 2009': name = 'Castle' if name == 'The Flash 2014': name = 'The Flash' itasaShowId = getShowsBySearch(name) itasaSubId = getSubtitle(ep, showId=itasaShowId) if not itasaSubId: return False # Recupero username e password with open('impostazioni.txt', 'r') as file: content = file.read() file.close() user = setup.getSetting('itasaUser') passwd = setup.getSetting('itasaPass') if not user or not passwd: user = input('Username Itasa: -> ') passwd = input('Password Itasa: -> ') newContent = content + '\nitasaUser='******'\nitasaPass='******'impostazioni.txt', 'w') as file: content = file.write(newContent) file.close() # Login itasa url = 'http://www.italiansubs.net/index.php' headers = {'User-Agent': 'AssKickSeries 0.1'} response = requests.get(url, headers=headers) if response.status_code != 200: print('Initiate Failed') login_parameter = { 'username': user, 'passwd': passwd, 'remember': 'yes', 'Submit': 'Login', 'remember': 'yes', 'option': 'com_user', 'task': 'login', 'silent': 'true' } session = requests.session() r = session.post(url, data=login_parameter, headers=headers) if not re.search('logouticon.png', r.text): print('Itasa login failed') return False else: pass # Scarico zip, estraggo e rinomino ita.srt url = 'http://www.italiansubs.net/index.php?option=com_remository&Itemid=6&func=fileinfo&id=' response = session.get(url + itasaSubId, headers=headers) downloadLink = re.search(r'http://\S+' + itasaSubId + '\S+html=1', response.text) if downloadLink: response = session.get(downloadLink.group(0), headers=headers) if response: file = open(subPath + 'ita.zip', 'wb') file.write(response.content) file.close() with zipfile.ZipFile(subPath + 'ita.zip', 'r') as z: z.extractall(subPath) os.remove(subPath + 'ita.zip') for file in os.listdir(subPath): if file.endswith('itasa.srt'): os.rename(subPath + file, subPath + 'ita.srt') print('Sottotitoli italiani scaricati correttamente') return True else: print('Sottotitoli italiani non trovati') return False else: print('Sottotitoli italiani non trovati') return False