Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
VLC-iOS
Commits
ecf9eb37
Commit
ecf9eb37
authored
Jun 28, 2014
by
Gleb Pinigin
Browse files
Network: use HEAD method to check availability of subtitles; follow code convention
parent
1d9bf526
Changes
1
Hide whitespace changes
Inline
Side-by-side
Sources/VLCOpenNetworkStreamViewController.m
View file @
ecf9eb37
...
...
@@ -265,37 +265,39 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
-
(
NSString
*
)
_checkURLofSubtitle
:(
NSString
*
)
url
{
NSString
*
S
ubtitleFileExtensions
=
kSupportedSubtitleFileExtensions
;
NSString
*
s
ubtitleFileExtensions
=
kSupportedSubtitleFileExtensions
;
NSCharacterSet
*
characterFilter
=
[
NSCharacterSet
characterSetWithCharactersInString
:
@"
\\
.():$"
];
S
ubtitleFileExtensions
=
[[
S
ubtitleFileExtensions
componentsSeparatedByCharactersInSet
:
characterFilter
]
componentsJoinedByString
:
@""
];
NSArray
*
arraySubtitleFileExtensions
=
[
S
ubtitleFileExtensions
componentsSeparatedByString
:
@"|"
];
s
ubtitleFileExtensions
=
[[
s
ubtitleFileExtensions
componentsSeparatedByCharactersInSet
:
characterFilter
]
componentsJoinedByString
:
@""
];
NSArray
*
arraySubtitleFileExtensions
=
[
s
ubtitleFileExtensions
componentsSeparatedByString
:
@"|"
];
NSString
*
urlTemp
=
[[
url
stringByDeletingPathExtension
]
stringByAppendingString
:
@"."
];
for
(
int
cnt
=
0
;
cnt
<
arraySubtitleFileExtensions
.
count
;
cnt
++
)
{
NSString
*
CheckURL
=
[
urlTemp
stringByAppendingString
:
arraySubtitleFileExtensions
[
cnt
]];
NSURLRequest
*
request
=
[
NSURLRequest
requestWithURL
:[
NSURL
URLWithString
:
CheckURL
]];
NSString
*
checkAddress
=
[
urlTemp
stringByAppendingString
:
arraySubtitleFileExtensions
[
cnt
]];
NSURL
*
checkURL
=
[
NSURL
URLWithString
:
checkAddress
];
NSMutableURLRequest
*
request
=
[
NSMutableURLRequest
requestWithURL
:
checkURL
];
request
.
HTTPMethod
=
@"HEAD"
;
NSURLResponse
*
response
=
nil
;
NSError
*
error
=
nil
;
NSData
*
receivedData
=
[[
NSData
alloc
]
initWithData
:[
NSURLConnection
sendSynchronousRequest
:
request
returningResponse
:
&
response
error
:
&
error
]];
[
NSURLConnection
sendSynchronousRequest
:
request
returningResponse
:
&
response
error
:
nil
];
NSInteger
httpStatus
=
[(
NSHTTPURLResponse
*
)
response
statusCode
];
receivedData
=
nil
;
if
(
httpStatus
==
200
)
{
NSString
*
receivedSub
=
[
NSString
stringWithContentsOfURL
:
[
NSURL
URLWithString
:
C
heckURL
]
encoding
:
NSASCIIStringEncoding
error
:
nil
];
NSString
*
receivedSub
=
[
NSString
stringWithContentsOfURL
:
c
heckURL
encoding
:
NSASCIIStringEncoding
error
:
nil
];
NSArray
*
searchPaths
=
NSSearchPathForDirectoriesInDomains
(
NSCachesDirectory
,
NSUserDomainMask
,
YES
);
NSString
*
directoryPath
=
searchPaths
[
0
];
NSString
*
F
ileSubtitlePath
=
[
directoryPath
stringByAppendingPathComponent
:[
C
heckURL
lastPathComponent
]];
NSString
*
f
ileSubtitlePath
=
[
directoryPath
stringByAppendingPathComponent
:[
c
heckURL
lastPathComponent
]];
NSFileManager
*
fileManager
=
[
NSFileManager
defaultManager
];
if
(
!
[
fileManager
fileExistsAtPath
:
F
ileSubtitlePath
])
{
if
(
!
[
fileManager
fileExistsAtPath
:
f
ileSubtitlePath
])
{
//create local subtitle file
[
fileManager
createFileAtPath
:
F
ileSubtitlePath
contents
:
nil
attributes
:
nil
];
if
(
!
[
fileManager
fileExistsAtPath
:
F
ileSubtitlePath
])
[
fileManager
createFileAtPath
:
f
ileSubtitlePath
contents
:
nil
attributes
:
nil
];
if
(
!
[
fileManager
fileExistsAtPath
:
f
ileSubtitlePath
])
APLog
(
@"file creation failed, no data was saved"
);
}
[
receivedSub
writeToFile
:
FileSubtitlePath
atomically
:
YES
encoding
:
NSUTF8StringEncoding
error
:
nil
];
return
FileSubtitlePath
;
[
receivedSub
writeToFile
:
fileSubtitlePath
atomically
:
YES
encoding
:
NSUTF8StringEncoding
error
:
nil
];
return
fileSubtitlePath
;
}
}
return
nil
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment