Exemple #1
0
    def make_from_filename(video_filepath):
        """ Returns a Movie or an Episode instance if it is possible,
        else returns a Video instance or None. """
        video = None

        if os.path.exists(video_filepath):
            try:
                video_signature = Video.get_video_signature(video_filepath)

                if video_signature:
                    guess = guessit.guess_movie_info(video_filepath,
                                                     info=['filename'])
                    if guess['type'] == 'movie':
                        video = Movie(video_filepath)
                    elif guess['type'] == 'episode':
                        video = Episode(video_filepath)
                    else:
                        video = Video(video_filepath)

                    video.signature = video_signature
            except FileMagicError:
                LOG.warning(
                    "This file was not recognized as a video file: {}".format(
                        video_filepath))
        else:
            LOG.error(
                "The following doesn't exists: {}".format(video_filepath))

        return video
Exemple #2
0
def update_movies_db(db, dir='files/' + movies_dir + '/'):
    """
    Find all movie files in the movie folder and add them to the database.
    """

    movies_in_db = [m.file_path for m in db.query(Movie).all()]

    for f in list_videos(dir):
        if f in movies_in_db:
            continue

        info("Currently scanning: " + f)
        filename, ext = path.splitext(f)
        f_info = stat(f)
        guess = guess_movie_info(f)

        movie = Movie()
        try:
            movie.title = guess['title']
        except:
            movie.title = filename

        movie.file_path = f
        movie.file_name = f
        movie.file_extension = ext[1:]
        movie.file_modification_date = datetime.fromtimestamp(f_info.st_mtime)
        movie.file_size = f_info.st_size
        movie.mime_type = guess_type(f)[0]

        db.add(movie)
    db.commit()
Exemple #3
0
    def compute_matches(self, video):
        matches = set()
        # episode
        if isinstance(video, Episode):
            # series
            if video.series and self.series.lower() == video.series.lower():
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            matches |= compute_guess_matches(
                video, guessit.guess_episode_info(self.release + '.mkv'))
        elif isinstance(video, Movie):
            if video.year and self.year == video.year:
                matches.add('year')

            if video.title and self.movie == video.title:
                matches.add('title')

            # guess
            matches |= compute_guess_matches(
                video, guessit.guess_movie_info(self.release + '.mkv'))
        else:
            logger.info('%r is not a valid movie_kind for %r', self.movie_kind,
                        video)
            return matches

        if self.subber and "yyets" in self.subber.lower():
            matches.add("yyets")

        return matches
def FILEtoIMDB(file_name):
    """
    Added function by nctiggy. This executes if the nzb does not have the IMDB id appended to the name
    This does capture all of the movies info not just the IMDB id
    """

    print "CouchPotatoServer did not append the IMDB id to the nzb, guessing instead"

    # Guessing at the name of the movie using the filename
    movie_info = guessit.guess_movie_info(file_name)

    #configuring tmdb to use the supplied api key
    tmdb.configure(tmdb_api_key)
    print "Guessed movie title as: %s" % (movie_info["title"])

    #Creating a collection of movies from tmdb for the guess movie title
    movies = tmdb.Movies(movie_info["title"])

    #parse through all movies found
    for movie in movies.iter_results():
        #Identify the first movie in the collection that matches exactly the movie title
        foundname = ''.join(e for e in movie["title"] if e.isalnum())
        origname = ''.join(e for e in movie_info["title"] if e.isalnum())
        if foundname.lower() == origname.lower():
            print "Matched movie title as: %s %s" % (movie["title"], movie["release_date"])
            movie = tmdb.Movie(movie["id"])
            break
    #return the imdb id of the movie identified
    return movie.get_imdb_id()
Exemple #5
0
    async def search(self, name):
        infos = guess_movie_info(name)
        if not infos.get('title'):
            return
        try:
            params = urlencode({
                's': infos['title'],
                'y': infos['year'],
                'type': 'movie',
                'r': 'json'
            })
        except KeyError:
            params = urlencode({
                's': infos['title'],
                'type': 'movie',
                'r': 'json'
            })
        url = 'http://www.omdbapi.com/?%s' % params

        async with self.aiohttp_session.get(url) as resp:
            resp = json.loads(await resp.text())
            if "Search" in resp:
                for res in resp['Search']:
                    poster = res['Poster'] if res['Poster'] != 'N/A' else ""
                    return Movie(
                        title=res['Title'],
                        imdbid=res['imdbID'],
                        poster=await save_poster(poster, self.loop,
                                                 self.aiohttp_session),
                    )
Exemple #6
0
 def compute_matches(self, video):
     matches = set()
     # episode
     if isinstance(video, Episode):
         # series
         if video.series and self.series.lower() == video.series.lower():
             matches.add('series')
         # season
         if video.season and self.season == video.season:
             matches.add('season')
         # episode
         if video.episode and self.episode == video.episode:
             matches.add('episode')
         # guess
         for release in self.releases:
             matches |= compute_guess_matches(video, guessit.guess_episode_info(release + '.mkv'))
     # movie
     elif isinstance(video, Movie):
         # title
         if video.title and self.title.lower() == video.title.lower():
             matches.add('title')
         # guess
         for release in self.releases:
             matches |= compute_guess_matches(video, guessit.guess_movie_info(release + '.mkv'))
     # year
     if self.year == video.year:
         matches.add('year')
     return matches
def FILEtoIMDB(
    file_name
):  #Added function by nctiggy. This executes if the nzb does not have the IMDB id appended to the name
    #This does capture all of the movies info not just the IMDB id
    #Future can eliminate the calls to IMDB to use this data instead perhaps

    print "CouchPotatoServer did not append the IMDB id to the nzb, guessing instead"
    api_key = "45e408d2851e968e6e4d0353ce621c66"  # You need to get this key from themoviedb.org

    # Guessing at the name of the movie using the filename
    movie_info = guessit.guess_movie_info(file_name)

    #configuring tmdb to use the supplied api key
    tmdb.configure(api_key)
    print "Guessed movie title as: %s" % (movie_info["title"])

    #Creating a collection of movies from tmdb for the guess movie title
    movies = tmdb.Movies(movie_info["title"])

    #parse through all movies found
    for movie in movies.iter_results():
        #Identify the first movie in the collection that matches exactly the movie title
        if movie["title"].lower() == movie_info["title"].lower():
            print "Matched movie title as: %s %s" % (movie["title"],
                                                     movie["release_date"])
            movie = tmdb.Movie(movie["id"])
            break
    #return the imdb id of the movie identified
    return movie.get_imdb_id()[2:]
