本文整理汇总了C#中WebMediaType类的典型用法代码示例。如果您正苦于以下问题:C# WebMediaType类的具体用法?C# WebMediaType怎么用?C# WebMediaType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebMediaType类属于命名空间,在下文中一共展示了WebMediaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Download
public ActionResult Download(WebMediaType type, string item)
{
// Create URL to GetMediaItem
Log.Debug("User wants to download type={0}; item={1}", type, item);
var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
queryString["clientDescription"] = String.Format("WebMediaPortal download (user {0})", HttpContext.User.Identity.Name);
queryString["type"] = ((int)type).ToString();
queryString["itemId"] = item;
string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
UriBuilder fullUri = new UriBuilder(fullUrl);
// If we connect to the services at localhost, actually give the extern IP address to users
if (NetworkInformation.IsLocalAddress(fullUri.Host, false))
fullUri.Host = NetworkInformation.GetIPAddress(false);
// Do the actual streaming
if (GetStreamMode() == StreamType.Proxied)
{
Log.Debug("Proxying download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeStreaming();
ProxyStream(fullUri.ToString());
}
else if (GetStreamMode() == StreamType.Direct)
{
Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
return Redirect(fullUri.ToString());
}
return new EmptyResult();
}
示例2: ArtworkImplementation
private static string ArtworkImplementation(this UrlHelper helper, WebMediaType mediaType, string id, Func<string, string, RouteValueDictionary, string> actionMethod)
{
switch (mediaType)
{
case WebMediaType.Movie:
return actionMethod("Cover", "MovieLibrary", new RouteValueDictionary(new { movie = id }));
case WebMediaType.MusicAlbum:
return actionMethod("AlbumImage", "MusicLibrary", new RouteValueDictionary(new { album = id }));
case WebMediaType.MusicArtist:
return actionMethod("ArtistImage", "MusicLibrary", new RouteValueDictionary(new { artist = id }));
case WebMediaType.MusicTrack:
return actionMethod("TrackImage", "MusicLibrary", new RouteValueDictionary(new { track = id }));
case WebMediaType.Radio:
case WebMediaType.TV:
return actionMethod("ChannelLogo", "Television", new RouteValueDictionary(new { channelId = id }));
case WebMediaType.Recording:
// TODO: Make width configurable with a parameter (object attributes or something like it)
return actionMethod("PreviewImage", "Recording", new RouteValueDictionary(new { id = id, width = 640 }));
case WebMediaType.TVEpisode:
return actionMethod("EpisodeImage", "TVShowsLibrary", new RouteValueDictionary(new { episode = id }));
case WebMediaType.TVSeason:
return actionMethod("SeasonImage", "TVShowsLibrary", new RouteValueDictionary(new { season = id }));
case WebMediaType.TVShow:
return actionMethod("SeriesPoster", "TVShowsLibrary", new RouteValueDictionary(new { season = id }));
default:
return String.Empty;
}
}
示例3: GetMediaName
public static string GetMediaName(WebMediaType type, string id)
{
try
{
switch (type)
{
case WebMediaType.Movie:
return Connections.Current.MAS.GetMovieDetailedById(Settings.ActiveSettings.MovieProvider, id).Title;
case WebMediaType.MusicAlbum:
return Connections.Current.MAS.GetMusicAlbumBasicById(Settings.ActiveSettings.MusicProvider, id).Title;
case WebMediaType.MusicTrack:
return Connections.Current.MAS.GetMusicTrackDetailedById(Settings.ActiveSettings.MusicProvider, id).Title;
case WebMediaType.Recording:
return Connections.Current.TAS.GetRecordingById(Int32.Parse(id)).Title;
case WebMediaType.TV:
return Connections.Current.TAS.GetChannelDetailedById(Int32.Parse(id)).Title;
case WebMediaType.TVEpisode:
return Connections.Current.MAS.GetTVEpisodeDetailedById(Settings.ActiveSettings.TVShowProvider, id).Title;
case WebMediaType.TVShow:
return Connections.Current.MAS.GetTVShowDetailedById(Settings.ActiveSettings.TVShowProvider, id).Title;
case WebMediaType.TVSeason:
default:
return "";
}
}
catch (Exception ex)
{
Log.Warn("Could not load display name of media", ex);
}
return "";
}
示例4: MediaSource
public MediaSource(WebMediaType type, int? provider, string id)
{
this.MediaType = (WebStreamMediaType)type;
this.Id = id;
this.Offset = 0;
this.Provider = provider;
}
示例5: GetExternalMediaInfo
public SerializableDictionary<string> GetExternalMediaInfo(WebMediaType type, string id)
{
return new SerializableDictionary<string>()
{
{ "Type", "file" },
{ "Path", GetFileBasic(id).Path.First() }
};
}
示例6: Download
//
// Streaming
public ActionResult Download(WebMediaType type, string item, string token = null)
{
// Check authentication
if (!IsUserAuthenticated())
{
string expectedData = String.Format("{0}_{1}_{2}", type, item, HttpContext.Application["randomToken"]);
byte[] expectedBytes = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(expectedData));
string expectedToken = expectedBytes.ToHexString();
if (token == null || expectedToken != token)
{
Log.Error("Denying download type={0}, item={1}, token={2}, ip={3}: user is not logged in and token is invalid", type, item, token, Request.UserHostAddress);
return new HttpUnauthorizedResult();
}
}
// Create URL to GetMediaItem
Log.Debug("User wants to download type={0}; item={1}", type, item);
var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
var userDescription = !String.IsNullOrEmpty(HttpContext.User.Identity.Name) ? String.Format(" (user {0})", HttpContext.User.Identity) :
// TODO: also grab the user from the Authorization header here
!String.IsNullOrEmpty(token) ? " (token-based download)" : String.Empty;
queryString["clientDescription"] = "WebMediaPortal download" + userDescription;
queryString["type"] = ((int)type).ToString();
queryString["itemId"] = item;
string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
UriBuilder fullUri = new UriBuilder(fullUrl);
// If we can access the file without any problems, let IIS stream it; that is a lot faster
if (NetworkInformation.IsLocalAddress(fullUri.Host) && type != WebMediaType.TV)
{
var path = type == WebMediaType.Recording ?
Connections.Current.TAS.GetRecordingFileInfo(Int32.Parse(item)).Path :
Connections.Current.MAS.GetMediaItem(GetProvider(type), type, item).Path[0];
if (System.IO.File.Exists(path))
return File(path, MIME.GetFromFilename(path, "application/octet-stream"), Path.GetFileName(path));
}
// If we connect to the services at localhost, actually give the extern IP address to users
if (NetworkInformation.IsLocalAddress(fullUri.Host))
fullUri.Host = NetworkInformation.GetIPAddressForUri();
// Do the actual streaming
if (GetStreamMode() == StreamType.Proxied)
{
Log.Debug("Proxying download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeStreaming();
ProxyStream(fullUri.ToString());
}
else if (GetStreamMode() == StreamType.Direct)
{
Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
return Redirect(fullUri.ToString());
}
return new EmptyResult();
}
示例7: GetDownloadArguments
public object GetDownloadArguments(WebMediaType mediaType, string itemId)
{
return new
{
item = itemId,
type = mediaType,
token = GenerateDownloadToken(mediaType, itemId)
};
}
示例8: GetExternalMediaInfo
public SerializableDictionary<string> GetExternalMediaInfo(WebMediaType type, string id)
{
string path = GetFileBasic(id).Path.First();
return new SerializableDictionary<string>()
{
{ "Type", File.Exists(path) ? "file" : "folder" },
{ "Path", path },
{ "Extensions", ".*" }
};
}
示例9: AddPlaylistItems
public WebBoolResult AddPlaylistItems(int? provider, string playlistId, WebMediaType type, int? position, string ids)
{
IList<WebPlaylistItem> playlist = GetAllPlaylistItems(provider, playlistId).Finalize(provider, type);
int pos = position != null ? (int)position : playlist.Count - 1;
string[] splitIds = ids.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < splitIds.Length; i++)
{
AddPlaylistItemToPlaylist(provider, splitIds[i], pos + i, playlist);
}
return PlaylistLibraries[provider].SavePlaylist(playlistId, playlist);
}
示例10: Download
public Stream Download(string clientDescription, WebMediaType type, int? provider, string itemId, long? position)
{
// validate source first
MediaSource source = new MediaSource(type, provider, itemId);
if (!source.Exists)
{
throw new FileNotFoundException();
}
// create context
DownloadContext context = new DownloadContext()
{
ClientDescription = clientDescription,
Source = source,
StartTime = DateTime.Now,
Stream = new ReadTrackingStreamWrapper(source.Retrieve()),
MediaInfo = MediaInfoHelper.LoadMediaInfoOrSurrogate(source) // for playerposition view
};
// seek to start position if wanted/needed
if (position != null && position > 0)
{
if (context.Stream.CanSeek)
{
context.Stream.Seek(position.Value, SeekOrigin.Begin);
}
else
{
Log.Warn("Download: Cannot seek on stream, failed to set start position to {0}", position);
}
}
// see comment in Streaming.cs:151
string realIp = WCFUtil.GetHeaderValue("forwardedFor", "X-Forwarded-For");
context.ClientIP = realIp == null ? WCFUtil.GetClientIPAddress() : String.Format("{0} (via {1})", realIp, WCFUtil.GetClientIPAddress());
// set headers for downloading
WCFUtil.AddHeader("Content-Disposition", "attachment; filename=\"" + source.GetFileInfo().Name + "\"");
if (source.MediaType != WebMediaType.TV)
WCFUtil.SetContentLength(source.GetFileInfo().Size);
// FIXME: there has to be a better way to do this
string mime = MIME.GetFromFilename(source.GetFileInfo().Name);
if (mime != null)
{
WCFUtil.SetContentType(mime);
}
// finally, save the context and return
runningDownloads.Add(context);
return context.Stream;
}
示例11: AddPlaylistItem
public WebBoolResult AddPlaylistItem(int? provider, string playlistId, WebMediaType type, string id, int? position)
{
IList<WebPlaylistItem> playlist = GetAllPlaylistItems(provider, playlistId).Finalize(provider, type);
if (AddPlaylistItemToPlaylist(provider, id, position, playlist))
{
return PlaylistLibraries[provider].SavePlaylist(playlistId, playlist);
}
else
{
return false;
}
}
示例12: MediaSource
public MediaSource(WebMediaType type, int? provider, string id, WebFileType filetype, int offset)
{
this.MediaType = type;
this.Id = id;
this.Provider = provider;
this.Offset = offset;
this.FileType = filetype;
if (!CheckArguments(type, filetype))
{
throw new ArgumentException("Invalid combination of mediatype and filetype");
}
}
示例13: ReturnFromService
public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, int maxWidth, int maxHeight, string defaultFile = null)
{
IStreamingService service;
int? provider = null;
switch (mediaType)
{
case WebMediaType.Drive:
case WebMediaType.File:
case WebMediaType.Folder:
service = Connections.Current.MASStream;
provider = Settings.ActiveSettings.FileSystemProvider;
break;
case WebMediaType.Movie:
service = Connections.Current.MASStream;
provider = Settings.ActiveSettings.MovieProvider;
break;
case WebMediaType.MusicAlbum:
case WebMediaType.MusicArtist:
case WebMediaType.MusicTrack:
service = Connections.Current.MASStream;
provider = Settings.ActiveSettings.MusicProvider;
break;
case WebMediaType.Picture:
service = Connections.Current.MASStream;
provider = Settings.ActiveSettings.PicturesProvider;
break;
case WebMediaType.TVShow:
case WebMediaType.TVSeason:
case WebMediaType.TVEpisode:
service = Connections.Current.MASStream;
provider = Settings.ActiveSettings.TVShowProvider;
break;
case WebMediaType.TV:
service = Connections.Current.TASStream;
break;
case WebMediaType.Recording:
service = Connections.Current.TASStream;
return ReturnFromService(service, () => service.ExtractImageResized(mediaType, provider, id, 15, maxWidth, maxHeight), defaultFile);
default:
throw new ArgumentException("Tried to load image for unknown mediatype " + mediaType);
}
string etag = String.Format("{0}_{1}_{2}_{3}_{4}_{5}", mediaType, provider, id, artworkType, maxWidth, maxHeight);
return ReturnFromService(service, () => service.GetArtworkResized(mediaType, provider, id, artworkType, 0, maxWidth, maxHeight), defaultFile, etag);
}
示例14: Download
public ActionResult Download(WebMediaType type, string item)
{
// Create URL to GetMediaItem
Log.Debug("User wants to download type={0}; item={1}", type, item);
var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
queryString["clientDescription"] = String.Format("WebMediaPortal download (user {0})", HttpContext.User.Identity.Name);
queryString["type"] = ((int)type).ToString();
queryString["itemId"] = item;
string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
UriBuilder fullUri = new UriBuilder(fullUrl);
// If we can access the file without any problems, let IIS stream it; that is a lot faster
if (NetworkInformation.IsLocalAddress(fullUri.Host, false) && type != WebMediaType.TV)
{
var path = type == WebMediaType.Recording ?
Connections.Current.TAS.GetRecordingFileInfo(Int32.Parse(item)).Path :
Connections.Current.MAS.GetMediaItem(GetProvider(type), type, item).Path[0];
if (System.IO.File.Exists(path))
return File(path, MIME.GetFromFilename(path, "application/octet-stream"), Path.GetFileName(path));
}
// If we connect to the services at localhost, actually give the extern IP address to users
if (NetworkInformation.IsLocalAddress(fullUri.Host, false))
fullUri.Host = NetworkInformation.GetIPAddress(false);
// Do the actual streaming
if (GetStreamMode() == StreamType.Proxied)
{
Log.Debug("Proxying download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeStreaming();
ProxyStream(fullUri.ToString());
}
else if (GetStreamMode() == StreamType.Direct)
{
Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
return Redirect(fullUri.ToString());
}
return new EmptyResult();
}
示例15: IsLocalFile
public WebBoolResult IsLocalFile(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
{
WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset);
return info.Exists && info.IsLocalFile;
}