Exemplo n.º 1
0
def getMetadataAtoms(part, metadata, type, episode=None):
  filename = part.file.decode('utf-8')
  file = os.path.basename(filename)
  
  (file, ext) = os.path.splitext(file)
  if ext.lower() in ['.mp4', '.m4v', '.mov']:
    mp4fileTags = mp4file.Mp4File(filename)
    
    try: metadata.posters['atom_coverart'] = Proxy.Media(find_data(mp4fileTags, 'moov/udta/meta/ilst/coverart'))
    except: pass
    try:
      title = find_data(mp4fileTags, 'moov/udta/meta/ilst/title') #Name
      if type == 'Movie': metadata.title = title
      else: episode.title = title
    except:
      pass
      
    try:
      try:
        summary = find_data(mp4fileTags, 'moov/udta/meta/ilst/ldes') #long description
      except:
        summary = find_data(mp4fileTags, 'moov/udta/meta/ilst/desc') #short description
        
      if type == 'Movie': metadata.summary = summary
      else: episode.summary = summary
    except:
      pass

    if type == 'Movie':
      try: 
        genres = find_data(mp4fileTags, 'moov/udta/meta/ilst/genre') #genre
        if len(genres) > 0:
          genList = genres.split(',')
          metadata.genres.clear()
          for g in genList:
            metadata.genres.add(g.strip())
      except: 
        pass
      try: 
        artists = find_data(mp4fileTags, 'moov/udta/meta/ilst/artist') #artist
        if len(artists) > 0:
          artList = artists.split(',')
          metadata.roles.clear()
          for a in artList:
            role = metadata.roles.new()
            role.actor = a.strip()
      except: 
        pass
      try:
        releaseDate = find_data(mp4fileTags, 'moov/udta/meta/ilst/year')
        releaseDate = releaseDate.split('T')[0]
        parsedDate = Datetime.ParseDate(releaseDate)
        
        metadata.year = parsedDate.year
        metadata.originally_available_at = parsedDate.date() #release date
      except: 
        pass
Exemplo n.º 2
0
 def update(self, metadata, media, lang):
   valid_posters = []
   for t in media.tracks:
     for i in media.tracks[t].items:
       for p in i.parts:
         filename = p.file.decode('utf-8')
         path = os.path.dirname(filename)
         (fileroot, fext) = os.path.splitext(filename)
         pathFiles = {}
         for pth in os.listdir(path):
           pathFiles[pth.lower()] = pth
         # Add the filename as a base, and the dirname as a base for poster lookups
         passFiles = {}
         passFiles['posters'] = artFiles['posters'] + [fileroot, path.split('/')[-1]]
         # Look for posters
         for e in artExt:
           for a in passFiles['posters']:
             f = (a + '.' + e).lower()
             if f in pathFiles.keys():
               data = Core.storage.load(os.path.join(path, pathFiles[f]))
               posterName = hashlib.md5(data).hexdigest()
               if posterName not in metadata.posters:
                 metadata.posters[posterName] = Proxy.Media(data)
                 valid_posters.append(posterName)
                 Log('Local asset image added: ' + f + ', for file: ' + filename)
               else:
                 Log('skipping add for local art')
         # Look for embedded id3 APIC images in mp3 files
         if fext.lower() == '.mp3':
           f = ID3(filename)
           for frame in f.getall("APIC"):
             if (frame.mime == 'image/jpeg') or (frame.mime == 'image/jpg'): ext = 'jpg'
             elif frame.mime == 'image/png': ext = 'png'
             elif frame.mime == 'image/gif': ext = 'gif'
             else: ext = ''
             posterName = hashlib.md5(frame.data).hexdigest()
             if posterName not in metadata.posters:
               Log('Adding embedded APIC art from mp3 file: ' + filename)
               metadata.posters[posterName] = Proxy.Media(frame.data, ext=ext)
               valid_posters.append(posterName)
             else:
               Log('skipping already added APIC')
         # Look for coverart atoms in mp4/m4a
         elif fext.lower() in ['.mp4','.m4a']:
           mp4fileTags = mp4file.Mp4File(filename)
           try:
             data = find_data(mp4fileTags, 'moov/udta/meta/ilst/coverart')
             posterName = hashlib.md5(data).hexdigest()
             if posterName not in metadata.posters:
               metadata.posters['atom_coverart'] = Proxy.Media(data)
               valid_posters.append(posterName)
               Log('Adding embedded coverart from m4a/mp4 file: ' + filename)
           except: pass
   metadata.posters.validate_keys(valid_posters)
