def write_local_cutlist(self, uncut_video, intended_app_name, my_rating):
     """ Writes a cutlist file to the instance's local_filename. """
 
     try:                        
         cutlist = open(self.local_filename, 'w')
                                     
         cutlist.writelines([
             "[General]\n",
             "Application=%s\n" % self.app,
             "Version=%s\n" % self.intended_version,
             "comment1=The following parts of the movie will be kept, the rest will be cut out.\n",
             "ApplyToFile=%s\n" % os.path.basename(uncut_video),
             "OriginalFileSizeBytes=%s\n" % str(fileoperations.get_size(uncut_video)),
             "FramesPerSecond=%s\n" % str(self.fps),
             "IntendedCutApplicationName=%s\n" % intended_app_name,
             "IntendedCutApplication=%s\n" % self.intended_app,
             "IntendedCutApplicationVersion=\n",
             "VDUseSmartRendering=%s\n" % str(int(self.smart)),
             "VDSmartRenderingCodecFourCC=0x53444646\n",
             "VDSmartRenderingCodecVersion=0x00000000\n",
             "NoOfCuts=%s\n" % str(len(self.cuts_frames)),
             "comment2=All values are given in seconds.\n",
             "\n",
             "[Info]\n",
             "Author=%s\n" % self.author,
             "RatingByAuthor=%s\n" % str(self.ratingbyauthor),
             "EPGError=%s\n" % str(int(self.wrong_content)),
             "ActualContent=%s\n" % str(self.actualcontent),
             "MissingBeginning=%s\n" % str(int(self.missing_beginning)),
             "MissingEnding=%s\n" % str(int(self.missing_ending)),
             "MissingVideo=0\n",
             "MissingAudio=0\n",
             "OtherError=%s\n" % str(int(self.other_error)),
             "OtherErrorDescription=%s\n" % str(self.othererrordescription),
             "SuggestedMovieName=%s\n" % str(self.suggested_filename),
             "UserComment=%s\n" % str(self.usercomment),
             "\n"
         ])
                   
         for count, (start_frame, duration_frames) in enumerate(self.cuts_frames):
             cutlist.writelines([
                 "[Cut%i]\n" % count,
                 "Start=%f\n" % (start_frame / self.fps),
                 "StartFrame=%i\n" % start_frame,             
                 "Duration=%f\n" % (duration_frames / self.fps),       
                 "DurationFrames=%i\n" % duration_frames,
                 "\n"
             ])
                                                 
     except IOError:
         print "Konnte Cutlist-Datei nicht erstellen: " + filename            
     finally:
         cutlist.close()
Example #2
0
    def write_local_cutlist(self, uncut_video, intended_app_name, my_rating):
        """ Writes a cutlist file to the instance's local_filename. """

        try:
            cutlist = open(self.local_filename, 'w')

            cutlist.writelines([
                "[General]\n", "Application=OTR-Verwaltung\n",
                "Version=%s\n" % self.intended_version,
                "comment1=The following parts of the movie will be kept, the rest will be cut out.\n",
                "ApplyToFile=%s\n" % os.path.basename(uncut_video),
                "OriginalFileSizeBytes=%s\n" %
                str(fileoperations.get_size(uncut_video)),
                "FramesPerSecond=%s\n" % str(self.fps),
                "IntendedCutApplicationName=%s\n" % intended_app_name,
                "IntendedCutApplication=%s\n" % self.intended_app,
                "IntendedCutApplicationVersion=\n",
                "VDUseSmartRendering=%s\n" % str(int(self.smart)),
                "VDSmartRenderingCodecFourCC=0x53444646\n",
                "VDSmartRenderingCodecVersion=0x00000000\n",
                "NoOfCuts=%s\n" % str(len(self.cuts_frames)),
                "comment2=All values are given in seconds.\n", "\n",
                "[Info]\n",
                "Author=%s\n" % self.author,
                "RatingByAuthor=%s\n" % str(self.ratingbyauthor),
                "EPGError=%s\n" % str(int(self.wrong_content)),
                "ActualContent=%s\n" % str(self.actualcontent),
                "MissingBeginning=%s\n" % str(int(self.missing_beginning)),
                "MissingEnding=%s\n" % str(int(self.missing_ending)),
                "MissingVideo=0\n", "MissingAudio=0\n",
                "OtherError=%s\n" % str(int(self.other_error)),
                "OtherErrorDescription=%s\n" % str(self.othererrordescription),
                "SuggestedMovieName=%s\n" % str(self.suggested_filename),
                "UserComment=%s\n" % str(self.usercomment), "\n"
            ])

            for count, (start_frame,
                        duration_frames) in enumerate(self.cuts_frames):
                cutlist.writelines([
                    "[Cut%i]\n" % count,
                    "Start=%f\n" % (start_frame / self.fps),
                    "StartFrame=%i\n" % start_frame,
                    "Duration=%f\n" % (duration_frames / self.fps),
                    "DurationFrames=%i\n" % duration_frames, "\n"
                ])

        except IOError:
            print "Konnte Cutlist-Datei nicht erstellen: " + filename
        finally:
            cutlist.close()
