def handleChoseResult(self): index = self.getFirstSelectedIndex(self.ui.myResultsListWidget) if index is None: return self.ui.mySavePushButton.setEnabled(False) self.ui.myWatchPushButton.setEnabled(False) url = self.myQueryResult[index][1] # instansiate myLinkSite with correct # this avoids the condition where the radio # button is changed after the fact because we # are referencing myAreResultsTvLinks, rather # than the radio button itself. self.updateStatus("Finding seasons. Please wait...") if self.myAreResultsTvLinks: self.myLinkSite = TVLinks(url) else: self.myLinkSite = OneChannel(url) seasonUpdateMethod = lambda data: self.updateListWidget( data, self.ui.mySeasonListWidget) self.createWebRequestThread(seasonUpdateMethod, self.myLinkSite.getSeasons, listWidget=self.ui.mySeasonListWidget)
def decide(show): #search onechannel for show oc_result = OneChannel.searchSite(show)[0] print oc_result #search tvlinks tl_result = TVLinks.searchSite(show)[0] print tl_result #instanciate both objects passing in the second part of the result tuple, the link oc = OneChannel(oc_result[1]) tl = TVLinks(tl_result[1]) all_sites = dict() #season is the last season of the show season = oc.getSeasons()[-1] #for all episodes in that season for episode in oc.getEpisodes(season): for type in oc.getHostSiteTypes(season, episode): if "daclips" in type: print season, episode, "onechannel" if type in all_sites: all_sites[type] = all_sites[type] + 1 else: all_sites[type] = 1 print all_sites season = tl.getSeasons()[-1] for episode in tl.getEpisodes(season): for type in tl.getHostSiteTypes(season, episode): if "daclips" in type: print season, episode, "tvlinks" if type in all_sites: all_sites[type] = all_sites[type] + 1 else: all_sites[type] = 1 print all_sites sorted_sites = sorted(all_sites.iteritems(), key=operator.itemgetter(1)) sorted_sites.reverse() print sorted_sites
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)
class TestOneChannel(unittest.TestCase, TestLinkSite): link_site = OneChannel( "http://www.1channel.ch/watch-9583-Avatar-The-Last-Airbender")
class OneChannelPickingTest(unittest.TestCase, TestHostSitePicker): link_site = OneChannel( "http://www.1channel.ch/watch-9583-Avatar-The-Last-Airbender")