parameters: (items)
return_statement: return True
docstring: Add and delete MythVideo records for played Miro Videos. Add and delete symbolic links
      to Miro Videos, to coverart/Miro icons, banners and Miro screenshots and fanart.
      NOTE: banner and fanart graphics were provided with the script and are used only if present.
      Abort if processing failed
      return True if processing was successful
docstring_summary: Add and delete MythVideo records for played Miro Videos. Add and delete symbolic links
      to Miro Videos, to coverart/Miro icons, banners and Miro screenshots and fanart.
      NOTE: banner and fanart graphics were provided with the script and are used only if present.
      Abort if processing failed
      return True if processing was successful
docstring_tokens: Add and delete MythVideo records for played Miro Videos . Add and delete symbolic links to Miro Videos to coverart / Miro icons banners and Miro screenshots and fanart . NOTE : banner and fanart graphics were provided with the script and are used only if present . Abort if processing failed return True if processing was successful
function: def updateMythVideo(items):
      '''Add and delete MythVideo records for played Miro Videos. Add and delete symbolic links
      to Miro Videos, to coverart/Miro icons, banners and Miro screenshots and fanart.
      NOTE: banner and fanart graphics were provided with the script and are used only if present.
      Abort if processing failed
      return True if processing was successful
      '''
      global localhostname, vid_graphics_dirs, storagegroups, channel_id, flat, simulation, verbose
      global channel_watch_only, statistics
      global graphic_suffix, graphic_path_suffix, graphic_name_suffix
      global local_only
  
      if not items: # There may not be any new items but a clean up of existing records may be required
          items = []
      # Check that a MIRO video directory exists
      # if not then create the dir and add symbolic link to cover/file or icon
      createMiroMythVideoDirectory()
  
      # Remove any Miro Mythvideo records which the video or graphics paths are broken
      records = list(mythdb.searchVideos(category=u'Miro'))
      statistics[u'Total_Miro_MythVideos'] = len(records)
      for record in records: # Count the Miro-MythVideos that Miro is expiring or has saved
          if record[u'filename'][0] == u'/':
              if os.path.islink(record[u'filename']) and os.path.isfile(record[u'filename']):
                  statistics[u'Total_Miro_expiring']+=1
          elif record[u'host'] and storagegroups.has_key(u'mythvideo'):
              if os.path.islink(storagegroups[u'mythvideo']+record[u'filename']) and \
                          os.path.isfile(storagegroups[u'mythvideo']+record[u'filename']):
                  statistics[u'Total_Miro_expiring']+=1
      for record in records:
          if checkVideometadataFails(record, flat):
              delete = False
              if os.path.islink(record[u'filename']): # Only delete video files if they are symlinks
                  if not record[u'host'] or record[u'filename'][0] == '/':
                      if not os.path.isfile(record[u'filename']):
                          delete = True
                  else:
                      if not os.path.isfile(vid_graphics_dirs[key_trans[field]]+record[u'filename']):
                          delete = True
              else:
                  if not os.path.isfile(record[u'filename']):
                      delete = True
              if delete: # Only delete video files if they are symlinks
                  if simulation:
                      logger.info(u"Simulation: DELETE videometadata for intid = %s" % \
                                          (record[u'intid'],))
                      logger.info(u"Simulation: DELETE oldrecorded for title(%s), subtitle(%s)" % \
                                          (record[u'title'], record[u'subtitle']))
                  else:
                      rtn = Video(record[u'intid'], db=mythdb).delete()
                      try: # An orphaned oldrecorded record may not exist
                          for oldrecorded in mythdb.searchOldRecorded(title=record[u'title'],
                                                                      subtitle=record[u'subtitle'] ):
                              rtn = delOldRecorded(channel_id,
                                                  oldrecorded['starttime'],
                                                  oldrecorded['endtime'],
                                                  oldrecorded['title'],
                                                  oldrecorded['subtitle'],
                                                  oldrecorded['description'])
                      except Exception, e:
                          pass
                  statistics[u'Total_Miro_MythVideos']-=1
                  # Remove video file
                  metadata.deleteFile(record[u'filename'], record[u'host'], u'mythvideo')
              if record[u'screenshot']: # Remove any associated Screenshot
                  metadata.deleteFile(record[u'screenshot'], record[u'host'], u'episodeimagedir')
              # Remove any unique cover art graphic files
              if record[u'title'].lower() in channel_icon_override:
                  metadata.deleteFile(record[u'coverfile'], record[u'host'], u'posterdir')
  
      if not items: # There may not be any new items to add to MythVideo
          return True
      # Reread Miro Mythvideo videometadata records
      # Remove the matching videometadata record from array of items
      items_copy = list(items)
      records = list(mythdb.searchVideos(category=u'Miro'))
      for record in records:
          for item in items:
              if item[u'channelTitle'] == record[u'title'] and item[u'title'] == record[u'subtitle']:
                  try:
                      items_copy.remove(item)
                  except ValueError:
                      logger.info((u"Video (%s - %s) was found multiple times in list of (watched "\
                                   u"and/or saved) items from Miro - skipping") % \
                                          (item[u'channelTitle'], item[u'title']))
                      pass
                  break
  
      for item in items: # Remove any items that are for a Channel that does not get MythVideo records
          if filter(is_not_punct_char, item[u'channelTitle'].lower()) in channel_watch_only:
              try:    # Some items may have already been removed, let those passed
                  items_copy.remove(item)
              except ValueError:
                  pass
      # Add Miro videos that remain in the item list
      # If not a flat directory check if title directory exists and add icon symbolic link as coverfile
      for item in items_copy:
          if not flat and not item.has_key(u'copied'):
              createMiroChannelSubdirectory(item)
          if not item[u'screenshot']: # If there is no screen shot then create one
              screenshot_mythvideo = u"%s%s - %s%s.jpg" % \
                              (vid_graphics_dirs[u'episodeimagedir'],
                               sanitiseFileName(item[u'channelTitle']),
                               sanitiseFileName(item[u'title']),
                               graphic_suffix[u'episodeimagedir'])
              try:
                  result = takeScreenShot(item[u'videoFilename'], screenshot_mythvideo, size_limit=False)
              except:
                  result = None
              if result is not None:
                  item[u'screenshot'] = screenshot_mythvideo
          tmp_array = createVideometadataRecord(item)
          videometadata = tmp_array[0]
          oldrecorded = tmp_array[1]
          if simulation:
              logger.info(u"Simulation: Create videometadata record for (%s - %s)" % \
                                              (item[u'channelTitle'], item[u'title']))
          else:  # Check for duplicates
              if not local_only and videometadata[u'filename'][0] != u'/':
                  intid = list(mythdb.searchVideos(exactfile=videometadata[u'filename'],
                                                   host=localhostname.lower()))
              else:
                  intid = list(mythdb.searchVideos(exactfile=videometadata[u'filename']))
  
              if intid == []: # Check for an empty array
                  try:
                      intid = Video(db=mythdb).create(videometadata).intid
                  except MythError, e:
                      logger.critical(u"Adding Miro video to MythVideo (%s - %s) failed for (%s)." % \
                                              (item[u'channelTitle'], item[u'title'], e.args[0]))
                      sys.exit(1)
                  if not item.has_key(u'copied'):
                      try:
                          OldRecorded().create(oldrecorded)
                      except MythError, e:
                          logger.critical(u"Failed writing the oldrecorded record for(%s)" % (e.args[0]))
                          sys.exit(1)
                  if videometadata[u'filename'][0] == u'/':
                      cmd = mythcommflag_videos % videometadata[u'filename']
                  elif videometadata[u'host'] and storagegroups[u'mythvideo']:
                      cmd = mythcommflag_videos % \
                                  ((storagegroups[u'mythvideo']+videometadata[u'filename']))
                  statistics[u'Miros_MythVideos_added']+=1
                  statistics[u'Total_Miro_expiring']+=1
                  statistics[u'Total_Miro_MythVideos']+=1
                  displayMessage(u"Added Miro video to MythVideo (%s - %s)" % \
                                          (videometadata[u'title'], videometadata[u'subtitle']))
              else:
                  sys.stdout.write(u'')
                  displayMessage(\
  u"""Skipped adding a duplicate Miro video to MythVideo:
  (%s - %s)
  Sometimes a Miro channel has the same video downloaded multiple times.
  This is a Miro/Channel web site issue and often rectifies itself overtime.
  """ % (videometadata[u'title'], videometadata[u'subtitle']))
  
      return True