Example #3
0
def download_cutlists(filename,
                      server,
                      choose_cutlists_by,
                      cutlist_mp4_as_hq,
                      error_cb=None,
                      cutlist_found_cb=None):
    """ Downloads all cutlists for the given file. 
            filename            - movie filename
            server              - cutlist server
            choose_cutlists_by  - 0 by size, 1 by name
            cutlist_mp4_as_hq   - 
            error_cb            - callback: an error occurs (message)
            cutlist_found_cb    - callback: a cutlist is found (Cutlist instance)
        
        Returns: error, a list of Cutlist instances    
    """

    llog = logging.getLogger(__name__)
    global extension
    if choose_cutlists_by == 0:  # by size
        size = fileoperations.get_size(filename)
        urls = [
            "%sgetxml.php?ofsb=%s" % (server, str(size)),
            # siehe http://www.otrforum.com/showthread.php?t=59666
            "%sgetxml.php?ofsb=%s" %
            (server, str((size + 2 * 1024**3) % (4 * 1024**3) - 2 * 1024**3))
        ]

    else:  # by name
        if "/" in filename:
            root, extension = os.path.splitext(os.path.basename(filename))
        else:
            root = filename

        if cutlist_mp4_as_hq and extension == '.mp4':
            root += ".HQ"

        urls = ["%sgetxml.php?name=%s" % (server, root)]

    cutlists = []

    for url in urls:
        llog.debug("Download from : {}".format(url))
        try:
            handle = urllib.request.urlopen(url)
        except IOError:
            if error_cb: error_cb("Verbindungsprobleme")
            return "Verbindungsprobleme", None

        try:
            dom_cutlists = xml.dom.minidom.parse(handle)
            handle.close()
            dom_cutlists = dom_cutlists.getElementsByTagName('cutlist')
        except:
            if error_cb: error_cb("Keine Cutlists gefunden")
            return "Keine Cutlists gefunden", None

        for cutlist in dom_cutlists:

            c = Cutlist()

            c.id = __read_value(cutlist, "id")
            c.author = __read_value(cutlist, "author")
            c.ratingbyauthor = __read_value(cutlist, "ratingbyauthor")
            c.rating = __read_value(cutlist, "rating")
            c.ratingcount = __read_value(cutlist, "ratingcount")
            c.countcuts = __read_value(cutlist, "cuts")
            c.actualcontent = __read_value(cutlist, "actualcontent")
            c.usercomment = __read_value(cutlist, "usercomment")
            c.filename = __read_value(cutlist, "filename")
            c.withframes = __read_value(cutlist, "withframes")
            c.withtime = __read_value(cutlist, "withtime")
            c.duration = __read_value(cutlist, "duration")
            c.errors = __read_value(cutlist, "errors")
            c.othererrordescription = __read_value(cutlist,
                                                   "othererrordescription")
            c.downloadcount = __read_value(cutlist, "downloadcount")
            c.autoname = __read_value(cutlist, "autoname")
            c.filename_original = __read_value(cutlist, "filename_original")

            ids = [cutlist.id for cutlist in cutlists]
            if not c.id in ids:
                if cutlist_found_cb: cutlist_found_cb(c)

                cutlists.append(c)

    if len(cutlists) == 0:
        return "Keine Cutlists gefunden", None
    else:
        return None, cutlists
