# Path: subdownloader/metadata.py
# class MetadataVideoTrack(object):
# class Metadata(object):
# class PyMediaInfoParser(object):
#     def __init__(self, duration_ms, framerate, framecount):
#     def get_framecount(self):
#     def get_framerate(self):
#     def get_duration_ms(self):
#     def __init__(self):
#     def add_metadata(self, metadata):
#     def get_videotracks(self):
#     def __init__(self):
#     def is_available():
#     def parse_path(path):
# def available():
# def parse(path):
# 
# Path: subdownloader/identification.py
# class IdentityCollection(object):
#     def __init__(self):
#         self._data = {}
# 
#     def add_identity(self, identity):
#         provider = identity.provider
#         try:
#             identities = self._data[provider]
#             identities.merge(identity)
#         except KeyError:
#             self._data[provider] = identity
# 
#     def __iter__(self):
#         return iter(self._data.values())
# 
#     def __len__(self):
#         return len(self._data)
# 
#     def __contains__(self, provider):
#         return provider in self._data
# 
#     def iter_video_identity(self):
#         for provider_identity in self:
#             video_identity = provider_identity.video_identity
#             if video_identity is not None:
#                 yield video_identity
# 
#     def iter_imdb_identity(self):
#         for provider_identity in self:
#             imdb_identity = provider_identity.imdb_identity
#             if imdb_identity is not None:
#                 yield imdb_identity
# 
#     def get_merged_video_identity(self):
#         res_video_identity = VideoIdentity(name=None, year=None)
#         for video_identity in self.iter_video_identity():
#             res_video_identity.merge(video_identity)
#         return res_video_identity
# 
#     def get_merged_imdb_identity(self):
#         res_imdb_identity = ImdbIdentity(imdb_id=None, imdb_rating=None)
#         for imdb_identity in self.iter_imdb_identity():
#             res_imdb_identity.merge(imdb_identity)
#         return res_imdb_identity
# 
#     def __repr__(self):
#         return '<IdentityCollection:{!r}>'.format(self._data)
# 
# Path: subdownloader/subtitle2.py
# class SubtitleFileCollection(object):
#     def __init__(self, parent):
#         self._parent = parent
#         self._networks = []
#         self._candidates = []
# 
#     def get_parent(self):
#         return self._parent
# 
#     def get_subtitle_networks(self):
#         return self._networks
# 
#     def add_subtitle(self, subtitle, priority=False):
#         for network in self._networks:
#             if network.equals_subtitle_file(subtitle):
#                 network.add_subtitle(subtitle, priority=priority)
#                 return
#         for candidate in self._candidates:
#             if candidate.equals_subtitle_file(subtitle):
#                 network = SubtitleFileNetwork(parent=self, subtitle_file=subtitle)
#                 network.add_subtitle(candidate.get_subtitles()[0])
#                 if priority:
#                     self._networks.insert(0, network)
#                 else:
#                     self._networks.append(network)
#                 self._candidates.remove(candidate)
#                 return
#         network = SubtitleFileNetwork(parent=self, subtitle_file=subtitle)
#         if priority:
#             self._networks.insert(0, network)
#         else:
#             self._networks.append(network)
# 
#     def add_candidates(self, subtitles):
#         for subtitle in subtitles:
#             for candidate in self._candidates:
#                 if candidate.equals_subtitle_file(subtitle):
#                     candidate.add_subtitle(subtitle, reparent=False)
#                     break
#             new_candidate = SubtitleFileNetwork(parent=self, subtitle_file=subtitle, reparent=False)
#             self._candidates.append(new_candidate)
# 
#     def iter_local_subtitles(self):
#         for network in self._networks:
#             for subtitle in network.iter_local_subtitles():
#                 yield subtitle
# 
#     def get_nb_subtitles(self):
#         return sum(len(network) for network in self._networks)
# 
#     def __len__(self):
#         return len(self._networks)
# 
#     def __getitem__(self, item):
#         return self._networks[item]


