Difference between revisions of "Myth video scan.py"
From MythTV Official Wiki
(add image download capacity) |
m |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | This script | + | {{EOL2|This script has been deprecated by a video scanner built into the backend in 0.25, accessible through [[Myth Protocol]].}} |
+ | |||
+ | {{Script info | ||
+ | |author=Raymond Wagner | ||
+ | |short=command line mythvideo scanner | ||
+ | |long=A basic scanner for MythVideo intended as an example to document the Video, MythVideo, and VideoGrabber classes. | ||
+ | |category=MythVideo | ||
+ | |file=myth_video_scan.py | ||
+ | |S24=yes}} | ||
This script will perform a scan of all defined storage groups, delete missing videos, and adding any new videos for which it can find an exact match using MythVideo's defined metadata grabbers. Any new videos for which there are no or multiple matches will be skipped. | This script will perform a scan of all defined storage groups, delete missing videos, and adding any new videos for which it can find an exact match using MythVideo's defined metadata grabbers. Any new videos for which there are no or multiple matches will be skipped. | ||
Line 11: | Line 19: | ||
import os | import os | ||
import sys | import sys | ||
− | |||
− | |||
try: | try: | ||
from MythTV import MythVideo, VideoGrabber, MythLog | from MythTV import MythVideo, VideoGrabber, MythLog | ||
Line 37: | Line 43: | ||
print 'ERROR: Cannot find MythVideo TV grabber' | print 'ERROR: Cannot find MythVideo TV grabber' | ||
sys.exit(-1) | sys.exit(-1) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# Load Movie Grabber | # Load Movie Grabber | ||
Line 64: | Line 58: | ||
if len(todel) > 0: | if len(todel) > 0: | ||
print '--- Deleting Old Videos ---' | print '--- Deleting Old Videos ---' | ||
− | print len(todel) | + | print len(todel),' found' |
for vid in todel: | for vid in todel: | ||
print ' '+format_name(vid) | print ' '+format_name(vid) | ||
Line 72: | Line 66: | ||
if len(toadd) > 0: | if len(toadd) > 0: | ||
print '--- Adding New Videos ---' | print '--- Adding New Videos ---' | ||
− | print len(toadd) | + | print len(toadd),' found' |
for vid in toadd: | for vid in toadd: | ||
print ' '+format_name(vid), | print ' '+format_name(vid), | ||
if vid.subtitle: | if vid.subtitle: | ||
− | matches = TVgrab. | + | matches = TVgrab.sortedSearch(vid.title, vid.subtitle) |
else: | else: | ||
− | matches = Mgrab. | + | matches = Mgrab.sortedSearch(vid.title) |
if len(matches) == 0: | if len(matches) == 0: | ||
Line 85: | Line 79: | ||
continue | continue | ||
elif len(matches) > 1: | elif len(matches) > 1: | ||
− | + | if matches[0].levenshtein > 0: | |
− | + | print '... multiple matches, skipped.' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
continue | continue | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
vid.create() | vid.create() | ||
− | + | vid.importMetadata(matches[0]) | |
− | |||
− | |||
− | |||
− | |||
− | |||
print '... successful.' | print '... successful.' | ||
</pre> | </pre> | ||
}} | }} | ||
− | + | ||
[[Category:Python_Scripts]] | [[Category:Python_Scripts]] |
Latest revision as of 00:57, 29 August 2011
End Of Life: This script has been deprecated by a video scanner built into the backend in 0.25, accessible through Myth Protocol.
Author | Raymond Wagner |
Description | A basic scanner for MythVideo intended as an example to document the Video, MythVideo, and VideoGrabber classes. |
Supports | ![]() |
This script will perform a scan of all defined storage groups, delete missing videos, and adding any new videos for which it can find an exact match using MythVideo's defined metadata grabbers. Any new videos for which there are no or multiple matches will be skipped.
#!/usr/bin/env python # -*- coding: UTF-8 -*- #---------------------- import os import sys try: from MythTV import MythVideo, VideoGrabber, MythLog except: print 'ERROR: The python bindings are not installed' sys.exit(-1) LOG = MythLog('MythVideo Scanner', lstr='general') mvid = MythVideo() def format_name(vid): # returns a string in the format 'TITLE[ - SEASONxEPISODE][ - SUBTITLE]' s = vid.title if vid.season: s += ' - %dx%02d' % (vid.season, vid.episode) if vid.subtitle: s += ' - '+vid.subtitle return s # Load TV Grabber try: TVgrab = VideoGrabber('TV', db=mvid) except: print 'ERROR: Cannot find MythVideo TV grabber' sys.exit(-1) # Load Movie Grabber try: Mgrab = VideoGrabber('Movie', db=mvid) except: print 'ERROR: Cannot find MythVideo Movie grabber' sys.exit(-1) # pull new/old content list LOG(LOG.GENERAL, 'Performing scan...') toadd, todel = mvid.scanStorageGroups(False) # print list of content to be deleted if len(todel) > 0: print '--- Deleting Old Videos ---' print len(todel),' found' for vid in todel: print ' '+format_name(vid) vid.delete() # loop through content to add if len(toadd) > 0: print '--- Adding New Videos ---' print len(toadd),' found' for vid in toadd: print ' '+format_name(vid), if vid.subtitle: matches = TVgrab.sortedSearch(vid.title, vid.subtitle) else: matches = Mgrab.sortedSearch(vid.title) if len(matches) == 0: print '... no matches, skipped.' continue elif len(matches) > 1: if matches[0].levenshtein > 0: print '... multiple matches, skipped.' continue vid.create() vid.importMetadata(matches[0]) print '... successful.'