Esempio n. 1
0
def TVRageDate(title, year, month, day, out=sys.stdout):
  """ TVRageDate -- Get and format subtitle and description from TVRage based on a date
      title   = Official name of TV-show ... as exact as possible, please
      year    = year number (int)
      month   = month number (int)
      day     = number (int)
      returns the correct subtitle and full description then the season and episode number
  """
  found = False
  try:
    #get the TVrage show information
    tvshow = tvrage.api.Show(title)
    #then get the TVrage Episode information
    seasoncount = int(tvshow.seasons)
    while (seasoncount > 0) and not found:
      season = tvshow.season(seasoncount)
      for episodes in season:
        if tvshow.season(seasoncount).episode(episodes).airdate == date(int(year), int(month), int(day)):
          subtitle = tvshow.season(seasoncount).episode(episodes).title
          #return subtitle and description
          if title == tvshow.season(seasoncount).episode(episodes).show:
            return subtitle, utility.massageDescription(tvshow.season(seasoncount).episode(episodes).summary), tvshow.season(seasoncount).episode(episodes).season, tvshow.season(seasoncount).episode(episodes).number
            found = True
      seasoncount = seasoncount - 1
  except:
    return 0
  if not found:
    return 0
Esempio n. 2
0
def TTVDBDate(title, year, month, day, out=sys.stdout):
  """ TTVDBDate -- Get and format subtitle and description from The TV Database based on a date
      title   = Official name of TV-show ... as exact as possible, please
      year    = year number (int)
      month   = month number (int)
      day     = number (int)
      returns the correct subtitle and full description then the season and episode number and lastly the TTVDBID
  """
  found = False
  try:
    #get the TTVDB show information
    ttvdb = tvdb_api.Tvdb()
    tvshow = ttvdb[title]
    #then get the TVrage Episode information

    for season in tvshow:
      for episode in tvshow[season]:
        try:
          airdate = datetime.strptime(tvshow[season][episode]['firstaired'], '%Y-%m-%d')
        except:
          airdate = datetime(1,1,1)
        if airdate == datetime(int(year), int(month), int(day)):
          subtitle = tvshow[season][episode]['episodename']
          #return subtitle and description
          return subtitle, utility.massageDescription(tvshow[season][episode]['overview']), season, episode, tvshow[season][episode]['seriesid']
          found = True
  except:
    return 0 
Esempio n. 3
0
def TTVDBSeasonEpisode(title, season, episode, out=sys.stdout):
  """ TTVDBSeasonEpisode -- Get and format subtitle and description from The TV Database based on a season and episode
      title   = Official name of TV-show ... as exact as possible, please
      season  = season number (int)
      episode = episode number (int)
      returns the correct title and full description, season, episode and TTVDBID
  """
  found = False
  try:
    #get the TVrage show information
    tvshow = tvdb_api.Tvdb()
    #then get the TVrage Episode information
    tvrageepisode = tvshow[title][season][episode]
    #return subtitle and description
    try:
      description = utility.massageDescription(tvrageepisode['overview'].encode('latin-1','ignore'))
    except:
      description = utility.massageDescription(tvrageepisode['overview'])
    return tvrageepisode['episodename'], description, season, episode, tvrageepisode['seriesid']
    found = True
  except:
    return 0
Esempio n. 4
0
def TTVDBSubtitle(title, subtitle, out=sys.stdout):
  """ TTVDBSubtitle -- Get and format subtitle and description from The TV Database based on a show subtitle
      title    = Official name of TV-show ... as exact as possible, please
      subtitle = correct official subtitle of the show
      returns the correct subtitle and full description then the season and episode number and lastly the TTVDBID
  """
  found = False
  try:
    #get the TTVDB show information
    ttvdb = tvdb_api.Tvdb()
    tvshow = ttvdb[title]
    for season in tvshow:
      for episode in tvshow[season]:
        if tvshow[season][episode]['episodename'] == subtitle:
          return subtitle, utility.massageDescription(tvshow[season][episode]['overview'].encode('latin-1','ignore')), season, episode, tvshow[season][episode]['seriesid']
          found = True
  except:
    return 0
Esempio n. 5
0
def TVRageSeasonEpisode(title, season, episode, out=sys.stdout):
  """ TVRageSeasonEpisode -- Get and format subtitle and description from TVRage based on a season and episode
      title   = Official name of TV-show ... as exact as possible, please
      season  = season number (int)
      episode = episode number (int)
      returns the correct title and full description
  """
  try:
    #get the TVrage show information
    tvshow = tvrage.api.Show(title)
    #then get the TVrage Episode information
    tvrageepisode = tvshow.season(season).episode(episode)
    if title.lower() == tvrageepisode.show.lower():
    #return subtitle and description
      return tvrageepisode.title, utility.massageDescription(tvrageepisode.summary)
    else:
      return 0
  except:
    return 0