function_tokens: def updateMythVideo ( items ) : global localhostname , vid_graphics_dirs , storagegroups , channel_id , flat , simulation , verbose global channel_watch_only , statistics global graphic_suffix , graphic_path_suffix , graphic_name_suffix global local_only if not items : # There may not be any new items but a clean up of existing records may be required items = [ ] # Check that a MIRO video directory exists # if not then create the dir and add symbolic link to cover/file or icon createMiroMythVideoDirectory ( ) # Remove any Miro Mythvideo records which the video or graphics paths are broken records = list ( mythdb . searchVideos ( category = u'Miro' ) ) statistics [ u'Total_Miro_MythVideos' ] = len ( records ) for record in records : # Count the Miro-MythVideos that Miro is expiring or has saved if record [ u'filename' ] [ 0 ] == u'/' : if os . path . islink ( record [ u'filename' ] ) and os . path . isfile ( record [ u'filename' ] ) : statistics [ u'Total_Miro_expiring' ] += 1 elif record [ u'host' ] and storagegroups . has_key ( u'mythvideo' ) : if os . path . islink ( storagegroups [ u'mythvideo' ] + record [ u'filename' ] ) and os . path . isfile ( storagegroups [ u'mythvideo' ] + record [ u'filename' ] ) : statistics [ u'Total_Miro_expiring' ] += 1 for record in records : if checkVideometadataFails ( record , flat ) : delete = False if os . path . islink ( record [ u'filename' ] ) : # Only delete video files if they are symlinks if not record [ u'host' ] or record [ u'filename' ] [ 0 ] == '/' : if not os . path . isfile ( record [ u'filename' ] ) : delete = True else : if not os . path . isfile ( vid_graphics_dirs [ key_trans [ field ] ] + record [ u'filename' ] ) : delete = True else : if not os . path . isfile ( record [ u'filename' ] ) : delete = True if delete : # Only delete video files if they are symlinks if simulation : logger . info ( u"Simulation: DELETE videometadata for intid = %s" % ( record [ u'intid' ] , ) ) logger . info ( u"Simulation: DELETE oldrecorded for title(%s), subtitle(%s)" % ( record [ u'title' ] , record [ u'subtitle' ] ) ) else : rtn = Video ( record [ u'intid' ] , db = mythdb ) . delete ( ) try : # An orphaned oldrecorded record may not exist for oldrecorded in mythdb . searchOldRecorded ( title = record [ u'title' ] , subtitle = record [ u'subtitle' ] ) : rtn = delOldRecorded ( channel_id , oldrecorded [ 'starttime' ] , oldrecorded [ 'endtime' ] , oldrecorded [ 'title' ] , oldrecorded [ 'subtitle' ] , oldrecorded [ 'description' ] ) except Exception , e : pass statistics [ u'Total_Miro_MythVideos' ] -= 1 # Remove video file metadata . deleteFile ( record [ u'filename' ] , record [ u'host' ] , u'mythvideo' ) if record [ u'screenshot' ] : # Remove any associated Screenshot metadata . deleteFile ( record [ u'screenshot' ] , record [ u'host' ] , u'episodeimagedir' ) # Remove any unique cover art graphic files if record [ u'title' ] . lower ( ) in channel_icon_override : metadata . deleteFile ( record [ u'coverfile' ] , record [ u'host' ] , u'posterdir' ) if not items : # There may not be any new items to add to MythVideo return True # Reread Miro Mythvideo videometadata records # Remove the matching videometadata record from array of items items_copy = list ( items ) records = list ( mythdb . searchVideos ( category = u'Miro' ) ) for record in records : for item in items : if item [ u'channelTitle' ] == record [ u'title' ] and item [ u'title' ] == record [ u'subtitle' ] : try : items_copy . remove ( item ) except ValueError : logger . info ( ( u"Video (%s - %s) was found multiple times in list of (watched " u"and/or saved) items from Miro - skipping" ) % ( item [ u'channelTitle' ] , item [ u'title' ] ) ) pass break for item in items : # Remove any items that are for a Channel that does not get MythVideo records if filter ( is_not_punct_char , item [ u'channelTitle' ] . lower ( ) ) in channel_watch_only : try : # Some items may have already been removed, let those passed items_copy . remove ( item ) except ValueError : pass # Add Miro videos that remain in the item list # If not a flat directory check if title directory exists and add icon symbolic link as coverfile for item in items_copy : if not flat and not item . has_key ( u'copied' ) : createMiroChannelSubdirectory ( item ) if not item [ u'screenshot' ] : # If there is no screen shot then create one screenshot_mythvideo = u"%s%s - %s%s.jpg" % ( vid_graphics_dirs [ u'episodeimagedir' ] , sanitiseFileName ( item [ u'channelTitle' ] ) , sanitiseFileName ( item [ u'title' ] ) , graphic_suffix [ u'episodeimagedir' ] ) try : result = takeScreenShot ( item [ u'videoFilename' ] , screenshot_mythvideo , size_limit = False ) except : result = None if result is not None : item [ u'screenshot' ] = screenshot_mythvideo tmp_array = createVideometadataRecord ( item ) videometadata = tmp_array [ 0 ] oldrecorded = tmp_array [ 1 ] if simulation : logger . info ( u"Simulation: Create videometadata record for (%s - %s)" % ( item [ u'channelTitle' ] , item [ u'title' ] ) ) else : # Check for duplicates if not local_only and videometadata [ u'filename' ] [ 0 ] != u'/' : intid = list ( mythdb . searchVideos ( exactfile = videometadata [ u'filename' ] , host = localhostname . lower ( ) ) ) else : intid = list ( mythdb . searchVideos ( exactfile = videometadata [ u'filename' ] ) ) if intid == [ ] : # Check for an empty array try : intid = Video ( db = mythdb ) . create ( videometadata ) . intid except MythError , e : logger . critical ( u"Adding Miro video to MythVideo (%s - %s) failed for (%s)." % ( item [ u'channelTitle' ] , item [ u'title' ] , e . args [ 0 ] ) ) sys . exit ( 1 ) if not item . has_key ( u'copied' ) : try : OldRecorded ( ) . create ( oldrecorded ) except MythError , e : logger . critical ( u"Failed writing the oldrecorded record for(%s)" % ( e . args [ 0 ] ) ) sys . exit ( 1 ) if videometadata [ u'filename' ] [ 0 ] == u'/' : cmd = mythcommflag_videos % videometadata [ u'filename' ] elif videometadata [ u'host' ] and storagegroups [ u'mythvideo' ] : cmd = mythcommflag_videos % ( ( storagegroups [ u'mythvideo' ] + videometadata [ u'filename' ] ) ) statistics [ u'Miros_MythVideos_added' ] += 1 statistics [ u'Total_Miro_expiring' ] += 1 statistics [ u'Total_Miro_MythVideos' ] += 1 displayMessage ( u"Added Miro video to MythVideo (%s - %s)" % ( videometadata [ u'title' ] , videometadata [ u'subtitle' ] ) ) else : sys . stdout . write ( u'' ) displayMessage ( u"""Skipped adding a duplicate Miro video to MythVideo:
  (%s - %s)
  Sometimes a Miro channel has the same video downloaded multiple times.
  This is a Miro/Channel web site issue and often rectifies itself overtime.
  """ % ( videometadata [ u'title' ] , videometadata [ u'subtitle' ] ) ) return True