Exemple #8
0
    def getReleaseNameYear(self, release_name, file_name=None):

        # Use guessit first
        if file_name:
            try:
                guess = guess_movie_info(file_name)
                if guess.get("title") and guess.get("year"):
                    return {"name": guess.get("title"), "year": guess.get("year")}
            except:
                log.debug('Could not detect via guessit "%s": %s' % (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = " ".join(re.split("\W+", simplifyString(release_name)))
        cleaned = re.sub(self.clean, " ", cleaned)
        year = self.findYear(cleaned)

        if year:  # Split name on year
            try:
                movie_name = cleaned.split(year).pop(0).strip()
                return {"name": movie_name, "year": int(year)}
            except:
                pass
        else:  # Split name on multiple spaces
            try:
                movie_name = cleaned.split("  ").pop(0).strip()
                return {"name": movie_name, "year": int(year)}
            except:
                pass

        return {}
Exemple #9
0
    def compute_matches(self, video):
        matches = set()
        # episode
        if isinstance(video, Episode):
            # series
            if video.series and self.series.lower() == video.series.lower():
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            matches |= compute_guess_matches(video, guessit.guess_episode_info(self.release + '.mkv'))
        elif isinstance(video, Movie):
            if video.year and self.year == video.year:
                matches.add('year')

            if video.title and self.movie == video.title:
                matches.add('title')

            # guess
            matches |= compute_guess_matches(video, guessit.guess_movie_info(self.release + '.mkv'))
        else:
            logger.info('%r is not a valid movie_kind for %r', self.movie_kind, video)
            return matches

        if self.subber and "yyets" in self.subber.lower():
            matches.add("yyets")
            
        return matches
Exemple #10
0
 def handle_file(self, parent_folder, item):
     item = self.format_file_name(item)
     file_details = guessit.guess_file_info(item)
     # Force type for strange filenames (Mini-series without seasons, etc.)
     if "episode" in str(item).lower():
         file_details['type'] = 'episode'
     if 'container' in file_details:
         if file_details['type'] == 'movie':
             details = guessit.guess_movie_info(parent_folder+item)
             details.update({
                            'file_dir': "%s/" % parent_folder,
                            'file_name': item
                            })
             file_object_storage.append(Movie(**details))
         elif file_details['type'] == 'episode':
             details = guessit.guess_episode_info(parent_folder+item)
             details.update({
                            'file_dir': "%s/" % parent_folder,
                            'file_name': item
                            })
             if len(file_location_storage) > 0:
                 temp_file_location_storage = file_location_storage.copy()
                 for i in temp_file_location_storage:
                     if i is details['file_dir']:
                         file_location_storage[i].append(
                             details['file_name']
                             )
                     else:
                         file_location_storage[details['file_dir']] = [details['file_name']]
             else:
                 file_location_storage[details['file_dir']] = [details['file_name']]
             file_object_storage.append(Episode(**details))
Exemple #11
0
    def perform(self, query):
        self.checkValid(query)
        media = query.find_one(node_type=Media)

        movieMetadata = guess_movie_info(media.filename)
        movieMetadata = guessitToPygoo(movieMetadata)

        # FIXME: this is a temporary hack waiting for the pygoo and ontology refactoring
        if len(tolist(movieMetadata.get('language', None))) > 1:
            movieMetadata['language'] = movieMetadata['language'][0]

        averageConfidence = sum(
            movieMetadata.confidence(prop)
            for prop in movieMetadata) / len(movieMetadata)

        # put the result of guessit in a form that smewt understands
        movie = query.Movie(confidence=averageConfidence, **movieMetadata)

        msg = u'Found filename information from %s:' % media.filename
        msg += str(movie).decode('utf-8')
        log.debug(msg)

        result = foundMetadata(query, movie)
        #result.display_graph()

        return result
 def compute_matches(self, video):
     matches = set()
     # episode
     if isinstance(video, Episode) and self.movie_kind == "episode":
         # series
         if video.series and self.series_name.lower() == video.series.lower():
             matches.add("series")
         # season
         if video.season and self.series_season == video.season:
             matches.add("season")
         # episode
         if video.episode and self.series_episode == video.episode:
             matches.add("episode")
         # guess
         matches |= compute_guess_matches(video, guessit.guess_episode_info(self.movie_release_name + ".mkv"))
     # movie
     elif isinstance(video, Movie) and self.movie_kind == "movie":
         # year
         if video.year and self.movie_year == video.year:
             matches.add("year")
         # guess
         matches |= compute_guess_matches(video, guessit.guess_movie_info(self.movie_release_name + ".mkv"))
     else:
         logger.info("%r is not a valid movie_kind for %r", self.movie_kind, video)
         return matches
     # hash
     if "opensubtitles" in video.hashes and self.hash == video.hashes["opensubtitles"]:
         matches.add("hash")
     # imdb_id
     if video.imdb_id and self.movie_imdb_id == video.imdb_id:
         matches.add("imdb_id")
     # title
     if video.title and self.movie_name.lower() == video.title.lower():
         matches.add("title")
     return matches
Exemple #13
0
    def make_from_filename(video_filepath):
        """ Returns a Movie or an Episode instance if it is possible,
        else returns a Video instance or None. """
        video = None

        if os.path.exists(video_filepath):
            try:
                video_signature = Video.get_video_signature(video_filepath)

                if video_signature:
                    guess = guessit.guess_movie_info(
                        video_filepath, info=['filename'])
                    if guess['type'] == 'movie':
                        video = Movie(video_filepath)
                    elif guess['type'] == 'episode':
                        video = Episode(video_filepath)
                    else:
                        video = Video(video_filepath)

                    video.signature = video_signature
            except FileMagicError:
                LOG.warning(
                    "This file was not recognized as a video file: {}".format(
                        video_filepath))
        else:
            LOG.error(
                "The following doesn't exists: {}".format(video_filepath))

        return video
def FILEtoIMDB(file_name): #Added function by nctiggy. This executes if the nzb does not have the IMDB id appended to the name
    #This does capture all of the movies info not just the IMDB id
    #Future can eliminate the calls to IMDB to use this data instead perhaps
    
    print "CouchPotatoServer did not append the IMDB id to the nzb, guessing instead"
    api_key = "45e408d2851e968e6e4d0353ce621c66" # You need to get this key from themoviedb.org

    # Guessing at the name of the movie using the filename
    movie_info = guessit.guess_movie_info(file_name)
    
    #configuring tmdb to use the supplied api key
    tmdb.configure(api_key)
    print "Guessed movie title as: %s" % (movie_info["title"])
    
    #Creating a collection of movies from tmdb for the guess movie title
    movies = tmdb.Movies(movie_info["title"])

    #parse through all movies found
    for movie in movies.iter_results():
        #Identify the first movie in the collection that matches exactly the movie title
        if movie["title"].lower() == movie_info["title"].lower():
            print "Matched movie title as: %s %s" % (movie["title"], movie["release_date"])
            movie = tmdb.Movie(movie["id"])
            break
    #return the imdb id of the movie identified
    return movie.get_imdb_id()[2:]
Exemple #15
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(PodnapisiSubtitle, self).get_matches(video, hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and self.title.lower() == video.series.lower():
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guess_episode_info(release + '.mkv'))
        # movie
        elif isinstance(video, Movie):
            # title
            if video.title and self.title.lower() == video.title.lower():
                matches.add('title')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guess_movie_info(release + '.mkv'))
        # year
        if video.year and self.year == video.year:
            matches.add('year')

        return matches
Exemple #16
0
    def perform(self, query):
        self.checkValid(query)
        media = query.find_one(node_type = Media)

        movieMetadata = guess_movie_info(media.filename)
        movieMetadata = guessitToPygoo(movieMetadata)

        # FIXME: this is a temporary hack waiting for the pygoo and ontology refactoring
        if len(tolist(movieMetadata.get('language', None))) > 1:
            movieMetadata['language'] = movieMetadata['language'][0]


        averageConfidence = sum(movieMetadata.confidence(prop) for prop in movieMetadata) / len(movieMetadata)

        # put the result of guessit in a form that smewt understands
        movie = query.Movie(confidence = averageConfidence, **movieMetadata)

        msg = u'Found filename information from %s:' % media.filename
        msg += str(movie).decode('utf-8')
        log.debug(msg)

        result = foundMetadata(query, movie)
        #result.display_graph()

        return result
Exemple #17
0
def FindMovies():
    movies = xdb.table_dump('database.db', 'movies_wanted', 10, 0, 'str_title')
    for movie in movies:
        #search nzb by imdb or title?
        #search kickasstorrents by title, year and category 
        results =  ka.search(urllib.quote('%s %s' % (movie['str_title'], movie['str_year'])), 'movies')
        if results:
            for result in results:
                languages = []
                guess = guessit.guess_movie_info(result['name'])
                #print guess
                if 'videoCodec' in guess:
                    vcodec = guess['videoCodec']
                else:
                    vcodec = 'Unknown'
                if 'audioCodec' in guess:
                    acodec = guess['audioCodec']
                else:
                    acodec = 'Unknown'
                if 'year' in guess:
                    year = guess['year']
                else:
                    year = ''
                if 'title' in guess:
                    title = guess['title']
                else:
                    pass
                if 'screensize' in guess:
                    screensize = guess['sreensize']
                else:
                    screensize = 'Unknown'
                if 'releaseGroup' in guess:
                    rgroup = guess['releaseGroup']
                else:
                    rgroup = ''
                if 'format' in guess:
                    format = guess['format']
                else:
                    format = ''
                if 'other' in guess:
                    other = ", ".join(guess['other'])
                else:
                    other = ''
                if 'size' in result:
                    size = result['size']
                else:
                    size = ''
                if 'language' in guess:
                    for each in guess['language']:
                        languages.append(each.english_name)
                    language = ", ".join(languages)
                else:
                    language = 'Unknown'
                if 'container' in guess:
                    container = guess['container']
                else:
                    container = 'Unknown'
                print title, year, format, screensize, language,  rgroup, vcodec, acodec, container, size
        else: 
            print 'No results for %s movie' % movie['str_title']
    def compare(self, element=None, download=None, string=None):
        guess = guessit.guess_movie_info(download.name, info=['filename'])
        self.e.getConfigsFor(element) #this will load all the elements configs
        # into the the self.e cache
        # needed for .<config_name_access>

        finalReason = []
        for attribute in ('format_select', 'screenSize_select', 'audioCodec_select'):
            attributeGuessName = attribute[:-7] # remove that _select
            attributeElementConfigValue = self.e.getConfig(attribute, element).value
            if attributeElementConfigValue == 'any': # current is any so we accept anything !
                finalReason.append('%s can be anything' % attributeGuessName)
                continue
            # attribute not set in guessit and current setting is not any (see above)
            # so we cant say we wan this one
            if attributeGuessName not in guess:
                return self.FilterResult(False, 'needed %s not in guess' % attributeGuessName)

            if guess[attributeGuessName] == attributeElementConfigValue:
                if self.e.any_all_select == 'any':
                    return self.FilterResult(True, '%s is correct with %s and we only needed one to be correct.' % (attributeGuessName, attributeElementConfigValue))
                else:
                    finalReason.append('%s is correct with %s' % (attributeGuessName, attributeElementConfigValue))
            elif self.e.any_all_select == 'any':
                finalReason.append('%s can be anything and it was %s' % (attributeGuessName, guess[attributeGuessName]))
                continue # lets try the next one
            elif self.e.any_all_select == 'all':
                return self.FilterResult(False, '%s is %s but we want %s and we only needed one to be correct.' % (attributeGuessName, guess[attributeGuessName], attributeElementConfigValue))
        else: # all cool
            return self.FilterResult(True, 'Everything looked great %s.' % ', '.join(finalReason))
Exemple #19
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(SubsCenterSubtitle, self).get_matches(video, hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and sanitized_string_equal(self.series, video.series):
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guess_episode_info(release + '.mkv'))
        # movie
        elif isinstance(video, Movie):
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guess_movie_info(release + '.mkv'))

        # title
        if video.title and sanitized_string_equal(self.title, video.title):
            matches.add('title')

        return matches
 def compute_matches(self, video):
     matches = set()
     # episode
     if isinstance(video, Episode) and self.movie_kind == 'episode':
         # series
         if video.series and self.series_name.lower() == video.series.lower():
             matches.add('series')
         # season
         if video.season and self.series_season == video.season:
             matches.add('season')
         # episode
         if video.episode and self.series_episode == video.episode:
             matches.add('episode')
         # guess
         matches |= compute_guess_matches(video, guessit.guess_episode_info(self.movie_release_name + '.mkv'))
     # movie
     elif isinstance(video, Movie) and self.movie_kind == 'movie':
         # year
         if video.year and self.movie_year == video.year:
             matches.add('year')
         # guess
         matches |= compute_guess_matches(video, guessit.guess_movie_info(self.movie_release_name + '.mkv'))
     else:
         logger.info('%r is not a valid movie_kind for %r', self.movie_kind, video)
         return matches
     # hash
     if 'opensubtitles' in video.hashes and self.hash == video.hashes['opensubtitles']:
         matches.add('hash')
     # imdb_id
     if video.imdb_id and self.movie_imdb_id == video.imdb_id:
         matches.add('imdb_id')
     # title
     if video.title and self.movie_name.lower() == video.title.lower():
         matches.add('title')
     return matches