Esempio n. 6
0
def Sync(db, xmlfile, title, out=sys.stdout):
  """Sync -- sync up with an RSS feed"""
  global complained_about_swf

  # Grab the XML
  xmllines = xmlfile.readlines()

  # Modify the XML to work around namespace handling bugs in FeedParser
  lines = []
  re_mediacontent = re.compile('(.*)<media:content([^>]*)/ *>(.*)')

  for line in xmllines:
    m = re_mediacontent.match(line)
    count = 1
    while m:
      line = '%s<media:wannabe%d>%s</media:wannabe%d>%s' %(m.group(1), count,
                                                         m.group(2),
                                                         count, m.group(3))
      m = re_mediacontent.match(line)
      count = count + 1

    lines.append(line)

  # Parse the modified XML
  xml = ''.join(lines)
  parser = feedparser.parse(xml)

  
  
  # Find the media:content entries
  for entry in parser.entries:

    # detect feedparser version
    try:                                       # feedparser >= 5.1.1 
      date = entry.published                  # publication date of entry 
      date_parsed = entry.published_parsed     # date parsed 
    except AttributeError:                      # older feedparser
      try:
        date = entry.date                       # feedparser < 5.1.1
        date_parsed = entry.date_parsed
      except: # needed because some feeds do not provide a viable date
        date = datetime.datetime.now()
        date_parsed = date
        time.sleep(1) # make sure every entry has a unique date

    videos = {}
    try:
      description = utility.massageDescription(entry.description)
    except:
      description = ''
    
    subtitle = entry.title