def download_cutlists(filename, server, choose_cutlists_by, cutlist_mp4_as_hq, error_cb=None, cutlist_found_cb=None):    
    """ Downloads all cutlists for the given file. 
            filename            - movie filename
            server              - cutlist server
            choose_cutlists_by  - 0 by size, 1 by name
            cutlist_mp4_as_hq   - 
            error_cb            - callback: an error occurs (message)
            cutlist_found_cb    - callback: a cutlist is found (Cutlist instance)
        
        Returns: error, a list of Cutlist instances    
    """

    if choose_cutlists_by == 0: # by size
        size = fileoperations.get_size(filename)
        urls = ["%sgetxml.php?ofsb=%s" % (server, str(size)),
                # siehe http://www.otrforum.com/showthread.php?t=59666
                "%sgetxml.php?ofsb=%s" % (server, str((size+2*1024**3)%(4*1024**3)- 2*1024**3))]
    
    else: # by name
        if "/" in filename:
            root, extension = os.path.splitext(os.path.basename(filename))
        else:
            root = filename
       
        if cutlist_mp4_as_hq and extension == '.mp4':
            root += ".HQ"
    
        urls = ["%sgetxml.php?name=%s" % (server, root)]

    cutlists = []
    
    for url in urls:
        print "[Cutlists] Download by : %s" % url
        try:
            handle = urllib.urlopen(url)
        except IOError:  
            if error_cb: error_cb("Verbindungsprobleme")
            return "Verbindungsprobleme", None
                       
        try:
            dom_cutlists = xml.dom.minidom.parse(handle)
            handle.close()
            dom_cutlists = dom_cutlists.getElementsByTagName('cutlist')
        except:
            if error_cb: error_cb("Keine Cutlists gefunden")
            return "Keine Cutlists gefunden", None
            
        for cutlist in dom_cutlists:
                                                                                   
            c = Cutlist()

            c.id                        = __read_value(cutlist, "id")
            c.author                    = __read_value(cutlist, "author")
            c.ratingbyauthor            = __read_value(cutlist, "ratingbyauthor")
            c.rating                    = __read_value(cutlist, "rating")
            c.ratingcount               = __read_value(cutlist, "ratingcount")
            c.countcuts                 = __read_value(cutlist, "cuts")
            c.actualcontent             = __read_value(cutlist, "actualcontent")
            c.usercomment               = __read_value(cutlist, "usercomment")
            c.filename                  = __read_value(cutlist, "filename")
            c.withframes                = __read_value(cutlist, "withframes")
            c.withtime                  = __read_value(cutlist, "withtime")
            c.duration                  = __read_value(cutlist, "duration")
            c.errors                    = __read_value(cutlist, "errors")
            c.othererrordescription     = __read_value(cutlist, "othererrordescription")
            c.downloadcount             = __read_value(cutlist, "downloadcount")
            c.autoname                  = __read_value(cutlist, "autoname")
            c.filename_original         = __read_value(cutlist, "filename_original")

            ids = [cutlist.id for cutlist in cutlists]
            if not c.id in ids:
                if cutlist_found_cb: cutlist_found_cb(c)
                   
                cutlists.append(c)

    if len(cutlists) == 0:
        return "Keine Cutlists gefunden", None
    else:
        return None, cutlists