Exemple #21
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(SubsCenterSubtitle,
                        self).get_matches(video,
                                          hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode):
            # series
            if video.series and sanitized_string_equal(self.series,
                                                       video.series):
                matches.add('series')
            # season
            if video.season and self.season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.episode == video.episode:
                matches.add('episode')
            # guess
            for release in self.releases:
                matches |= guess_matches(video,
                                         guess_episode_info(release + '.mkv'))
        # movie
        elif isinstance(video, Movie):
            # guess
            for release in self.releases:
                matches |= guess_matches(video,
                                         guess_movie_info(release + '.mkv'))

        # title
        if video.title and sanitized_string_equal(self.title, video.title):
            matches.add('title')

        return matches
Exemple #22
0
    def getReleaseNameYear(self, release_name, file_name=None):

        release_name = release_name.strip(' .-_')

        # Use guessit first
        guess = {}
        if file_name:
            try:
                guessit = guess_movie_info(toUnicode(file_name))
                if guessit.get('title') and guessit.get('year'):
                    guess = {
                        'name': guessit.get('title'),
                        'year': guessit.get('year'),
                    }
            except:
                log.debug('Could not detect via guessit "%s": %s',
                          (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
        cleaned = re.sub(self.clean, ' ', cleaned)

        year = None
        for year_str in [file_name, release_name, cleaned]:
            if not year_str: continue
            year = self.findYear(year_str)
            if year:
                break

        cp_guess = {}

        if year:  # Split name on year
            try:
                movie_name = cleaned.rsplit(year, 1).pop(0).strip()
                if movie_name:
                    cp_guess = {
                        'name': movie_name,
                        'year': int(year),
                    }
            except:
                pass

        if not cp_guess:  # Split name on multiple spaces
            try:
                movie_name = cleaned.split('  ').pop(0).strip()
                cp_guess = {
                    'name': movie_name,
                    'year': int(year) if movie_name[:4] != year else 0,
                }
            except:
                pass

        if cp_guess.get('year') == guess.get('year') and len(
                cp_guess.get('name', '')) > len(guess.get('name', '')):
            return cp_guess
        elif guess == {}:
            return cp_guess

        return guess
Exemple #23
0
def getReleaseNameYear(release_name, file_name=None):

    # Use guessit first
    guess = {}
    if release_name:
        release_name = re.sub(clean, ' ', release_name.lower())
        try:
            guess = guess_movie_info(toUnicode(release_name))
            if guess.get('title') and guess.get('year'):
                guess = {
                    'name': guess.get('title'),
                    'year': guess.get('year'),
                }
            elif guess.get('title'):
                guess = {
                    'name': guess.get('title'),
                    'year': 0,
                }
        except:
            log.debug('Could not detect via guessit "%s": %s',
                      (file_name, traceback.format_exc()))

    # Backup to simple
    cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
    for i in range(1, 4):
        cleaned = re.sub(clean, ' ', cleaned)
        cleaned = re.sub(clean, ' ', cleaned)
    year = findYear(cleaned)
    cp_guess = {}

    if year:  # Split name on year
        try:
            movie_name = cleaned.split(year).pop(0).strip()
            cp_guess = {
                'name': movie_name,
                'year': int(year),
            }
        except:
            pass
    else:  # Split name on multiple spaces
        try:
            movie_name = cleaned.split('  ').pop(0).strip()
            cp_guess = {
                'name': movie_name,
                'year': 0,
            }
        except:
            pass

    if cp_guess.get('year') == guess.get('year') and len(
            cp_guess.get('name', '')) > len(guess.get('name', '')):
        return guess
    elif guess == {}:
        return cp_guess
    if cp_guess.get('year') == guess.get('year') and len(
            cp_guess.get('name', '')) < len(guess.get('name', '')):
        return cp_guess
    return guess
Exemple #24
0
    def getReleaseNameYear(self, release_name, file_name = None):

        release_name = release_name.strip(' .-_')

        # Use guessit first
        guess = {}
        if file_name:
            try:
                guessit = guess_movie_info(toUnicode(file_name))
                if guessit.get('title') and guessit.get('year'):
                    guess = {
                        'name': guessit.get('title'),
                        'year': guessit.get('year'),
                    }
            except:
                log.debug('Could not detect via guessit "%s": %s', (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
        cleaned = re.sub(self.clean, ' ', cleaned)

        year = None
        for year_str in [file_name, release_name, cleaned]:
            if not year_str: continue
            year = self.findYear(year_str)
            if year:
                break

        cp_guess = {}

        if year: # Split name on year
            try:
                movie_name = cleaned.rsplit(year, 1).pop(0).strip()
                if movie_name:
                    cp_guess = {
                        'name': movie_name,
                        'year': int(year),
                    }
            except:
                pass

        if not cp_guess:  # Split name on multiple spaces
            try:
                movie_name = cleaned.split('  ').pop(0).strip()
                cp_guess = {
                    'name': movie_name,
                    'year': int(year) if movie_name[:4] != year else 0,
                }
            except:
                pass

        if cp_guess.get('year') == guess.get('year') and len(cp_guess.get('name', '')) > len(guess.get('name', '')):
            return cp_guess
        elif guess == {}:
            return cp_guess

        return guess
Exemple #25
0
def guessMovieDetails(path):
	rVal = []
	guess = guessit.guess_movie_info(path,info=['filename'])
	if 'title' in guess:
		rVal.append(guess['title'])
		if 'year' in guess:
			rVal.append(guess['year'])

	return rVal
Exemple #26
0
 async def resolve(self, path, movie):
     if movie.title:
         return movie
     #Report.fail += 1
     name, ext = os.path.splitext(os.path.basename(path))
     infos = guess_movie_info(name)
     if infos.get('title'):
         return Movie(title=infos['title'])
     else:
         return Movie(title=name)
Exemple #27
0
 async def resolve(self, path, movie):
     if movie.title:
         return movie
     #Report.fail += 1
     name, ext = os.path.splitext(os.path.basename(path))
     infos = guess_movie_info(name)
     if infos.get('title'):
         return Movie(title=infos['title'])
     else:
         return Movie(title=name)
def getReleaseNameYear(release_name, file_name = None):

        # Use guessit first
        guess = {}
        if release_name:
            release_name = re.sub(clean, ' ', release_name.lower())
            try:
                guess = guess_movie_info(toUnicode(release_name))
                if guess.get('title') and guess.get('year'):
                    guess = {
                        'name': guess.get('title'),
                        'year': guess.get('year'),
                    }
                elif guess.get('title'):
                    guess = {
                        'name': guess.get('title'),
                        'year': 0,
                    }
            except:
                log.debug('Could not detect via guessit "%s": %s', (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
        for i in range(1,4):
            cleaned = re.sub(clean, ' ', cleaned)
            cleaned = re.sub(clean, ' ', cleaned)
        year = findYear(cleaned)
        cp_guess = {}

        if year: # Split name on year
            try:
                movie_name = cleaned.split(year).pop(0).strip()
                cp_guess = {
                    'name': movie_name,
                    'year': int(year),
                }
            except:
                pass
        else: # Split name on multiple spaces
            try:
                movie_name = cleaned.split('  ').pop(0).strip()
                cp_guess = {
                    'name': movie_name,
                    'year': 0,
                }
            except:
                pass

        if cp_guess.get('year') == guess.get('year') and len(cp_guess.get('name', '')) > len(guess.get('name', '')):
            return guess
        elif guess == {}:
            return cp_guess
        if cp_guess.get('year') == guess.get('year') and len(cp_guess.get('name', '')) < len(guess.get('name', '')):
            return cp_guess
        return guess
Exemple #29
0
 def infer_metadata_from_movie_file(self, path_to_file):
     guess = guessit.guess_movie_info(path_to_file, info=['filename'])
     if guess is None or len(guess) == 0:
         self.log("[Warning] Failed to guess movie metadata")
         return None
     return Helper._extract_metadata_from_guessit_dict(
         guess,
         mappings={
             "title": Helper.Keys.MovieTitle,
             "year": Helper.Keys.MovieYear
         })
    def _guess(self, feed_item):
        guess = guessit.guess_movie_info(feed_item.title)

        try:
            feed_item.title_parsed = title if not 'title' in guess else guess[
                'title']
            feed_item.year = None if not 'year' in guess else guess['year']
            self.logger.debug('Guessed "%s" from %s.' %
                              (feed_item.title_canonical, feed_item.title))
        except Exception:
            self.logger.error(guess)
            raise
    def getReleaseNameYear(self, release_name, file_name=None):

        release_name = release_name.strip(" .-_")

        # Use guessit first
        guess = {}
        if file_name:
            try:
                guessit = guess_movie_info(toUnicode(file_name))
                if guessit.get("title") and guessit.get("year"):
                    guess = {"name": guessit.get("title"), "year": guessit.get("year")}
            except:
                log.debug('Could not detect via guessit "%s": %s', (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = " ".join(re.split("\W+", simplifyString(release_name)))
        cleaned = re.sub(self.clean, " ", cleaned)

        year = None
        for year_str in [file_name, release_name, cleaned]:
            if not year_str:
                continue
            year = self.findYear(year_str)
            if year:
                break

        cp_guess = {}

        if year:  # Split name on year
            try:
                movie_name = cleaned.rsplit(year, 1).pop(0).strip()
                if movie_name:
                    cp_guess = {"name": movie_name, "year": int(year)}
            except:
                pass

        if not cp_guess:  # Split name on multiple spaces
            try:
                movie_name = cleaned.split("  ").pop(0).strip()
                cp_guess = {"name": movie_name, "year": int(year) if movie_name[:4] != year else 0}
            except:
                pass

        if cp_guess.get("year") == guess.get("year") and len(cp_guess.get("name", "")) > len(guess.get("name", "")):
            return cp_guess
        elif guess == {}:
            return cp_guess

        return guess
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle,
                        self).get_matches(video,
                                          hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode) and self.movie_kind == 'episode':
            # series
            if video.series and sanitized_string_equal(self.series_name,
                                                       video.series):
                matches.add('series')
            # season
            if video.season and self.series_season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.series_episode == video.episode:
                matches.add('episode')
            # title
            if video.title and sanitized_string_equal(self.series_title,
                                                      video.title):
                matches.add('title')
            # guess
            matches |= guess_matches(
                video, guess_episode_info(self.movie_release_name + '.mkv'))
        # movie
        elif isinstance(video, Movie) and self.movie_kind == 'movie':
            # title
            if video.title and sanitized_string_equal(self.movie_name,
                                                      video.title):
                matches.add('title')
            # year
            if video.year and self.movie_year == video.year:
                matches.add('year')
            # guess
            matches |= guess_matches(
                video, guess_movie_info(self.movie_release_name + '.mkv'))
        else:
            logger.info('%r is not a valid movie_kind', self.movie_kind)
            return matches

        # hash
        if 'opensubtitles' in video.hashes and self.hash == video.hashes[
                'opensubtitles']:
            matches.add('hash')
        # imdb_id
        if video.imdb_id and self.movie_imdb_id == video.imdb_id:
            matches.add('imdb_id')

        return matches
Exemple #33
0
def find_imdbid(dirName, inputName):
    imdbid = None

    logger.info('Attemping imdbID lookup for %s' % (inputName))

    # find imdbid in dirName
    logger.info('Searching folder and file names for imdbID ...')
    m = re.search('(tt\d{7})', dirName + inputName)
    if m:
        imdbid = m.group(1)
        logger.info("Found imdbID [%s]" % imdbid)
        return imdbid

    logger.info('Searching IMDB for imdbID ...')
    guess = guessit.guess_movie_info(inputName)
    if guess:
        # Movie Title
        title = None
        if 'title' in guess:
            title = guess['title']

        # Movie Year
        year = None
        if 'year' in guess:
            year = guess['year']

        url = "http://www.omdbapi.com"

        logger.debug("Opening URL: %s" % url)

        try:
            r = requests.get(url, params={'y': year, 't': title}, verify=False)
        except requests.ConnectionError:
            logger.error("Unable to open URL %s" % url)
            return

        results = r.json()

        try:
            imdbid = results['imdbID']
        except:
            pass

        if imdbid:
            logger.info("Found imdbID [%s]" % imdbid)
            return imdbid

    logger.warning('Unable to find a imdbID for %s' % (inputName))
def find_imdbid(dirName, inputName):
    imdbid = None

    logger.info('Attemping imdbID lookup for %s' % (inputName))

    # find imdbid in dirName
    logger.info('Searching folder and file names for imdbID ...')
    m = re.search('(tt\d{7})', dirName+inputName)
    if m:
        imdbid = m.group(1)
        logger.info("Found imdbID [%s]" % imdbid)
        return imdbid

    logger.info('Searching IMDB for imdbID ...')
    guess = guessit.guess_movie_info(inputName)
    if guess:
        # Movie Title
        title = None
        if 'title' in guess:
            title = guess['title']

        # Movie Year
        year = None
        if 'year' in guess:
            year = guess['year']

        url = "http://www.omdbapi.com"

        logger.debug("Opening URL: %s" % url)

        try:
            r = requests.get(url, params={'y': year, 't': title}, verify=False)
        except requests.ConnectionError:
            logger.error("Unable to open URL %s" % url)
            return

        results = r.json()

        try:
            imdbid = results['imdbID']
        except:
            pass

        if imdbid:
            logger.info("Found imdbID [%s]" % imdbid)
            return imdbid

    logger.warning('Unable to find a imdbID for %s' % (inputName))
Exemple #35
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(MakeDieSubtitle, self).get_matches(video, hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode):
            # guess
            for release in self.releases:
                matches |= guess_matches(video, guess_episode_info(release + ".mkv"))

        # movie
        elif isinstance(video, Movie):
            for release in self.releases:
                matches |= guess_matches(video, guess_movie_info(release + ".mkv"))

        # Other mesaurements
        #   * upload_date
        #   * downloads
        # not included in subliminal, but use its score
        # hearing_impaired (1) -> audio_codec (2) -> video_codec (4)
        try:
            if self.upload_date and video.year:
                from datetime import datetime, date

                format = "%Y-%m-%d %H:%M:%S"
                d0 = datetime.strptime(str(video.year) + "-01-01 00:00:00", format)
                d1 = datetime.strptime(self.upload_date, format)
                level = (d1 - d0).days // 100
                if level == 1:
                    matches.add("hearing_impaired")
                elif level == 2:
                    matches.add("audio_codec")
                else:
                    matches.add("video_codec")

            # self defined scores, plus one (use audio_codec to mark)
            if self.downloads:
                level = int(self.downloads) // 1000
                if level == 1:
                    matches.add("hearing_impaired")
                elif level == 2:
                    matches.add("audio_codec")
                else:
                    matches.add("video_codec")
        except:
            logger.info("Wrong data fetched from makedie")

        return matches
Exemple #36
0
def getDirectoryDetails(newroot):
	# remove unecessary puntuation from filenames
	newroot = re.sub('[.,;-]', ' ', newroot)
	# run guessit parser to try and get the movie title and the year
	guess = guessit.guess_movie_info(newroot, info=['filename'])
	title = guess.get('title')
	year = guess.get('year')
	# a lot of movies have 'the' appeneded instead of at the start of the string title
	# e.g. Fifth Estate The
	# strip 'the' off the back and add to the fron so we get:
	# e.g. The Fifth Estate
	suffix = ['the','The']
        for s in suffix:
	    if str(title).endswith(s):
		title = title[:-3]
		title = 'The ' + title
	return title, year
Exemple #37
0
def getDirectoryDetails(newroot):
    # remove unecessary puntuation from filenames
    newroot = re.sub('[.,;-]', ' ', newroot)
    # run guessit parser to try and get the movie title and the year
    guess = guessit.guess_movie_info(newroot, info=['filename'])
    title = guess.get('title')
    year = guess.get('year')
    # a lot of movies have 'the' appeneded instead of at the start of the string title
    # e.g. Fifth Estate The
    # strip 'the' off the back and add to the fron so we get:
    # e.g. The Fifth Estate
    suffix = ['the', 'The']
    for s in suffix:
        if str(title).endswith(s):
            title = title[:-3]
            title = 'The ' + title
    return title, year
Exemple #38
0
    def compare(self, element=None, download=None, string=None):
        guess = guessit.guess_movie_info(download.name, info=['filename'])
        self.e.getConfigsFor(element)  #this will load all the elements configs
        # into the the self.e cache
        # needed for .<config_name_access>

        finalReason = []
        for attribute in ('format_select', 'screenSize_select',
                          'audioCodec_select'):
            attributeGuessName = attribute[:-7]  # remove that _select
            attributeElementConfigValue = self.e.getConfig(attribute,
                                                           element).value
            if attributeElementConfigValue == 'any':  # current is any so we accept anything !
                finalReason.append('%s can be anything' % attributeGuessName)
                continue
            # attribute not set in guessit and current setting is not any (see above)
            # so we cant say we wan this one
            if attributeGuessName not in guess:
                return self.FilterResult(
                    False, 'needed %s not in guess' % attributeGuessName)

            if guess[attributeGuessName] == attributeElementConfigValue:
                if self.e.any_all_select == 'any':
                    return self.FilterResult(
                        True,
                        '%s is correct with %s and we only needed one to be correct.'
                        % (attributeGuessName, attributeElementConfigValue))
                else:
                    finalReason.append(
                        '%s is correct with %s' %
                        (attributeGuessName, attributeElementConfigValue))
            elif self.e.any_all_select == 'any':
                finalReason.append(
                    '%s can be anything and it was %s' %
                    (attributeGuessName, guess[attributeGuessName]))
                continue  # lets try the next one
            elif self.e.any_all_select == 'all':
                return self.FilterResult(
                    False,
                    '%s is %s but we want %s and we only needed one to be correct.'
                    % (attributeGuessName, guess[attributeGuessName],
                       attributeElementConfigValue))
        else:  # all cool
            return self.FilterResult(
                True, 'Everything looked great %s.' % ', '.join(finalReason))
Exemple #39
0
def classify():
    if request.content_type == "application/json":
        form = ClassifyForm(data=request.get_json(force=True))
    else:
        form = ClassifyForm(request.form)
    if form.validate():
        release_name = form.release_name.data
        options = {"name_only": True}
        if form.media_type.data == "unknown":
            data = guessit.guess_file_info(release_name, options=options)
        elif form.media_type.data == "tv":
            data = guessit.guess_episode_info(release_name, options=options)
        else:
            data = guessit.guess_movie_info(release_name, options=options)
        try:
            jsonify()
            return json.dumps(data, default=json_serial)
        except Exception as err:
            return json.dumps({"err": str(err)}, default=json_serial)
Exemple #40
0
def main():
    fp = open(argv[1])
    for line in fp:
        name = line.strip()
        guess = guessit.guess_movie_info(name, info = ['filename'])
        #print guess.nice_string()
        while True:
            if path.isdir(name) == True:
                new_name = guess["title"]
            else:
                extension = name.split(".")[-1]
                new_name = "{0}.{1}".format(guess["title"], extension)

            ans = raw_input("Do you want me to rename '{0}' to '{1}'? (y/n) ".format(name, new_name))
            if ans == "y":
                rename(name, new_name)
            elif ans == "n":
                break
    fp.close()
Exemple #41
0
def classify():
    if request.content_type == "application/json":
        form = ClassifyForm(data=request.get_json(force=True))
    else:
        form = ClassifyForm(request.form)
    if form.validate():
        release_name = form.release_name.data
        options = {'name_only': True}
        if form.media_type.data == "unknown":
            data = guessit.guess_file_info(release_name, options=options)
        elif form.media_type.data == "tv":
            data = guessit.guess_episode_info(release_name, options=options)
        else:
            data = guessit.guess_movie_info(release_name, options=options)
        try:
            jsonify()
            return json.dumps(data, default=json_serial)
        except Exception as err:
            return json.dumps({"err": str(err)}, default=json_serial)
Exemple #42
0
 def process(self, directory, fakedir=False):
     self.reset_infos()
     if fakedir:
         self.directory = directory
     else:
         self.directory = os.path.abspath(directory).replace(
             settings.FTP_ROOT, '', 1)
     existing = Directory.objects.filter(location=self.directory).exists()
     if existing:
         print 'Directory is already present in the database'
         return False
     dir = self.__reg_dir.match(self.directory).group(2) + '/'
     guess = guessit.guess_movie_info(dir.decode('utf-8'))
     if not ('title' and 'year') in guess:
         print 'Error while processing ' + self.directory
         return False
     search_string = 'site:imdb.com %s %s' % (
             guess['title'], str(guess['year']))
     r = requests.get(
             'http://www.bing.com/search', params={'q': search_string})
     match = self.__reg_bing.search(r.content)
     if not match:
         print r.url
         print "Bing wasn't able to find this movie, skipping"
         return False
     self.id_imdb = match.group('id')
     self.title = guess['title']
     self.year = guess['year']
     if 'screenSize' in guess:
         self.quality = guess['screenSize']
     else:
         self.quality = 'SD'
     #Size of the directory in Mo
     #TODO understand why the result is different from du
     #TODO make it actually work :S
     if fakedir:
         self.size = 0
     else:
         #self.size = (get_size(directory) + 500000) // 1000000
         self.size = 0
     self.save()
     return True
Exemple #43
0
    async def search(self, name):
        infos = guess_movie_info(name)
        if not infos.get('title'):
            return
        try:
            params = urlencode({'s': infos['title'], 'y': infos['year'], 'type': 'movie', 'r': 'json'})
        except KeyError:
            params = urlencode({'s': infos['title'], 'type': 'movie', 'r': 'json'})
        url = 'http://www.omdbapi.com/?%s' % params

        async with self.aiohttp_session.get(url) as resp:
            resp = json.loads(await resp.text())
            if "Search" in resp:
                for res in resp['Search']:
                    poster = res['Poster'] if res['Poster'] != 'N/A' else ""
                    return Movie(
                        title=res['Title'],
                        imdbid=res['imdbID'],
                        poster=await save_poster(poster, self.loop, self.aiohttp_session),
                    )
Exemple #44
0
    def get_matches(self, video, hearing_impaired=False):
        matches = super(OpenSubtitlesSubtitle, self).get_matches(video, hearing_impaired=hearing_impaired)

        # episode
        if isinstance(video, Episode) and self.movie_kind == 'episode':
            # series
            if video.series and self.series_name.lower() == video.series.lower():
                matches.add('series')
            # season
            if video.season and self.series_season == video.season:
                matches.add('season')
            # episode
            if video.episode and self.series_episode == video.episode:
                matches.add('episode')
            # title
            if video.title and self.series_title.lower() == video.title.lower():
                matches.add('title')
            # guess
            matches |= guess_matches(video, guess_episode_info(self.movie_release_name + '.mkv'))
        # movie
        elif isinstance(video, Movie) and self.movie_kind == 'movie':
            # title
            if video.title and self.movie_name.lower() == video.title.lower():
                matches.add('title')
            # year
            if video.year and self.movie_year == video.year:
                matches.add('year')
            # guess
            matches |= guess_matches(video, guess_movie_info(self.movie_release_name + '.mkv'))
        else:
            logger.info('%r is not a valid movie_kind', self.movie_kind)
            return matches

        # hash
        if 'opensubtitles' in video.hashes and self.hash == video.hashes['opensubtitles']:
            matches.add('hash')
        # imdb_id
        if video.imdb_id and self.movie_imdb_id == video.imdb_id:
            matches.add('imdb_id')

        return matches
Exemple #45
0
 def force(self, directory, id_imdb, fakedir=False):
     self.reset_infos()
     if fakedir:
         self.directory = directory
     else:
         self.directory = os.path.abspath(directory).replace(
             settings.FTP_ROOT, '', 1)
     dir = self.__reg_dir.match(self.directory).group(2) + '/'
     guess = guessit.guess_movie_info(dir.decode('utf-8'))
     if 'screenSize' in guess:
         self.quality = guess['screenSize']
     else:
         self.quality = 'SD'
     m = self.movie.process(id_imdb)
     self.size = 0
     try:
         existing = Directory.objects.get(location=self.directory)
         existing.movie = m
     except ObjectDoesNotExist:
         Directory.objects.create(
                 movie=m, location=self.directory,
                 quality=self.quality, size=self.size)
Exemple #46
0
    def getReleaseNameYear(self, release_name, file_name = None):

        # Use guessit first
        if file_name:
            try:
                guess = guess_movie_info(file_name)
                if guess.get('title') and guess.get('year'):
                    return {
                        'name': guess.get('title'),
                        'year': guess.get('year'),
                    }
            except:
                log.debug('Could not detect via guessit "%s": %s' % (file_name, traceback.format_exc()))

        # Backup to simple
        cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
        cleaned = re.sub(self.clean, ' ', cleaned)
        year = self.findYear(cleaned)

        if year: # Split name on year
            try:
                movie_name = cleaned.split(year).pop(0).strip()
                return {
                    'name': movie_name,
                    'year': int(year),
                }
            except:
                pass
        else: # Split name on multiple spaces
            try:
                movie_name = cleaned.split('  ').pop(0).strip()
                return {
                    'name': movie_name,
                    'year': int(year),
                }
            except:
                pass

        return {}
Exemple #47
0
    def fill_with_absolute_file_path(self, absolute_file_path: str) -> None:
        info = guessit.guess_movie_info(absolute_file_path)
        # print(info)

        if MovieGuessedInfo.TITLE in info:
            self.__title = info[MovieGuessedInfo.TITLE]
        if MovieGuessedInfo.YEAR in info:
            self.__year = str(info[MovieGuessedInfo.YEAR])
        if MovieGuessedInfo.COUNTRY in info:
            self.__country = info[MovieGuessedInfo.COUNTRY][0]
        if MovieGuessedInfo.LANGUAGE in info:
            self.__language = info[MovieGuessedInfo.LANGUAGE][0].alpha2
        if MovieGuessedInfo.SUBTITLE_LANGUAGE in info:
            self.__subtitle_language = info[
                MovieGuessedInfo.SUBTITLE_LANGUAGE][0]
        if MovieGuessedInfo.BONUS_TITLE in info:
            self.__bonus_title = info[MovieGuessedInfo.BONUS_TITLE]
        if MovieGuessedInfo.CD_NUMBER in info:
            self.__cd_number = str(info[MovieGuessedInfo.CD_NUMBER])
        if MovieGuessedInfo.CD_NUMBER_TOTAL in info:
            self.__cd_number_total = str(
                info[MovieGuessedInfo.CD_NUMBER_TOTAL])
        if MovieGuessedInfo.EDITION in info:
            self.__edition = info[MovieGuessedInfo.EDITION]
nzb_tmdbid = 0
nzb_tmdbtitle = ''
radarr_id = 0
radarr_title = ''

if radarr_ssl == 1:
    proto = 'https'
else:
    proto = 'http'

radarr_url = proto + "://" + radarr_host + ":" + radarr_port + "/" + radarr_webroot
print("Radarr URL: %s" % radarr_url)

#os.environ['NZBPP_NZBFILENAME'] = "Captain.Marvel.2019.720p.BluRay.x264.IMAX-WHALES.nzb"
guess = guessit.guess_movie_info(os.environ['NZBNA_FILENAME'])
print(guess.nice_string())
try:
    if guess['type'] == 'movie':
        nzb_tmdbid, nzb_tmdbtitle = tmdbInfo(guess)
        print("TMDB id from NZB: %s" % nzb_tmdbid)
except Exception as e:
    print("Could not find a TMDB match")
    sys.exit(NZBGET_POSTPROCESS_NONE)

just_watch = JustWatch(country='US')

try:
    movies = just_watch.search_for_item(query=nzb_tmdbtitle)
except Exception as e:
    print("Could not determine Streaming Services")
 def fromname(cls, name):
     return cls.fromguess(
         os.path.split(name)[1], guessit.guess_movie_info(name))
Exemple #50
0



from guessit import guess_file_info
os.chdir("D:\Program Files\ApexDC++\Downloads\Movies\Temp Movies")
raw_movies=[]
for file in glob.glob("*.*"):
    raw_movies.append(file)


movie_names=[]
movie_names_set=set()
for x in raw_movies:
    path = x
    guess = guessit.guess_movie_info(path, info=['filename'])
    name=guess.get('title')
    if name not in movie_names_set:
        movie_names.append(name)
        movie_names_set.add(name)



all_movies=[]
for n in movie_names:
    print (n)
    make_movie_object(n)

    

    status = 1

if os.environ['NZBPP_CATEGORY'] != 'Movies':
    print("This is only valid for Movies.")
    status = 1

# All checks done, now launching the script.
if status == 1:
    sys.exit(NZBGET_POSTPROCESS_NONE)

nzb_tmdbid = 0
nzb_title = ''
radarr_id = 0
radarr_title = ''
# Get the TMDBID of the movie
guess = guessit.guess_movie_info(os.environ['NZBPP_NZBFILENAME'])
print guess.nice_string()
try:
    if guess['type'] == 'movie':
        nzb_tmdbid, nzb_tmdbtitle = tmdbInfo(guess)
        print("TMDB id from NZB: %s" % nzb_tmdbid)
except Exception as e:
    print(e)

radarrSession = requests.Session()
radarrSession.trust_env = False
#print("%s/api/movie?apikey=%s" % (radarr_url, radarr_key))
radarrMovies = radarrSession.get('{0}/api/movie?apikey={1}'.format(
    radarr_url, radarr_key))
if radarrMovies.status_code != 200:
    print('Radarr server error - response %s' % radarrMovies.status_code)
Exemple #52
0
 def fromname(cls, name):
     return cls.fromguess(name, guess_movie_info(name))
Exemple #53
0
def find_imdbid(dirName, inputName):
    imdbid = None

    logger.info('Attemping imdbID lookup for %s' % (inputName))

    # find imdbid in dirName
    logger.info('Searching folder and file names for imdbID ...')
    m = re.search('(tt\d{7})', dirName + inputName)
    if m:
        imdbid = m.group(1)
        logger.info("Found imdbID [%s]" % imdbid)
        return imdbid
    if os.path.isdir(dirName):
        for file in os.listdir(dirName):
            m = re.search('(tt\d{7})', file)
            if m:
                imdbid = m.group(1)
                logger.info("Found imdbID [%s] via file name" % imdbid)
                return imdbid
    if os.environ.has_key('NZBPR__DNZB_MOREINFO'):
        dnzb_more_info = os.environ.get('NZBPR__DNZB_MOREINFO', '')
        if dnzb_more_info != '':
            regex = re.compile(r'^http://www.imdb.com/title/(tt[0-9]+)/$',
                               re.IGNORECASE)
            m = regex.match(dnzb_more_info)
            if m:
                imdbid = m.group(1)
                logger.info("Found imdbID [%s] from DNZB-MoreInfo" % imdbid)
                return imdbid
    logger.info('Searching IMDB for imdbID ...')
    guess = guessit.guess_movie_info(inputName)
    if guess:
        # Movie Title
        title = None
        if 'title' in guess:
            title = guess['title']

        # Movie Year
        year = None
        if 'year' in guess:
            year = guess['year']

        url = "http://www.omdbapi.com"

        logger.debug("Opening URL: %s" % url)

        try:
            r = requests.get(url,
                             params={
                                 'y': year,
                                 't': title
                             },
                             verify=False,
                             timeout=(60, 300))
        except requests.ConnectionError:
            logger.error("Unable to open URL %s" % url)
            return

        results = r.json()

        try:
            imdbid = results['imdbID']
        except:
            pass

        if imdbid:
            logger.info("Found imdbID [%s]" % imdbid)
            return imdbid

    logger.warning('Unable to find a imdbID for %s' % (inputName))
    return imdbid