|
| 1 | +import requests |
| 2 | +import os |
| 3 | +from bs4 import BeautifulSoup |
| 4 | +from prettytable import PrettyTable |
| 5 | + |
| 6 | +isHighQuality=True |
| 7 | +directory = 'C:\\Users\\rohan.yadav\\Downloads\\Movies' |
| 8 | + |
| 9 | +def download_series(url,directory): |
| 10 | + if(url[0:24]!='https://ytstv.com/series'): |
| 11 | + print('cannot download from this link, please select anothe link\nquitting...') |
| 12 | + return |
| 13 | + sc = requests.get(url) |
| 14 | + soup = BeautifulSoup(sc.text,'lxml') |
| 15 | + seasons = soup.select('.tvseason') |
| 16 | + index = 1 |
| 17 | + series_name = soup.select('#mv-info > div.mvi-content > div.mvic-desc > h3')[0].text |
| 18 | + series_root_directory = directory+'\\'+series_name |
| 19 | + safeMkdir(series_root_directory) |
| 20 | + qual = input("enter y for high quality torrents else enter n\n") |
| 21 | + if qual =="n": |
| 22 | + global isHighQuality |
| 23 | + isHighQuality = False |
| 24 | + options = {} |
| 25 | + for each_season in seasons: |
| 26 | + title = each_season.find('div',{'class' : 'les-title'}) |
| 27 | + print("Enter "+str(index)+" for : "+trim(title.text)) |
| 28 | + options[index] = (trim(title.text),each_season.select('.les-content > a')) |
| 29 | + print('------------------------------------') |
| 30 | + index+=1 |
| 31 | + option = int(input()) |
| 32 | + try: |
| 33 | + downloadSeason(options[option],series_root_directory) |
| 34 | + except KeyError as e: |
| 35 | + print('Bro select a valid option') |
| 36 | + |
| 37 | +def downloadSeason(season_data,root_directory): |
| 38 | + season_directory = root_directory +'\\'+ season_data[0] |
| 39 | + safeMkdir(season_directory) |
| 40 | + episodes = season_data[1] |
| 41 | + for episode in episodes: |
| 42 | + name = trim(episode.text) |
| 43 | + downloadEpisode(name,episode['href'],season_directory) |
| 44 | + |
| 45 | +def downloadEpisode(episode_name,episode_url,directory): |
| 46 | + try: |
| 47 | + sc = requests.get(episode_url) |
| 48 | + soup = BeautifulSoup(sc.text,'lxml') |
| 49 | + table = soup.find(id = 'lnk list-downloads') |
| 50 | + links = table.select('.lnk-lnk') |
| 51 | + torrent_url = links[-1]['href'] |
| 52 | + print('downloading '+ episode_name) |
| 53 | + resp = requests.get(torrent_url) |
| 54 | + with open(directory+'\\'+episode_name+'.torrent','wb') as f: |
| 55 | + f.write(resp.content) |
| 56 | + f.close() |
| 57 | + except Exception as e: |
| 58 | + print('failed to download '+ episode_name +' you can download the torrent at '+ episode_url) |
| 59 | + |
| 60 | + |
| 61 | +def search_series(): |
| 62 | + pass |
| 63 | + |
| 64 | +def show_list(): |
| 65 | + sc = requests.get('https://ytstv.com/series/') |
| 66 | + soup = BeautifulSoup(sc.text,'lxml') |
| 67 | + pages = int(len(soup.select('#pagination > nav > ul > li'))/2) |
| 68 | + list = [] |
| 69 | + list.extend(get_list(soup)) |
| 70 | + for i in range(2,pages+1): |
| 71 | + sc =requests.get('https://ytstv.com/series/page/'+str(i)+'/') |
| 72 | + soup = BeautifulSoup(sc.text,'lxml') |
| 73 | + list.extend(get_list(soup)) |
| 74 | + table = PrettyTable(['index','Name', 'Ratings']) |
| 75 | + index = 1 |
| 76 | + selected_option = {} |
| 77 | + for movies in list: |
| 78 | + table.add_row([index,movies[0],movies[1]]) |
| 79 | + selected_option[index] = movies[2] |
| 80 | + index+=1 |
| 81 | + print(table) |
| 82 | + global directory |
| 83 | + option = int(input('Enter the index no. of the movie\n')) |
| 84 | + try: |
| 85 | + download_series(selected_option[option],directory) |
| 86 | + except KeyError as e: |
| 87 | + print('Bro select a valid option...') |
| 88 | + |
| 89 | +def get_list(soup): |
| 90 | + list = soup.select('#main > div > div.main-content.main-category > div > div.movies-list.movies-list-full > div') |
| 91 | + arr = [] |
| 92 | + for least in list: |
| 93 | + try: |
| 94 | + demo = [] |
| 95 | + demo.append(least.select('.qtip-title')[0].text) |
| 96 | + demo.append(least.select('.jt-imdb')[0].text) |
| 97 | + demo.append(least.select('.ml-mask')[0]['href']) |
| 98 | + arr.append(demo) |
| 99 | + except Exception as e: |
| 100 | + i |
| 101 | + return arr |
| 102 | + |
| 103 | +def trim(unstripped_string): |
| 104 | + return unstripped_string.replace('\n','').strip() |
| 105 | + |
| 106 | +def safeMkdir(path): |
| 107 | + if not os.path.exists(path): |
| 108 | + os.makedirs(path) |
| 109 | + |
| 110 | +def main(): |
| 111 | + # resp = int(input('enter 1 for displaying list of available tv series\nenter 2 for searching specific series\n')) |
| 112 | + # if(resp == 2): |
| 113 | + # search_series() |
| 114 | + # else: |
| 115 | + # show_list() |
| 116 | + show_list() |
| 117 | + |
| 118 | +if __name__ == '__main__': |
| 119 | + main() |
0 commit comments