@@ -17,12 +17,16 @@ namespace Orchard.MediaLibrary.Controllers {
17
17
[ Admin , Themed ( false ) ]
18
18
public class OEmbedController : Controller {
19
19
private readonly IMediaLibraryService _mediaLibraryService ;
20
+ private readonly IOEmbedService _oEmbedService ;
20
21
21
22
public OEmbedController (
22
23
IOrchardServices services ,
23
- IMediaLibraryService mediaManagerService ) {
24
- _mediaLibraryService = mediaManagerService ;
24
+ IMediaLibraryService mediaManagerService ,
25
+ IOEmbedService oEmbedService ) {
26
+
25
27
Services = services ;
28
+ _mediaLibraryService = mediaManagerService ;
29
+ _oEmbedService = oEmbedService ;
26
30
T = NullLocalizer . Instance ;
27
31
}
28
32
@@ -78,39 +82,9 @@ public ActionResult IndexPOST(string folderPath, string url, string type, string
78
82
}
79
83
}
80
84
81
- var webClient = new WebClient { Encoding = Encoding . UTF8 } ;
82
85
try {
83
- // <link rel="alternate" href="http://vimeo.com/api/oembed.xml?url=http%3A%2F%2Fvimeo.com%2F23608259" type="text/xml+oembed">
84
-
85
- var source = webClient . DownloadString ( url ) ;
86
+ viewModel . Content = _oEmbedService . DownloadMediaData ( url ) ;
86
87
87
- // seek type="text/xml+oembed" or application/xml+oembed
88
- var oembedSignature = source . IndexOf ( "type=\" text/xml+oembed\" " , StringComparison . OrdinalIgnoreCase ) ;
89
- if ( oembedSignature == - 1 ) {
90
- oembedSignature = source . IndexOf ( "type=\" application/xml+oembed\" " , StringComparison . OrdinalIgnoreCase ) ;
91
- }
92
- if ( oembedSignature != - 1 ) {
93
- var tagStart = source . Substring ( 0 , oembedSignature ) . LastIndexOf ( '<' ) ;
94
- var tagEnd = source . IndexOf ( '>' , oembedSignature ) ;
95
- var tag = source . Substring ( tagStart , tagEnd - tagStart ) ;
96
- var matches = new Regex ( "href=\" ([^\" ]+)\" " ) . Matches ( tag ) ;
97
- if ( matches . Count > 0 ) {
98
- var href = matches [ 0 ] . Groups [ 1 ] . Value ;
99
- try {
100
- var content = webClient . DownloadString ( Server . HtmlDecode ( href ) ) ;
101
- viewModel . Content = XDocument . Parse ( content ) ;
102
- }
103
- catch {
104
- // bubble exception
105
- }
106
- }
107
- }
108
- if ( viewModel . Content == null ) {
109
- viewModel . Content = new XDocument (
110
- new XDeclaration ( "1.0" , "utf-8" , "yes" ) ,
111
- new XElement ( "oembed" )
112
- ) ;
113
- }
114
88
var root = viewModel . Content . Root ;
115
89
if ( ! String . IsNullOrWhiteSpace ( url ) ) {
116
90
root . El ( "url" , url ) ;
0 commit comments