Quantcast
Viewing all articles
Browse latest Browse all 151235

Revised AdultDVDEmpire plugin

I'm not sure how to get this back into github, so I'm posting it here. This updates the AdultDVDEmpire plugin to handle split scenes; if a file has a scene name embedded in it (like "movie movie - Scene 1 - actress" or "1 - scene name"), the plugin uses the parent directory's name as the movie title and attempts to parse the scene name to standardize it.

Known issues:
- Will probably be trouble if you have single files of scenes that aren't in a directory with the name of the movie
- Couldn't get each file's title to reflect Movie : Scene # : Description; apparently setting the title for one file in a directory sets it for all of them


# AdultDVDEmpire
import re

# URLS
ADE_BASEURL = 'http://www.adultdvdempire.com/'
ADE_SEARCH_MOVIES = ADE_BASEURL + 'SearchTitlesPage.aspx?SearchString=%s'
ADE_MOVIE_INFO = ADE_BASEURL + '%s/'

def Start():
  HTTP.CacheTime = CACHE_1DAY
  HTTP.SetHeader('User-agent', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)')

class ADEAgent(Agent.Movies):
  name = 'Adult DVD Empire'
  languages = [Locale.Language.English]
  primary_provider = True

  def ParseScene(self,title,filename):
    Log("ParseScene: checking " + title)
    # Special case: if the filename has a number in brackets, that's the scene number, but Plex eats it
    # so we have to check the filename rather than title
    result = re.search(r"(\[\d{1,2}\])",filename)
    if result:
       sceneNumber = result.group(1)
       return "Scene " + sceneNumber
       
    # If it's an intro, credits, trailer, etc, use that name
    if re.search(r"(^intro$)",title,re.IGNORECASE):
      return "Intro"

    if re.search(r"(opening\scredits|open\scredits)",title,re.IGNORECASE):
      return "Opening credits"

    if re.search(r"(ending\scredits|end\scredits)",title,re.IGNORECASE):
      return "End credits"

    if re.search(r"^end$",title,re.IGNORECASE):
      return "End"

    if re.search(r"^credits$",title,re.IGNORECASE):
      return "Credits"
    
    result = re.match(r"(s?\d{1,2}\s|scene\s?\d{1,2}|sc?\s?\d{1,2}\s|\[\d{1,2}\])(.*)",title,re.IGNORECASE)
    if result:
      Log("Got scene match: " + result.group(1))
      scene = result.group(1)
      extra = result.group(2)
      # We have S01 or Scene1 or Sc1 or something, get the numbers
      result = re.search(r"(\d+)",scene)
      return "Scene " + scene.strip() + " : " + extra.strip()

    # If the title is in the form "Movie name - Scene XX", get scene name
    result = re.search(r"(.+)\s(scene\s?\d{1,2}|s\d{1,2}|sc\d{1,2})(?:\s|$|,)(.*)",title,re.IGNORECASE)
    if result:
        Log("Got embedded scene number" + result.group(2))
        scene = result.group(2)
        extra = result.group(3)
        result = re.search(r"(\d+)",scene)
        return "Scene " + scene.strip() + " : " + extra.strip()

    return False


  def search(self, results, media, lang):
    title = media.name
    Log("Processing " + title)
    if media.primary_metadata is not None:
      title = media.primary_metadata.title

    if title.startswith('The '):
      if title.count(':'):
        title = title.split(':',1)[0].replace('The ','',1) + ', The:' + title.split(':',1)[1]
      else:
        title = title.replace('The ','',1) + ', The'
    
    sceneName = self.ParseScene(title,media.items[0].parts[0].file.decode('utf-8'))
    if (sceneName):
        Log("Got scene name '" + sceneName + "', using parent dir name")
        file = media.items[0].parts[0].file.decode('utf-8')
        pathList = file.split("/")
        pathList.pop()
        parentPath = pathList.pop()
        Log("Parent path: " + parentPath)
        # We don't want to pass in the year if it's there
        title = re.sub(r'\(\d{4}\)','',parentPath)
        # Replace dots and underscores with spaces
        title = re.sub(r'[\s\.]',' ',title)
        Log("Got title " + title)
        
        # If our title includes metadata, remove it
        result = re.search(r"(.*?)(cheggit|bdrip|dvdrip|xxx\sdvdrip|720|split\s?scene|\(split|xvid)",title,re.IGNORECASE)
        if result:
          Log("Stripping scene info: " + result.group(2))
          title = result.group(1)
          Log("New title: " + title)

        # Special case: if our title has " 1" at the end, trim that
        result = re.search(r"(.*)\s1",title)
        if result:
          Log("Removing trailing '1'")
          title = result.group(1)
          Log("New title: " + title)

    query = String.URLEncode(String.StripDiacritics(title.replace('-','')))

    for movie in HTML.ElementFromURL(ADE_SEARCH_MOVIES % query).xpath('//div[contains(@class,"ListItem_ItemTitle")]/a'):
      curName = movie.text_content().strip()
      curID = movie.get('href').split('/',2)[1]
      score = 100 - Util.LevenshteinDistance(title.lower(), curName.lower())
      if score >= 85:
        if curName.count(', The'):
          curName = 'The ' + curName.replace(', The','',1)
        if curName.count(', A'):
          curName = 'A ' + curName.replace(', A','',1)
        if sceneName:
          # ISSUE: If you set one file's title to hold the scene name, all files in that dir are 
          # affected (you end up with 5 files called "movie : scene 5") 
          #curName = curName + " : " + sceneName
          Log("Setting full title to " + curName)

        results.Append(MetadataSearchResult(id = curID, name = curName, score = score, lang = lang))
    
    results.Sort('score', descending=True)

  def update(self, metadata, media, lang):
    html = HTML.ElementFromURL(ADE_MOVIE_INFO % metadata.id)
    Log("Current metadata title: " + metadata.title)
    Log("Current media title: " + media.title)
    metadata.title = media.title
    
    # Get Thumb and Poster
    try:
      img = html.xpath('//div[@id="ctl00_ContentPlaceHolder_ctl00_pnl_Default"]/a/img[contains(@src,"m.jpg")]')[0]
      thumbUrl = img.get('src')
      thumb = HTTP.Request(thumbUrl)
      posterUrl = img.get('src').replace('m.jpg','h.jpg')
      metadata.posters[posterUrl] = Proxy.Preview(thumb)
    except:
      pass

    # Get tagline
    try: metadata.tagline = html.xpath('//span[@class="Item_InfoTagLine"]')[0].text_content().strip()
    except: pass

    # Summary.
    try:
      metadata.summary = html.xpath('//div[@class="Item_InfoContainer"]')[0].text_content().replace('\t','').strip()
      if metadata.summary.find(metadata.tagline) != -1:
        metadata.summary = metadata.summary.replace(metadata.tagline, '').strip()
    except: pass

    # Other data.
    data = {}
    for div in html.xpath('//div[@class="Item_ProductInfoSectionConatiner"]/div'):
      name, value = div.text_content().split(':')
      data[name.strip()] = value.strip()

    if data.has_key('Rating'):
      metadata.content_rating = data['Rating']

    if data.has_key('Studio'):
      metadata.studio = data['Studio']

    if data.has_key('Release Date'):
      try:
        metadata.originally_available_at = Datetime.ParseDate(data['Release Date']).date()
        metadata.year = metadata.originally_available_at.year
      except: pass

Viewing all articles
Browse latest Browse all 151235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>