returns the mediatype depending on given metainfos
MEDIA_TYPE_AUDIO if soundfile,
MEDIA_TYPE_VIDEO if videofile,
MEDIA_TYPE_VIDEO_ONLY if videofile without soundstream.
347902
private function getMediaType($metainfo) {
        if (
            $metainfo['audio'] != false &&
            (
                $metainfo['video'] == false ||
                $metainfo['video']['codec_name'] == 'png' ||
                $metainfo['video']['codec_name'] == 'jpg'
            )
        ) {
            return $this::MEDIA_TYPE_AUDIO;
        }

        if ($metainfo['video'] != false && $metainfo['audio'] == false) {
            return $this::MEDIA_TYPE_VIDEO_ONLY;
        }

        if ($metainfo['video'] != false && $metainfo['audio'] != false) {
            return $this::MEDIA_TYPE_VIDEO;
        }
        return $this::MEDIA_TYPE_UNKNOWN;
    }
1202881
private static MediaType parse(String mediaType) {

		Assert.notNullOrEmptyTrimmed(mediaType, "Missing media type!");

		String type = null;
		String subType = null;
		Map<String, String> params = new HashMap<>();

		String[] parts = mediaType.split(";");
		for (int i = 0; i < parts.length; i++) {

			String part = StringUtils.trimToNull(parts[i]);
			if (part == null) {
				continue;
			}

			if (i == 0) {
				// get type and subtype
				String[] typeSubType = part.split("/");
				Assert.isTrue(typeSubType.length == 2, "Missing or invalid type with subType: '" + part + "'");

				type = StringUtils.trimToNull(typeSubType[0]);
				subType = StringUtils.trimToNull(typeSubType[1]);

				Assert.notNull(type, "Missing media type!");
				Assert.notNull(subType, "Missing media sub-type!");

			} else {

				try {
					Pair<String, String> pair = getNameValue(part);
					params.put(pair.getKey(), pair.getValue());
				}
				catch (IllegalArgumentException e) {
					log.warn("Invalid media type option: ", e);
				}
			}
		}

		return new MediaType(type, subType, params);
	}
387471
def filter(self, media_type, **params):
        
        mtype, msubtype = self._split_media_type(media_type)
        for x in self.__iter__():
            # all the params have to match to make the media type valid
            matched = True
            for k, v in params.items():
                if x[2].get(k, None) != v:
                    matched = False
                    break

            if matched:
                if x[0][0] == '*':
                    if x[0][1] == '*':
                        yield x

                    elif x[0][1] == msubtype:
                        yield x

                elif mtype == '*':
                    if msubtype == '*':
                        yield x

                    elif x[0][1] == msubtype:
                        yield x

                elif x[0][0] == mtype:
                    if msubtype == '*':
                        yield x

                    elif x[0][1] == '*':
                        yield x

                    elif x[0][1] == msubtype:
                        yield x
1230438
private function ffprobeHasAudio()
	{
		if (isset($this->metadata['streams']))
		{
			foreach ($this->metadata['streams'] as $streamIndex => $stream)
			{
				if (isset($stream['codec_type']) && $stream['codec_type'] === "audio")
				{
					return $streamIndex;
				}
			}
		}

		return false;
	}
1200926
public MediaType getContentType() {
		String value = getFirst(CONTENT_TYPE);
		return (StringUtils.hasLength(value) ? MediaType.parseMediaType(value) : null);
	}
1162254
static function guessFileTypeFromMimeType($mt, $def = '')
	{
		// for audio, image, videos, this is simple, the Mime type is explicit
		if ( strpos($mt, 'audio/') === 0 )
			return 'audio';
		if ( strpos($mt, 'image/') === 0 )
			return 'image';
		if ( strpos($mt, 'video/') === 0 )
			return 'video';
		
			
		switch ( $mt )
		{
			case 'application/pdf':
				return 'pdf';
			case 'text/html':
				return 'html';
			case 'text/plain':
				return 'text';
			case 'message/rfc822':
				return 'email';
			case 'application/msword':
			case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
			case 'application/vnd.oasis.opendocument.text':
				return 'word';
			case 'application/vnd.ms-excel':
			case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
			case 'application/vnd.oasis.opendocument.spreadsheet':
				return 'excel';
			case 'application/vnd.ms-powerpoint':
			case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
			case 'application/vnd.oasis.opendocument.presentation':
				return 'powerpoint';
			case 'application/zip':
				return 'zip';
			default :
				return $def;
		}
	}
720100
public String getMimeType()
   {
      if (mediaType == null || untrustedAgent)
      {
         return mimeTypeResolver.getMimeType(fileName);
      }

      return mediaType.getType() + "/" + mediaType.getSubtype();
   }
678167
private function getMediaTypes()
    {
        $counter = 1;

        $types = [];
        $types[$counter++] = 'None';
        $types[$counter++] = 'File';
        $types[$counter++] = 'Image';
        $types[$counter++] = 'Video';

        return $types;
    }
1123503
public static MediaType getMediaTypeByExtension(String extension) {
        final String input = EXTENSIONS.get(extension);
        if (input == null) {
            return null;
        }
        return MediaType.parse(input);
    }
244581
def _get_media_category(is_direct_message, file_type):
        
        if is_direct_message:
            prefix = 'dm'
        else:
            prefix = 'tweet'

        if file_type in IMAGE_MIMETYPES:
            if file_type == 'image/gif':
                return prefix + '_gif'
            else:
                return prefix + '_image'
        elif file_type == 'video/mp4':
            return prefix + '_video'
111279
def get_items_of_media_type(self, media_type):
        
        return (item for item in self.items if item.media_type == media_type)
1255481
def detect_mimetype(file_data)
      if file_data.content_type.strip == "application/octet-stream"
        return File.mime_type?(file_data.original_filename)
      else
        return file_data.content_type
      end
    end
1078354
def guess_media_type(filepath):
    """"""
    o = subprocess.check_output(['file', '--mime-type', '-Lb', filepath])
    o = o.strip()
    return o
27823
public boolean mediaIsVideo () {
        String contentType = this.getContentType();
        return contentType != null && this.media != null && contentType.startsWith("video");
    }
724782
def audio_type(hsh)
      if !hsh.nil? && hsh.length
        hsh['mp3'] ? mime_type('mp3') : hsh['m4a'] ? mime_type('m4a') : hsh['ogg'] ? mime_type('ogg') : mime_type('opus')
      end
    end
420736
def get_content_type(self):
        """"""
        ctype = self.part.get_content_type()
        # replace underspecified mime description by a better guess
        if ctype in ['octet/stream', 'application/octet-stream',
                     'application/octetstream']:
            ctype = guess_mimetype(self.get_data())
        return ctype
48732
def content_type(path)
      path = path.downcase
      return 'image/jpeg' if path.end_with?('.jpg')
      return 'image/jpeg' if path.end_with?('.jpeg')
      return 'image/png' if path.end_with?('.png')
      return 'application/json' if path.end_with?('.geojson')
      return 'video/quicktime' if path.end_with?('.mov')
      return 'video/mp4' if path.end_with?('.m4v')
      return 'video/mp4' if path.end_with?('.mp4')
      raise "Unknown content-type for file #{path}"
    end