original_docstring: 
      Query MongoDB and build data structures prior to transcoding
      
docstring: Query MongoDB and build data structures prior to transcoding
docstring_tokens: Query MongoDB and build data structures prior to transcoding
code: def vdataBuild():
      """
      Query MongoDB and build data structures prior to transcoding
      """
      global monjer, config
  
      vx.fdi = monjer.findOne('files', {'_id': vinfo.id})
      if vx.fdi:
          logthis("Found matching entry in database", loglevel=LL.INFO)
          # Get episode information
          if vx.fdi['episode_id']:
              vx.fdi_epx = monjer.findOne('episodes', {'_id': vx.fdi['episode_id']})
              logthis("Found matching episode entry", loglevel=LL.VERBOSE)
          else:
              vx.fdi_epx = None
  
          # Get series information
          if vx.fdi['series_id']:
              vx.fdi_srx = monjer.findOne('series', {'_id': vx.fdi['series_id']})
              logthis("Found matching series entry", loglevel=LL.VERBOSE)
          else:
              vx.fdi_srx = None
  
          # Check if matching video already exists
          if not monjer.findOne('videos', {'_id': vx.fdi['_id']}):
              logthis("Entry does not already exist. Populating video metadata", loglevel=LL.INFO)
              vinfo.mxmode = MXM.INSERT
              # Check location
              if config.vid['location']:
                  # Get from running config (--vername option or vid.vername)
                  vinfo.location = config.vid['location']
              else:
                  # Otherwise, get first location from list
                  vinfo.location = vx.fdi['location'].keys()[0]
  
              # Initialize metadata
              xvid = {
                      '_id': vx.fdi['_id'],
                      'metadata': {
                              'title': setifset(vx.fdi_epx, 'EpisodeName'),
                              'series': vx.fdi['fparse']['series'],
                              'episode': vx.fdi['fparse']['episode'],
                              'season': vx.fdi['fparse']['season'],
                              'special': vx.fdi['fparse']['special']
                          },
                      'tdex_id': setifset(vx.fdi_srx, 'norm_id'),
                      'series_id': vx.fdi['series_id'],
                      'episode_id': vx.fdi['episode_id'],
                      'tvdb_id': {'series': vx.fdi_srx['xrefs']['tvdb'], 'episode': vx.fdi_epx['tvdb_id']},
                      'source': {
                              'filename': vx.fdi['location'][vinfo.location]['fpath']['file'],
                              'location': {
                                      'hostname': vinfo.location,
                                      'path': vx.fdi['location'][vinfo.location]['fpath']['real']
                                  },
                              'mediainfo': vx.fdi['mediainfo'],
                              'checksum': vx.fdi['checksum'],
                              'stat': vx.fdi['location'][vinfo.location]['stat']
                          },
                      'subs': {
                              'enabled': trueifset(config.run['bake'], typematch=True),
                              'lang': 'eng',
                              'fansub': setifset(config.run, 'fansub')
                          },
                      'versions': {}
                     }
          else:
              # Entry already exists in db.videos
              logthis("Entry already exists. Will update version or vscap information.", loglevel=LL.INFO)
              vinfo.mxmode = MXM.UPDATE
              xvid = {'versions': {}}
      else:
          logthis("No matching entry found in database. ID:", suffix=vinfo.id, loglevel=LL.ERROR)
          failwith(ER.NOTFOUND, "No match for VID. Will not contiue. Aborting.")
  
      return xvid
code_tokens: def vdataBuild ( ) : global monjer , config vx . fdi = monjer . findOne ( 'files' , { '_id' : vinfo . id } ) if vx . fdi : logthis ( "Found matching entry in database" , loglevel = LL . INFO ) if vx . fdi [ 'episode_id' ] : vx . fdi_epx = monjer . findOne ( 'episodes' , { '_id' : vx . fdi [ 'episode_id' ] } ) logthis ( "Found matching episode entry" , loglevel = LL . VERBOSE ) else : vx . fdi_epx = None if vx . fdi [ 'series_id' ] : vx . fdi_srx = monjer . findOne ( 'series' , { '_id' : vx . fdi [ 'series_id' ] } ) logthis ( "Found matching series entry" , loglevel = LL . VERBOSE ) else : vx . fdi_srx = None if not monjer . findOne ( 'videos' , { '_id' : vx . fdi [ '_id' ] } ) : logthis ( "Entry does not already exist. Populating video metadata" , loglevel = LL . INFO ) vinfo . mxmode = MXM . INSERT if config . vid [ 'location' ] : vinfo . location = config . vid [ 'location' ] else : vinfo . location = vx . fdi [ 'location' ] . keys ( ) [ 0 ] xvid = { '_id' : vx . fdi [ '_id' ] , 'metadata' : { 'title' : setifset ( vx . fdi_epx , 'EpisodeName' ) , 'series' : vx . fdi [ 'fparse' ] [ 'series' ] , 'episode' : vx . fdi [ 'fparse' ] [ 'episode' ] , 'season' : vx . fdi [ 'fparse' ] [ 'season' ] , 'special' : vx . fdi [ 'fparse' ] [ 'special' ] } , 'tdex_id' : setifset ( vx . fdi_srx , 'norm_id' ) , 'series_id' : vx . fdi [ 'series_id' ] , 'episode_id' : vx . fdi [ 'episode_id' ] , 'tvdb_id' : { 'series' : vx . fdi_srx [ 'xrefs' ] [ 'tvdb' ] , 'episode' : vx . fdi_epx [ 'tvdb_id' ] } , 'source' : { 'filename' : vx . fdi [ 'location' ] [ vinfo . location ] [ 'fpath' ] [ 'file' ] , 'location' : { 'hostname' : vinfo . location , 'path' : vx . fdi [ 'location' ] [ vinfo . location ] [ 'fpath' ] [ 'real' ] } , 'mediainfo' : vx . fdi [ 'mediainfo' ] , 'checksum' : vx . fdi [ 'checksum' ] , 'stat' : vx . fdi [ 'location' ] [ vinfo . location ] [ 'stat' ] } , 'subs' : { 'enabled' : trueifset ( config . run [ 'bake' ] , typematch = True ) , 'lang' : 'eng' , 'fansub' : setifset ( config . run , 'fansub' ) } , 'versions' : { } } else : logthis ( "Entry already exists. Will update version or vscap information." , loglevel = LL . INFO ) vinfo . mxmode = MXM . UPDATE xvid = { 'versions' : { } } else : logthis ( "No matching entry found in database. ID:" , suffix = vinfo . id , loglevel = LL . ERROR ) failwith ( ER . NOTFOUND , "No match for VID. Will not contiue. Aborting." ) return xvid
short_docstring: Query MongoDB and build data structures prior to transcoding
short_docstring_tokens: Query MongoDB and build data structures prior to transcoding
comment: """
      Query MongoDB and build data structures prior to transcoding
      """$SEP$# Get episode information$SEP$# Get series information$SEP$# Check if matching video already exists$SEP$# Check location$SEP$# Get from running config (--vername option or vid.vername)$SEP$# Otherwise, get first location from list$SEP$# Initialize metadata$SEP$# Entry already exists in db.videos