Ejemplo n.º 1
0
def update_subscriber_movies(name):

    ################################################################################
    ################################################################################
    # MOVIES - this is much easier - just check for any new movies and prompt for
    # copy or not

    #stores the folder names of movies to copy:
    global movie_copy_queue
    
    for dir in config['movie_paths']:
        files_in_path = utils.listdirPaths(dir)
        for file in files_in_path:
            if file != ".deletedByTMM":
                movies_available.append(file)

    logging.info( "MOVIES AVAILABLE:" )
    for file in movies_available:
        logging.debug( file )

    logging.info( "CHANGES: " )
    #what is the difference
    for movie in movies_available:
        movie_name = os.path.basename(movie)
        #pprint.pprint(user_config['movies_to_ignore'][0:10])
        #print(movie_name)
        #in agogo mode we add all unwatched movies to the queue
        #if args.mode=="agogo":
        #    logging.info(movie_name + " - Added")
        #    movie_copy_queue.append(movie)
        #elif movie_name not in user_config['movies_to_ignore']:

        if movie_name not in user_config['movies_to_ignore'] and movie_name != ".deletedByTMM":
            print ""
            answer = raw_input("Add new movie " + repr(movie_name) + " to copy list (return = no, y = yes)")
            if (not answer) or answer =="n" or answer=="N":
                logging.info(movie_name + " - Not Added")
            else:
                logging.info(movie_name + " - Added")
                movie_copy_queue.append(movie)
Ejemplo n.º 2
0
def update_subscriber_tv(name):
    """ Do a library update for a subscriber """

    global config
    global user_config
    global args
    global outputPaths
    global tv_copy_queue
    global unfound_shows
    global original_show_list


    ##############################################################################
    # build a list of all available tv shows, and 

    show_list, new_show_list = build_show_lists()
 
    ################################################################################
    logging.info( str(len(user_config['basic_show_list'])) + " AVAILABLE SHOWS" )
    for show in sorted(user_config['basic_show_list'], key=str.lower):
        logging.debug( os.path.basename(show) )

    if len(new_show_list)>0:
        logging.debug( str(len(new_show_list)) + " NEW SHOWS FOUND:" )
        for show in new_show_list:
            logging.debug( os.path.basename(show) )

    logging.info( "ADD ANY NEW SHOWS INTERACTIVELY" )

    #add new shows?
    for show in new_show_list:
        print ""
        answer = raw_input("Add new TV show " + show + " to copy list (return = no, y = yes)")
        if (not answer) or answer=="n" or answer=="N":
            print (show + " - Not Added, set to 0|0 in output_show_list")
            logging.debug  (show + " - Not Added, set to 0|0 in output_show_list")
            output_show_list[os.path.basename(show)] = [0,0]
        else:
            print show + " - Added "
            logging.info  (show + " - Added")
            user_config['tv_wanted_list'].append(os.path.basename(show) + "|1|0\n")

    ################################################################################


    logging.info( "NOW PROCESSING EACH WANTED SHOW" )

    #ok for each wanted show...
    for wanted in user_config['tv_wanted_list']:

        # Parse config file
        try:
            wanted_show, wanted_season, wanted_episode, showId = wanted.split('|')
            wanted_season_int = int(wanted_season)
            wanted_season = format(wanted_season_int, "02d")
            wanted_episode = int(wanted_episode)
            showId = int(showId)
        except Exception as inst:
            logging.error("Problem in config: " + wanted + " " + format_exc(inst))
            sys.exit()

        #record where we started
        original_show_list[wanted_show] = [wanted_season_int,wanted_episode]

        #######################
        #skip if set to 0,0
        if wanted_season_int == 0 and wanted_episode == 0:
            logging.info( "Show: " + wanted_show + " set to 0|0 -> skip it")
            original_show_list[wanted_show] = [0,0]
            output_show_list[wanted_show] = [0,0]
            #print outputShowList
            #go back to the top of the loop for the next show
            continue

        #######################
        #otherwise start processing
        logging.info( "Show: Wanted name: " + wanted_show + " - Wanted Series: " + str(wanted_season) + " - Wanted Epsiode: " + str(wanted_episode) )

        found_show = False
        output_folder = ""
        origin_folder = ""

        ############
        #do we recognise this show?
        for possible_show in show_list:
            # logging.info("Matching " + wanted_show + " to " + os.path.basename(possible_show))
            if wanted_show == os.path.basename(possible_show):
                logging.info("Matched " + wanted_show + " to " + possible_show)
                output_folder = os.path.join(user_config['paths']['tv_output_path'], wanted_show)
                origin_folder = possible_show
                found_show = True
                break;

        #show is not in the available list
        if not found_show:
            logging.error ( "WARNING: SHOW NOT FOUND - so added to unfound list" )
            unfound_shows.append(wanted_show)
        # we found it, so let's maybe copy some stuff
        else:
            logging.info( "Show: From: " + origin_folder )
            logging.info( "Show: To:   " + output_folder )

            #ok so the show is available and we want some of it.  Let's find out if there are new episodes?
            start_season_int =  int(wanted_season)
            start_season_folder = origin_folder +"\\Season " + wanted_season
            start_season_folder_output = output_folder +"\\Season " + wanted_season

            #set up for loop
            current_season_folder = start_season_folder
            current_season_folder_output = start_season_folder_output
            current_season_int = start_season_int
            episode_considering = 0

            season_folder_exists = True
            found_new_episode = False

            #we loop through each season until we can't find another season
            while season_folder_exists:
                if os.path.exists(current_season_folder):
                    #the season folder exists
                    logging.info( "Show: Handling " + os.path.basename(current_season_folder) )

                    #make a list of files in the current season
                    current_season_files = utils.listdirPaths(current_season_folder)

                    #ok so now we want to match only the wanted episode and above and add them to the copy queue
                    #keep track of them for logginh
                    episodes_added = []
                    #and a queue to store files like folder.jpg that we will only copy if we found at least 1 new ep.
                    possible_queue = []

                    for current_season_file in current_season_files:
                        #match the SXXEXX part of the filename
                        p = re.compile('S[0-9]*E[0-9]*')
                        match = p.search(current_season_file)
                        if match:
                            episode_string = match.group()
                            #logging.info( "episodeString is " + episodeString
                            episode_considering = int(episode_string[4:6])
                            if episode_considering > wanted_episode:
                                found_new_episode = True
                                if episode_string not in episodes_added:
                                    episodes_added.append(episode_string)
                                #logging.info("Show: Episode " + str(episodeConsidering) + " file is newer than " + str(wantedEpisode) +", adding to queue")
                                tv_copy_queue.append([current_season_file, current_season_folder_output, wanted_show, showId, int(current_season_int), int(episode_considering)])
                            #else:
                                #logging.info("Show: Episode " + str(episodeConsidering) + " file is older/same than " + str(wantedEpisode) +", not adding")

                        else:
                            logging.info( "Show: Did not match - copy just to be safe? " + current_season_file)
                            possible_queue.append([current_season_file, current_season_folder_output])

                    #copy unmatched files if we're adding new things to this season (e.g. folder.jpg)
                    if found_new_episode and len(possible_queue) > 0:
                        logging.info( "Show: Adding unmatched files to queue as we found a new episode - " + str(possible_queue) )
                        tv_copy_queue.extend(possible_queue)

                    #get set up for the next season
                    current_season_int += 1
                    current_season_folder = origin_folder + "\\Season " + '%0*d' % (2, current_season_int)
                    current_season_folder_output = output_folder + "\\Season " + '%0*d' % (2, current_season_int)
                    #if we're moving up a season we want all episodes from the new season
                    wanted_episode = 0
                    if len(episodes_added)>0:
                        logging.info("Show: Added: " + str(episodes_added))
                    else:
                        logging.info("Show: No episodes to add from this season.")

                else:
                    logging.info( "Show: There is no: " + current_season_folder)
                    break

            #if we copied anything from this season, record the last thing we copied
            output_show_int = current_season_int - 1
            #don't decrement if we didn't copy a new season
            if output_show_int < wanted_season_int:
                output_show_int = wanted_season_int
            output_show_list[wanted_show] = [output_show_int,episode_considering]
            logging.info( "Show: Updated " + wanted_show + " to " + str(output_show_list[wanted_show]) )

            # If here are any new epsiodes, add the base files to the queue as well (e.g. folder.jpg)
            if found_new_episode:
                base_dir_files = utils.listfiles(origin_folder)
                short_list = []
                for base_dir_file in base_dir_files:
                    tv_copy_queue.append([base_dir_file, output_folder])
                    short_list.append(os.path.basename(base_dir_file))
                logging.info( "Show: Base files found and added to queue: " + str(short_list) )
Ejemplo n.º 3
0
def set_up_new_person(name, latest_episodes=None, watched_movies=None):
    """ 
    Sets up a new subscriber to the library by creating the tv.name.txt and movies.names.txt config files
    Can be in two ways  - just initialisation, in which case the config files created are all movies seen/tvshow|0|0 - i.e. don't want this show
                        - with a list of latestEpisodes which should have in it the names of the latest watched episodes for all shows with unwatched episodes remaining

    """

    global user_config
    global config

    if args.update =="tv" or args.update =="both":
        #create the 3 config files - one for tv, paths, and optionally one for movies if we're not
        out_config_tv_filename = "config/Subscribers/config." + name + ".tv.txt"
  
        answer = ""
        create_file = True

        #don't clobber existing files by accident
        if os.path.isfile(out_config_tv_filename):
            logging.error("TV config file already exists: " + out_config_tv_filename)
            create_file = False
            answer = raw_input("Over write existing config file [x] or use the existing file [enter]?")

        if create_file or answer.lower()=="x" or args.mode=="init":

            out_config_tv_file = open(out_config_tv_filename, 'w')

            # DO TV SHOW ZERO LIST
            tv_show_list = []

            for d in config['tv_paths']:
                temp = utils.listdirPaths(d)
                for a in temp:
                    tv_show_list.append(os.path.basename(a))

            logging.debug("\nTV show list is: \n" + pprint.pformat(sorted(tv_show_list)))

            if latest_episodes is None:
                logging.info("Setting all TV shows to unwanted in created config file")
                for show in sorted(tv_show_list):
                   out_config_tv_file.write( show + "|0|0|" + str(latest_episodes[show]["showId"]) + "\n")

            else:            
                logging.info("Processing latest episodes list (creating on-the-fly a-go-go config)")
                for show in sorted(tv_show_list):
                    logging.debug("Processing: " + show)
                    #check if there is a latest watched episode for this how
                    if show not in latest_episodes:
                        logging.debug(show + " was not found to have a latest watched epsiode - set to unwanted")
                        user_config[show] = {'season':0,'episode':0}
                        out_config_tv_file.write( show + "|0|0|0\n")
                    else:
                        logging.debug( show + " has a latest watched episode of " + str(latest_episodes[show]["season"]) + "|" + str(latest_episodes[show]["episode"]))
                        #we're creating an output file for aGoGo machine so get the latest wathched episode and record the previous episode 
                        #in the config file as the last one copied
                        outEpNum = int(latest_episodes[show]["episode"])
                        #the config file stores the latest watched episode - so we have to take one off the unwatched episode number
                        if outEpNum > 0:
                            outEpNum = outEpNum - 1
                        
                        out_config_tv_file.write( show + "|" + latest_episodes[show]["season"] + "|" + str(outEpNum) + "|" + str(latest_episodes[show]["showId"]) + "\n")
             
            out_config_tv_file.close()      

    # DO MOVIE LIST & BATCH FILE IF WE'RE NOT UPDATING AN aGoGO Machine
    # i.e. with aGoGo machines we don't currenly do anything with movies, we manually copy those

    if args.update =="movies" or args.update =="both":

        out_config_movies_filename = "config/Subscribers/config." + name + ".movies.txt"

        answer=""
        #don't clobber existing files by accident
        if os.path.isfile(out_config_movies_filename):
            logging.error("Movie config file already exists " + out_config_movies_filename)
            answer = raw_input("Over write existing config file [x] or use the existing file [enter]?")
            
        if answer.lower()=="x" or args.mode=="init":
            out_config_movies_file = open(out_config_movies_filename, 'w')
            #not doing agogo, so build watched_movies now
            if watched_movies is None:
                logging.info("Setting all movies to seen in created config file")
                watched_movies = []

                for d in config['movie_paths']:
                    temp = utils.listdirPaths(d)
                    for a in temp:
                        watched_movies.append(os.path.basename(a))

            logging.debug("\nSeen Movies is: \n" + pprint.pformat(watched_movies))

            for movie in sorted(watched_movies):
                out_config_movies_file.write(movie + "\n")

            out_config_movies_file.close()


    # DO PATHS
    #create empty paths in all cases

    if args.mode!="agogo":
        out_config_paths_filename = "config/Subscribers/config." + name + ".paths.yaml"
        if os.path.isfile(out_config_paths_filename):
            logging.error("Config file already exists: " + out_config_paths_filename)
        else:
            out_config_paths_file = open(out_config_paths_filename, 'w')
            user_config['paths'] = {'tv_output_path': "", 'movie_output_path': ""}
            yaml.dump(user_config, out_config_paths_file, default_flow_style=False,allow_unicode=True)
            out_config_paths_file.close()