Permalink
Browse files

Fix Trailer scrapers

  • Loading branch information...
1 parent 22ba643 commit b9757aae93a606a6479a8113c5b2b6c72c45cb42 @Giftie committed Mar 19, 2013
@@ -4,29 +4,24 @@
Apple Movie Trailers current trailers scraper
"""
-import sys
-import os
-
-import xbmc
-import xbmcaddon
-import time
-import re
-import urllib
+import os, sys, time, re, urllib, traceback
from random import shuffle, random
from xml.sax.saxutils import unescape
+import xbmc
+
#__useragent__ = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
__useragent__ = "QuickTime/7.6.5 (qtver=7.6.5;os=Windows NT 5.1Service Pack 3)"
#__useragent__ = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.6"
-_A_ = xbmcaddon.Addon('script.cinema.experience')
-_L_ = _A_.getLocalizedString
class _urlopener( urllib.FancyURLopener ):
version = __useragent__
# set for user agent
urllib._urlopener = _urlopener()
-BASE_CURRENT_SOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
+BASE_CACHE_PATH = sys.modules["__main__"].BASE_CACHE_PATH
+BASE_RESOURCE_PATH = sys.modules["__main__"].BASE_RESOURCE_PATH
+BASE_CURRENT_SOURCE_PATH = sys.modules["__main__"].BASE_CURRENT_SOURCE_PATH
class _Parser:
"""
@@ -59,6 +54,7 @@ def _parse_source( self, xmlSource ):
# randomize the trailers and create our play list
shuffle( movies )
# enumerate thru the movies list and gather info
+ print movies
for id, movie in movies:
# user preference to skip watch trailers
if ( self.settings[ "trailer_unwatched_only" ] and id in self.watched ):
@@ -83,15 +79,35 @@ def _parse_source( self, xmlSource ):
poster = re.findall( "<poster>(.*?)</poster>", movie )
preview = re.findall( "<preview>(.*?)</preview>", movie )
# set our info
- title = unicode( unescape( re.findall( "<title>(.*?)</title>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
- runtime = re.findall( "<runtime>(.*?)</runtime>", info[ 0 ] )[ 0 ]
- studio = unicode( unescape( re.findall( "<studio>(.*?)</studio>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
+ try:
+ title = unicode( unescape( re.findall( "<title>(.*?)</title>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
+ except:
+ traceback.print_exc()
+ title = ""
+ print info[ 0 ]
+ try:
+ runtime = re.findall( "<runtime>(.*?)</runtime>", info[ 0 ] )[ 0 ]
+ except:
+ traceback.print_exc()
+ runtime = ""
+ print info[ 0 ]
+ try:
+ studio = unicode( unescape( re.findall( "<studio>(.*?)</studio>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
+ except:
+ traceback.print_exc()
+ studio = ""
+ print info[ 0 ]
#postdate = ""
#tmp_postdate = re.findall( "<postdate>(.*?)</postdate>", info[ 0 ] )[ 0 ]
#if ( tmp_postdate ):
# postdate = "%s-%s-%s" % ( tmp_postdate[ 8 : ], tmp_postdate[ 5 : 7 ], tmp_postdate[ : 4 ], )
- releasedate = re.findall( "<releasedate>(.*?)</releasedate>", info[ 0 ] )[ 0 ]
- if ( not releasedate ):
+ try:
+ releasedate = re.findall( "<releasedate>(.*?)</releasedate>", info[ 0 ] )[ 0 ]
+ if ( not releasedate ):
+ releasedate = ""
+ except:
+ traceback.print_exc()
+ print info[ 0 ]
releasedate = ""
#copyright = unicode( unescape( re.findall( "<copyright>(.*?)</copyright>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
director = unicode( unescape( re.findall( "<director>(.*?)</director>", info[ 0 ] )[ 0 ] ), encoding, "replace" )
@@ -111,22 +127,22 @@ def _parse_source( self, xmlSource ):
# trailer
trailer = re.findall( "<large[^>]*>(.*?)</large>", preview[ 0 ] )[ 0 ]
# replace with 1080p if quality == 1080p
- if ( self.settings[ "trailer_quality" ] == 3 ):
+ if ( self.settings[ "trailer_quality" ] == "1080p" ):
trailer = trailer.replace( "a720p.m4v", "h1080p.mov" )
# add user agent to url
trailer += "|User-Agent=%s" % ( urllib.quote_plus( __useragent__ ), )
# size
#size = long( re.findall( "filesize=\"([0-9]*)", preview[ 0 ] )[ 0 ] )
# add the item to our media list
- self.trailers += [ ( id, title, trailer, poster, plot, runtime, mpaa, releasedate, studio, genre, _L_( 32605 ), director, ) ]
+ self.trailers += [ ( id, title, trailer, poster, plot, runtime, mpaa, releasedate, studio, genre, "Movie Trailer", director, ) ]
# increment counter
count += 1
# if we have enough exit
if ( count == self.settings[ "trailer_count" ] ):
break
except:
# oops print error message
- print "ERROR: %s::%s (%d) - %s" % ( self.__class__.__name__, sys.exc_info()[ 2 ].tb_frame.f_code.co_name, sys.exc_info()[ 2 ].tb_lineno, sys.exc_info()[ 1 ], )
+ traceback.print_exc()
class Main:
@@ -7,26 +7,24 @@
"""
# TODO: add watched.xml to skip watched trailers
-import os, sys, re
+import os, sys, time, re, urllib
+from random import shuffle, random
+from xml.sax.saxutils import unescape
+
import xbmc
-from random import shuffle
-import xbmcaddon
logmessage = "[ " + __scriptID__ + " ] - [ " + __modname__ + " ]"
-_A_ = xbmcaddon.Addon( __scriptID__ )
-_L_ = _A_.getLocalizedString
-trailer_settings = sys.modules[ "__main__" ].trailer_settings
-BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
-
+trailer_settings = sys.modules[ "__main__" ].trailer_settings
+BASE_CACHE_PATH = sys.modules[ "__main__" ].BASE_CACHE_PATH
+BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_RESOURCE_PATH
+BASE_CURRENT_SOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
from folder import dirEntries
from ce_playlist import _set_trailer_info
class Main:
xbmc.log("%s - Local Folder Trailer Scraper Started" % logmessage, level=xbmc.LOGNOTICE )
- # base paths
- BASE_CURRENT_SOURCE_PATH = BASE_RESOURCE_PATH
-
+
def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
self.mpaa = equivalent_mpaa
self.genre = genre.replace( "Sci-Fi", "Science Fiction" ).replace( "Action", "Action and ADV" ).replace( "Adventure", "ACT and Adventure" ).replace( "ACT", "Action" ).replace( "ADV", "Adventure" ).split( " / " )
@@ -87,9 +85,9 @@ def _get_watched( self ):
try:
# base path to watched file
if int( self.settings[ "trailer_play_mode" ] )== 1:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
else:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
# open path
usock = open( base_path, "r" )
# read source
@@ -102,9 +100,9 @@ def _get_watched( self ):
def _reset_watched( self ):
xbmc.log("%s - Resetting Watched List" % logmessage, level=xbmc.LOGNOTICE )
if int( self.settings[ "trailer_play_mode" ] )== 1:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
else:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
if ( os.path.isfile( base_path ) ):
os.remove( base_path )
self.watched = []
@@ -114,9 +112,9 @@ def _save_watched( self ):
try:
# base path to watched file
if int( self.settings[ "trailer_play_mode" ] )== 1:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, "downloader" + "_watched.txt" )
else:
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
# if the path to the source file does not exist create it
if ( not os.path.isdir( os.path.dirname( base_path ) ) ):
os.makedirs( os.path.dirname( base_path ) )
@@ -6,38 +6,35 @@
XBMC Movie Library Trailer Scraper
"""
-import sys
-import os
-import xbmcaddon
-import xbmc
-
-from random import shuffle
-from urllib import quote_plus
-import datetime, traceback
+import os, sys, time, re, urllib, traceback, datetime
+from random import shuffle, random
+from xml.sax.saxutils import unescape
if sys.version_info < (2, 7):
import simplejson
else:
import json as simplejson
+import xbmc
+
logmessage = "[ " + __scriptID__ + " ] - [ " + __modname__ + " ]"
-_A_ = xbmcaddon.Addon('script.cinema.experience')
-_L_ = _A_.getLocalizedString
-trailer_settings = sys.modules[ "__main__" ].trailer_settings
-BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
+
+trailer_settings = sys.modules[ "__main__" ].trailer_settings
+BASE_CACHE_PATH = sys.modules[ "__main__" ].BASE_CACHE_PATH
+BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_RESOURCE_PATH
+BASE_CURRENT_SOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
from ce_playlist import _get_thumbnail, _get_trailer_thumbnail
-unwatched_movie_only = True
-__useragent__ = "QuickTime/7.2 (qtver=7.2;os=Windows NT 5.1Service Pack 3)"
+from utils import list_to_string
+__useragent__ = "QuickTime/7.2 (qtver=7.2;os=Windows NT 5.1Service Pack 3)"
class Main:
xbmc.log( "%s - XBMC Movie Library Trailer Scraper" % logmessage, level=xbmc.LOGNOTICE )
- BASE_CURRENT_SOURCE_PATH = BASE_RESOURCE_PATH
-
+
def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
self.settings = settings
if settings['trailer_limit_mpaa']:
- self.mpaa = "Rated %s" % mpaa
+ self.mpaa = mpaa
else:
self.mpaa = ""
if settings['trailer_limit_genre'] and settings['trailer_rating'] == '--':
@@ -67,16 +64,28 @@ def fetch_trailers( self ):
# shorten MPAA/BBFC ratings
if trailer_rating == "":
trailer_rating = "NR"
- elif trailer_rating.startswith("Rated"):
+ #MPAA
+ if trailer_rating.startswith("Rated"):
trailer_rating = trailer_rating.split( " " )[ 1 - ( len( trailer_rating.split( " " ) ) == 1 ) ]
trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "G", "PG", "PG-13", "R", "NC-17", "Unrated", ) ]
+ #BBFC
elif trailer_rating.startswith("UK"):
- trailer_rating = trailer_rating.split( ":" )[ 1 - ( len( trailer_rating.split( ":" ) ) == 1 ) ]
+ if trailer_rating.startswith( "UK:" ):
+ trailer_rating = trailer_rating.split( ":" )[ 1 - ( len( trailer_rating.split( ":" ) ) == 1 ) ]
+ else:
+ trailer_rating = trailer_rating.split( " " )[ 1 - ( len( trailer_rating.split( " " ) ) == 1 ) ]
trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
+ elif trailer_rating.startswith("FSK"):
+ if trailer_rating.startswith( "FSK:" ):
+ trailer_rating = trailer_rating.split( ":" )[ 1 - ( len( trailer_rating.split( ":" ) ) == 1 ) ]
+ else:
+ trailer_rating = trailer_rating.split( " " )[ 1 - ( len( trailer_rating.split( " " ) ) == 1 ) ]
else:
- trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
+ trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "0", "6", "12", "12A", "PG", "15", "16", "18", "R18", "MA", "U", ) ]
# add trailer to our final list
- if not trailer['trailer'].startswith( 'plugin://' ) and self.settings['trailer_skip_youtube'] :
+ if trailer['trailer'].startswith( 'plugin://' ) and not self.settings['trailer_skip_youtube']:
+ continue
+ else:
trailer_info = ( xbmc.getCacheThumbName( trailer['trailer'] ), # id
trailer['label'], # title
trailer['trailer'], # trailer
@@ -86,7 +95,7 @@ def fetch_trailers( self ):
trailer_rating, # mpaa
'', # release date
'', # studio
- trailer['genre'], # genre
+ list_to_string( trailer['genre'] ), # genre
'Trailer', # writer
'', # director 32613
)
@@ -98,14 +107,19 @@ def fetch_trailers( self ):
# if we have enough exit
if count == self.settings[ "trailer_count" ]:
break
+ else:
+ xbmc.log( "No Movie Trailers found", level=xbmc.LOGNOTICE )
self._save_watched()
return self.trailers
+ else:
+ xbmc.log( "No results found", level=xbmc.LOGNOTICE )
+ return []
def _get_watched( self ):
xbmc.log("%s - Getting Watched List" % logmessage, level=xbmc.LOGNOTICE )
try:
# base path to watched file
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
# open path
usock = open( base_path, "r" )
# read source
@@ -117,7 +131,7 @@ def _get_watched( self ):
def _reset_watched( self ):
xbmc.log("%s - Resetting Watched List" % logmessage, level=xbmc.LOGNOTICE )
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
if os.path.isfile( base_path ):
os.remove( base_path )
self.watched = []
@@ -126,7 +140,7 @@ def _save_watched( self ):
xbmc.log("%s - Saving Watched List" % logmessage, level=xbmc.LOGNOTICE )
try:
# base path to watched file
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] +"_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] +"_watched.txt" )
# if the path to the source file does not exist create it
if not os.path.isdir( os.path.dirname( base_path ) ):
os.makedirs( os.path.dirname( base_path ) )

0 comments on commit b9757aa

Please sign in to comment.