import logging
import os
import struct
from subdownloader import metadata
from subdownloader.identification import IdentityCollection
from subdownloader.subtitle2 import SubtitleFileCollection
        Initialize a new local VideoFile
        :param filepath: path of the videofile as string
        """
        log.debug('VideoFile.__init__("{}")'.format(filepath))

        self._filepath = filepath
        if not self._filepath.exists():
            raise NotAVideoException(self._filepath)

        # calculate hash and size on request
        self._size = None
        self._osdb_hash_valid = False
        self._osdb_hash = None

        # Initialize metadata on request.
        self._fps = None
        self._time_ms = None
        self._framecount = None

        self._subtitles = SubtitleFileCollection(parent=self)
        self._identities = IdentityCollection()

    def __repr__(self):
        if self._is_metadata_init():
            meta = '{fps={fps},time_ms={time_ms},framecount={framecount}'.format(
                fps=self._fps, time_ms=self._time_ms, framecount=self._framecount)
        else:
            meta = '<unavailable>'
        return '<Video:path="{path}",size={size},osdb_hash={osdb_hash},metadata={metadata},' \
               '#identities={identities}>'.format(

# Path: subdownloader/metadata.py
# class MetadataVideoTrack(object):
# class Metadata(object):
# class PyMediaInfoParser(object):
#     def __init__(self, duration_ms, framerate, framecount):
#     def get_framecount(self):
#     def get_framerate(self):
#     def get_duration_ms(self):
#     def __init__(self):
#     def add_metadata(self, metadata):
#     def get_videotracks(self):
#     def __init__(self):
#     def is_available():
#     def parse_path(path):
# def available():
# def parse(path):
# 
# Path: subdownloader/identification.py
# class IdentityCollection(object):
#     def __init__(self):
#         self._data = {}
# 
#     def add_identity(self, identity):
#         provider = identity.provider
#         try:
#             identities = self._data[provider]
#             identities.merge(identity)
#         except KeyError:
#             self._data[provider] = identity
# 
#     def __iter__(self):
#         return iter(self._data.values())
# 
#     def __len__(self):
#         return len(self._data)
# 
#     def __contains__(self, provider):
#         return provider in self._data
# 
#     def iter_video_identity(self):
#         for provider_identity in self:
#             video_identity = provider_identity.video_identity
#             if video_identity is not None:
#                 yield video_identity
# 
#     def iter_imdb_identity(self):
#         for provider_identity in self:
#             imdb_identity = provider_identity.imdb_identity
#             if imdb_identity is not None:
#                 yield imdb_identity
# 
#     def get_merged_video_identity(self):
#         res_video_identity = VideoIdentity(name=None, year=None)
#         for video_identity in self.iter_video_identity():
#             res_video_identity.merge(video_identity)
#         return res_video_identity
# 
#     def get_merged_imdb_identity(self):
#         res_imdb_identity = ImdbIdentity(imdb_id=None, imdb_rating=None)
#         for imdb_identity in self.iter_imdb_identity():
#             res_imdb_identity.merge(imdb_identity)
#         return res_imdb_identity
# 
#     def __repr__(self):
#         return '<IdentityCollection:{!r}>'.format(self._data)
# 
# Path: subdownloader/subtitle2.py
# class SubtitleFileCollection(object):
#     def __init__(self, parent):
#         self._parent = parent
#         self._networks = []
#         self._candidates = []
# 
#     def get_parent(self):
#         return self._parent
# 
#     def get_subtitle_networks(self):
#         return self._networks
# 
#     def add_subtitle(self, subtitle, priority=False):
#         for network in self._networks:
#             if network.equals_subtitle_file(subtitle):
#                 network.add_subtitle(subtitle, priority=priority)
#                 return
#         for candidate in self._candidates:
#             if candidate.equals_subtitle_file(subtitle):
#                 network = SubtitleFileNetwork(parent=self, subtitle_file=subtitle)
#                 network.add_subtitle(candidate.get_subtitles()[0])
#                 if priority:
#                     self._networks.insert(0, network)
#                 else:
#                     self._networks.append(network)
#                 self._candidates.remove(candidate)
#                 return
#         network = SubtitleFileNetwork(parent=self, subtitle_file=subtitle)
#         if priority:
#             self._networks.insert(0, network)
#         else:
#             self._networks.append(network)
# 
#     def add_candidates(self, subtitles):
#         for subtitle in subtitles:
#             for candidate in self._candidates:
#                 if candidate.equals_subtitle_file(subtitle):
#                     candidate.add_subtitle(subtitle, reparent=False)
#                     break
#             new_candidate = SubtitleFileNetwork(parent=self, subtitle_file=subtitle, reparent=False)
#             self._candidates.append(new_candidate)
# 
#     def iter_local_subtitles(self):
#         for network in self._networks:
#             for subtitle in network.iter_local_subtitles():
#                 yield subtitle
# 
#     def get_nb_subtitles(self):
#         return sum(len(network) for network in self._networks)
# 
#     def __len__(self):
#         return len(self._networks)
# 
#     def __getitem__(self, item):
#         return self._networks[item]


# Path: subdownloader/video2.py
import logging
import os
import struct
from subdownloader import metadata
from subdownloader.identification import IdentityCollection
from subdownloader.subtitle2 import SubtitleFileCollection

        Initialize a new local VideoFile
        :param filepath: path of the videofile as string
        """
        log.debug('VideoFile.__init__("{}")'.format(filepath))

        self._filepath = filepath
        if not self._filepath.exists():
            raise NotAVideoException(self._filepath)

        # calculate hash and size on request
        self._size = None
        self._osdb_hash_valid = False
        self._osdb_hash = None

        # Initialize metadata on request.
        self._fps = None
        self._time_ms = None
        self._framecount = None

        self._subtitles = SubtitleFileCollection(parent=self)
        self._identities = IdentityCollection()

    def __repr__(self):
        if self._is_metadata_init():
            meta = '{fps={fps},time_ms={time_ms},framecount={framecount}'.format(
                fps=self._fps, time_ms=self._time_ms, framecount=self._framecount)
        else:
            meta = '<unavailable>'
        return '<Video:path="{path}",size={size},osdb_hash={osdb_hash},metadata={metadata},' \
               '#identities={identities}>'.format(

                    path=self._filepath, size=self._size, osdb_hash=self._osdb_hash, metadata=meta,