Exemplo n.º 3
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    # Take top two as show/season, but require at least the top one.
    paths = Utils.SplitPath(path)

    if len(paths) == 1 and len(paths[0]) == 0:

        # Run the select regexps we allow at the top level.
        for i in files:
            file = os.path.basename(i)
            for rx in episode_regexps[0:-1]:
                match = re.search(rx, file, re.IGNORECASE)
                if match:

                    # Extract data.
                    show = match.group('show')
                    season = int(match.group('season'))
                    episode = int(match.group('ep'))
                    endEpisode = episode
                    if match.groupdict().has_key('secondEp') and match.group(
                            'secondEp'):
                        endEpisode = int(match.group('secondEp'))

                    # Clean title.
                    name, year = VideoFiles.CleanName(show)
                    if len(name) > 0:
                        for ep in range(episode, endEpisode + 1):
                            tv_show = Media.Episode(name, season, ep, '', year)
                            tv_show.display_offset = (ep - episode) * 100 / (
                                endEpisode - episode + 1)
                            tv_show.parts.append(i)
                            mediaList.append(tv_show)

    elif len(paths) > 0 and len(paths[0]) > 0:
        done = False

        # See if parent directory is a perfect match (e.g. a directory like "24 - 8x02 - Day 8_ 5_00P.M. - 6_00P.M")
        if len(files) == 1:
            for rx in standalone_episode_regexs:
                res = re.findall(rx, paths[-1])
                if len(res):
                    show, junk, year, season, episode, junk, endEpisode, junk, title = res[
                        0]

                    # If it didn't have a show, then grab it from the directory.
                    if len(show) == 0:
                        (show, year) = VideoFiles.CleanName(paths[0])

                    episode = int(episode)
                    if len(endEpisode) > 0:
                        endEpisode = int(endEpisode)
                    else:
                        endEpisode = episode

                    for ep in range(episode, endEpisode + 1):
                        tv_show = Media.Episode(show, season, ep, title, year)
                        tv_show.display_offset = (ep - episode) * 100 / (
                            endEpisode - episode + 1)
                        tv_show.parts.append(files[0])
                        mediaList.append(tv_show)

                    done = True
                    break

        if done == False:

            # Not a perfect standalone match, so get information from directories. (e.g. "Lost/Season 1/s0101.mkv")
            season = None
            seasonNumber = None

            (show, year) = VideoFiles.CleanName(paths[0])

            # Which component looks like season?
            if len(paths) >= 2:
                season = paths[len(paths) - 1]
                match = re.match(season_regex, season, re.IGNORECASE)
                if match:
                    seasonNumber = int(match.group('season'))

            # Make sure an episode name didn't make it into the show.
            for rx in ends_with_episode:
                show = re.sub(rx, '', show)

            for i in files:
                done = False
                file = os.path.basename(i)
                (file, ext) = os.path.splitext(file)

                if ext.lower() in ['.mp4', '.m4v', '.mov']:
                    m4season = m4ep = m4year = 0
                    m4show = title = ''
                    try:
                        mp4fileTags = mp4file.Mp4File(i)

                        # Show.
                        try:
                            m4show = find_data(
                                mp4fileTags,
                                'moov/udta/meta/ilst/tvshow').encode('utf-8')
                        except:
                            pass

                        # Season.
                        try:
                            m4season = int(
                                find_data(mp4fileTags,
                                          'moov/udta/meta/ilst/tvseason'))
                        except:
                            pass

                        # Episode.
                        m4ep = None
                        try:
                            # tracknum (can be 101)
                            m4ep = int(
                                find_data(mp4fileTags,
                                          'moov/udta/meta/ilst/tracknum'))
                        except:
                            try:
                                # tvepisodenum (can be S2E16)
                                m4ep = find_data(
                                    mp4fileTags,
                                    'moov/udta/meta/ilst/tvepisodenum')
                            except:
                                # TV Episode (can be 101)
                                m4ep = int(
                                    find_data(mp4fileTags,
                                              'moov/udta/meta/ilst/tvepisode'))

                        if m4ep is not None:
                            found = False
                            try:
                                # See if it matches regular expression.
                                for rx in episode_regexps[:-1]:
                                    match = re.search(rx, file, re.IGNORECASE)
                                    if match:
                                        m4season = int(match.group('season'))
                                        m4ep = int(match.group('ep'))
                                        found = True

                                if found == False and re.match(
                                        '[0-9]+', str(m4ep)):
                                    # Carefully convert to episode number.
                                    m4ep = int(m4ep) % 100
                                elif found == False:
                                    m4ep = int(re.findall('[0-9]+', m4ep)[0])
                            except:
                                pass

                        # Title.
                        try:
                            title = find_data(
                                mp4fileTags,
                                'moov/udta/meta/ilst/title').encode('utf-8')
                        except:
                            pass

                        # Year.
                        try:
                            m4year = int(
                                find_data(mp4fileTags,
                                          'moov/udta/meta/ilst/year')[:4])
                        except:
                            pass

                        if year and m4year == 0:
                            m4year = year

                        # If we have all the data we need, add it.
                        if len(m4show) > 0 and m4season > 0 and m4ep > 0:
                            tv_show = Media.Episode(m4show, m4season, m4ep,
                                                    title, m4year)
                            tv_show.parts.append(i)
                            mediaList.append(tv_show)
                            continue

                    except:
                        pass

                # Check for date-based regexps first.
                for rx in date_regexps:
                    match = re.search(rx, file)
                    if match:
                        year = int(match.group('year'))
                        month = int(match.group('month'))
                        day = int(match.group('day'))

                        # Use the year as the season.
                        tv_show = Media.Episode(show, year, None, None, None)
                        tv_show.released_at = '%d-%02d-%02d' % (year, month,
                                                                day)
                        tv_show.parts.append(i)
                        mediaList.append(tv_show)

                        done = True
                        break

                if done == False:

                    # Take the year out, because it's not going to help at this point.
                    cleanName, cleanYear = VideoFiles.CleanName(file)
                    if cleanYear != None:
                        file = file.replace(str(cleanYear), 'XXXX')

                    # Minor cleaning on the file to avoid false matches on H.264, 720p, etc.
                    whackRx = [
                        '([hHx][\.]?264)[^0-9]', '[^[0-9](720[pP])',
                        '[^[0-9](1080[pP])', '[^[0-9](480[pP])'
                    ]
                    for rx in whackRx:
                        file = re.sub(rx, ' ', file)

                    for rx in episode_regexps:

                        match = re.search(rx, file, re.IGNORECASE)
                        if match:
                            # Parse season and episode.
                            the_season = int(match.group('season'))
                            episode = int(match.group('ep'))
                            endEpisode = episode
                            if match.groupdict().has_key(
                                    'secondEp') and match.group('secondEp'):
                                endEpisode = int(match.group('secondEp'))

                            # More validation for the weakest regular expression.
                            if rx == episode_regexps[-1]:

                                # Look like a movie? Skip it.
                                if re.match('.+ \([1-2][0-9]{3}\)', paths[-1]):
                                    done = True
                                    break

                                # Skip episode 0 on the weak regex since it's pretty much never right.
                                if the_season == 0:
                                    break

                                # Make sure this isn't absolute order.
                                if seasonNumber is not None:
                                    if seasonNumber != the_season:
                                        # Something is amiss, see if it starts with an episode numbers.
                                        if re.search('^[0-9]+[ -]', file):
                                            # Let the episode matcher have it.
                                            break

                                        # Treat the whole thing as an episode.
                                        episode = episode + the_season * 100
                                        if endEpisode is not None:
                                            endEpisode = endEpisode + the_season * 100

                            for ep in range(episode, endEpisode + 1):
                                tv_show = Media.Episode(
                                    show, the_season, ep, None, year)
                                tv_show.display_offset = (
                                    ep - episode) * 100 / (endEpisode -
                                                           episode + 1)
                                tv_show.parts.append(i)
                                mediaList.append(tv_show)

                            done = True
                            break

                if done == False:

                    # OK, next let's see if we're dealing with something that looks like an episode.
                    # Begin by cleaning the filename to remove garbage like "h.264" that could throw
                    # things off.
                    #
                    (file, fileYear) = VideoFiles.CleanName(file)

                    # if don't have a good year from before (when checking the parent folders) AND we just got a good year, use it.
                    if not year and fileYear:
                        year = fileYear

                    for rx in just_episode_regexs:
                        episode_match = re.search(rx, file, re.IGNORECASE)
                        if episode_match is not None:
                            the_episode = int(episode_match.group('ep'))
                            the_season = 1

                            # Now look for a season.
                            if seasonNumber is not None:
                                the_season = seasonNumber

                                # See if we accidentally parsed the episode as season.
                                if the_episode >= 100 and int(
                                        the_episode / 100) == the_season:
                                    the_episode = the_episode % 100

                            tv_show = Media.Episode(show, the_season,
                                                    the_episode, None, year)
                            tv_show.parts.append(i)
                            mediaList.append(tv_show)
                            done = True
                            break

                if done == False:
                    print "Got nothing for:", file

    # Stack the results.
    Stack.Scan(path, files, mediaList, subdirs)
Exemplo n.º 4
0
          seasonNumber = int(match.group('season'))
      
      # Make sure an episode name didn't make it into the show.
      for rx in ends_with_episode:
        show = re.sub(rx, '', show)

      for i in files:
        done = False
        file = os.path.basename(i)
        (file, ext) = os.path.splitext(file)
        
        if ext.lower() in ['.mp4', '.m4v', '.mov']:
          m4season = m4ep = m4year = 0
          m4show = title = ''
          try: 
            mp4fileTags = mp4file.Mp4File(i)
            
            # Show.
            try: m4show = find_data(mp4fileTags, 'moov/udta/meta/ilst/tvshow').encode('utf-8')
            except: pass
              
            # Season.
            try: m4season = int(find_data(mp4fileTags, 'moov/udta/meta/ilst/tvseason'))
            except: pass
              
            # Episode.
            m4ep = None
            try:
              # tracknum (can be 101)
              m4ep = int(find_data(mp4fileTags, 'moov/udta/meta/ilst/tracknum'))
            except: