def testPickFromHostSiteTypes(self): #picking arbitrary season, episode hostsitepicker.pickFromLinkSite(self.getLinkSite(), 2, 2)
def main(): parser = argparse.ArgumentParser( description = 'Jankflix - A jankier way to watch things!') parser.add_argument('query', type = str, help = 'A show you want to watch', nargs = "?") parser.add_argument('-s', dest = 'season', type = int, help = 'season to watch') parser.add_argument('-e', dest = 'episode', type = int, help = 'episode to watch') parser.add_argument('-c', dest = 'command', type = str, help = 'command to run when the video starts downloading') args = parser.parse_args() query = args.query season = args.season episode = args.episode command = args.command while True: if not query: query = raw_input("What show do you want to watch: ") search_result = OneChannel.searchSite(query) if len(search_result) == 0: print "Search did not return any results." query = None else: break for i in range(len(search_result)): title, link = search_result[i] print "%i : %s (%s)" % (i, title, link) if len(search_result) > 1: selnum = get_int_input("Which one do you want to watch: ", 0, len(search_result) - 1) else: print "Automatically choosing %s" % (search_result[0][0]) selnum = 0 title, link = search_result[selnum] print "Accessing show page" oc = OneChannel(link) seasons = oc.getSeasons() if season and season not in seasons: print "Season does not exist. Please choose another." season = None if not season: print "Seasons: ", str(seasons)[1:-1] season = get_int_input("Which season do you want to watch: ", int(min(seasons)), int(max(seasons))) #this assumes that between the min and max of the season numbers, #it is completely filled. print "Selecting season %d" % (season) episodes = oc.getEpisodes(season) names = oc.getEpisodeNames(season) if episode and episode not in episodes: print "Episode does not exist. Please choose another." episode = None if not episode: #TODO: this doesn't work. Need to cast array to int to run min on it. for i in range(len(episodes)): print episodes[i], ":", names[i] episode = get_int_input("Which episode do you want to watch: ", int(min(episodes)), int(max(episodes))) #this assumes that between the min and max of the season numbers, #it is completely filled. print "Selecting episode %d" % (episode) if not command : save_or_run = get_int_input( "Do you want to (0) save or (1) run the episode: ", 0, 1) if save_or_run == 1: command = raw_input("Run with which program? (vlc): ") if command == "": command = "vlc" print "Getting host site" host_site = hostsitepicker.pickFromLinkSite(oc, season, episode) metadata = host_site.getMetadata() video_url = host_site.getVideo() filename = "%sS%sE%s.%s" % (query, str(season).zfill(2), str(episode).zfill(2), metadata["extension"]) if command: processs, status = downloadmanager.start_downloads([(video_url, filename)]) atexit.register(onexit, proc = processs[0], rmFile = filename) for i in range(30): if os.path.isfile(filename) and os.stat(filename).st_size > 1000: break else: time.sleep(.2) subprocess.call([command, filename]) processs[0].terminate() else: processs, status = downloadmanager.start_downloads([(video_url, filename)]) atexit.register(onexit, proc = processs[0]) while processs[0].is_alive: print status[0].get(True)