#    if entry.has_key('media_description'):
#      description = utility.massageDescription(entry['media_description'])
     
    # Enclosures
    #out.write(entry)
    if entry.has_key('enclosures'):
      for enclosure in entry.enclosures:
        try:
          videos[enclosure.type] = enclosure
        except:
          videos[GuessMimeType(enclosure.href)] = enclosure

    # Media:RSS
    for key in entry.keys():
      if key.startswith('media_wannabe'):
        attrs = ParseAttributes(entry[key])
        if attrs.has_key('type'):
          videos[attrs['type']] = attrs
        if attrs.has_key('title'):
          subtitle = attrs['title']

    done = False
    if FLAGS.verbose:
      out.write('  Considering: %s: %s\n' %(title, subtitle))

    # very crude, basic subtitle detection
    if not done and db.GetOneRow('select title from mythnettv_programs '
                                   'where title=%s and subtitle=%s;' %(db.FormatSqlValue('', title), db.FormatSqlValue('', subtitle))):
      done = True
      if FLAGS.verbose:
        out.write('   Dupicate detected %s: %s\n' %(title, subtitle))
    
    if not done and db.GetOneRow('select title from mythnettv_programs '
                                 'where guid="%s";' % utility.hashtitlesubtitle(title, subtitle)):
      done = True
      if FLAGS.verbose:
        out.write('   Dupicate detected in GUID: %s\n' % utility.hashtitlesubtitle(title, subtitle))
      
    # add this if you want actual bittorrent files instead of magnets 'application/x-bittorrent',
    for preferred in ['video/x-msvideo', 'video/mp4', 'video/x-xvid',
                      'video/wmv', 'video/x-ms-wmv', 'video/quicktime',
                      'video/x-m4v', 'video/x-flv', 'video/m4v',
                      'video/msvideo',
                      'video/vnd.objectvideo', 'video/ms-wmv', 'video/mpeg']:

      if not done and videos.has_key(preferred):
        Download(db,
                 videos[preferred]['url'],
                 utility.hashtitlesubtitle(title, subtitle),
                 preferred,
                 title,
                 subtitle,
                 description,
                 date,
                 date_parsed,
                 out=out)
        done = True


    if not done and entry.has_key('link'):
      if FLAGS.verbose:
        out.write('Link found: %s' %(entry['link']))
      if entry['link'].startswith('magnet'):
	if FLAGS.verbose:
	  out.write('    Warning: treating the link as if it where a Magnet link\n')
	Download(db,
               entry['link'],
               utility.hashtitlesubtitle(title, subtitle),
               'application/x-bittorrent',
               title,
               subtitle,
               description,
               date,
               date_parsed,
               out=out)
        done = True

    if not done and entry.has_key('magnetURI'):
      if FLAGS.verbose:
        out.write('%s' %(entry['magnetURI']))
      if entry['magnetURI'].startswith('magnet'):
        if FLAGS.verbose:
          out.write('    Warning: treating the magnetURI as if it where a Magnet link\n')
        Download(db,
               entry['magnetURI'],
               utility.hashtitlesubtitle(title, subtitle),
               'application/x-bittorrent',
               title,
               subtitle,
               description,
               date,
               date_parsed,
               out=out)
        done = True

    if not done and entry.has_key('link'):
      if FLAGS.verbose:
        out.write('Link found: %s' %(entry['link']))
      if entry['link'].endswith('m3u8'):
	if FLAGS.verbose:
	  out.write('    Warning: this seems to be a m3u8 stream\n')
	Download(db,
               entry['link'],
               utility.hashtitlesubtitle(title, subtitle),
               'application/x-mpegurl',
               title,
               subtitle,
               description,
               date,
               date_parsed,
               out=out)
        done = True
    
     # handle youtube rss feeds
    if not done and entry['link'].startswith('http://www.youtube') or entry['link'].startswith('https://www.youtube'):
      if FLAGS.verbose:
        out.write(' Warning: looks like a YouTube video link\n')
      Download(db,
             entry['link'],
             utility.hashtitlesubtitle(title, subtitle),
             'application/x-shockwave-flash',
             title,
             subtitle,
             description,
             date,
             date_parsed,
             out=out)
      done = True

    # handle ZDF rss feeds
    if not done and entry['link'].startswith('http://www.zdf'):
      if FLAGS.verbose:
        out.write(' Warning: looks like a ZDF Mediathek link\n')
      Download(db,
             entry['link'],
             utility.hashtitlesubtitle(title, subtitle),
             'application/x-shockwave-flash',
             title,
             subtitle,
             description,
             date,
             date_parsed,
             out=out)
      done = True

    if not done and entry['link'].startswith('http://www.thedaily'):
      if FLAGS.verbose:
        out.write(' Warning: looks like a The Daily Show video link\n')
      Download(db,
             entry['link'],
             utility.hashtitlesubtitle(title, subtitle),
             'application/x-shockwave-flash',
             title,
             subtitle,
             description,
             date,
             date_parsed,
             out=out)
      done = True

    if not done and entry['link'].startswith('http://teamcoco'):
      if FLAGS.verbose:
        out.write(' Warning: looks like a TeamCoco video link\n')
      Download(db,
             entry['link'],
             utility.hashtitlesubtitle(title, subtitle),
             'application/x-shockwave-flash',
             title,
             subtitle,
             description,
             date,
             date_parsed,
             out=out)
      done = True

      
    # handle xvideos rss feeds
    if not done and (entry['link'].startswith('http://www.xvideos') or entry['link'].startswith('http://www.youporn') or entry['link'].startswith('http://video.xnxx')):
      if FLAGS.verbose:
        out.write(' Warning: looks like a P0rn video link\n')
      Download(db,
             entry['link'],
             utility.hashtitlesubtitle(title, subtitle),
             'application/x-shockwave-flash',
             title,
             subtitle,
             description,
             date,
             date_parsed,
             out=out)
      done = True  
      
    if not done and videos.has_key('text/html'):
      db.Log('Warning: Treating text/html as an video enclosure type for '
             '%s' % utility.hashtitlesubtitle(title, subtitle))
      out.write('    Warning: Treating text/html as an video enclosure from %s for'
                ' %s pointing to %s\n'
                %(repr(videos.keys()), subtitle, videos['text/html']['url']))

      Download(db,
               videos['text/html']['url'],
               utility.hashtitlesubtitle(title, subtitle),
               'text/html',
               title,
               subtitle,
               description,
               date,
               date_parsed,
               out=out)
      done = True

    if not done and videos.has_key('application/x-shockwave-flash'):
      # we now can download vimeo videos
      if videos['application/x-shockwave-flash']['url'].startswith('http://vimeo'):
        Download(db,
                videos['application/x-shockwave-flash']['url'],
                utility.hashtitlesubtitle(title, subtitle),
                'application/x-shockwave-flash',
                title,
                subtitle,
                description,
                date,
                date_parsed,
                out=out)
        done = True
      if not complained_about_swf:
        out.write('%s\n' % repr(videos))
        out.write('Error: SWF is currently unsupported due to ffmpeg and mencoder not supporting compressed SWF files as input. Let [email protected] know if you are aware of an open source way of transcoding these files.\n\n')
        complained_about_swf = True
      done = True

    if not done and len(videos.keys()) == 1:
      # If there is only one attachment, make the rather remarkable
      # assumption that it is a video
      out.write('Assuming that %s is a video format\n'
                % videos.keys()[0])
      Download(db,
               videos[videos.keys()[0]]['url'],
               utility.hashtitlesubtitle(title, subtitle),
               videos.keys()[0],
               title,
               subtitle,
               description,
               date,
               date_parsed,
               out=out)
      done = True

    if not done and videos:
      out.write('Error: Unsure which to prefer from: %s for %s\n  [%s]\n\n'
                %(repr(videos.keys()),
                  subtitle.encode('utf-8'),
                  repr(videos)))

    if not done and FLAGS.verbose:
      out.write('  No downloadable content\n')