1919
2020import 'dart:convert' ;
2121
22+ import 'package:boxbox/classes/video.dart' ;
2223import 'package:boxbox/helpers/constants.dart' ;
2324import 'package:boxbox/helpers/download.dart' ;
25+ import 'package:boxbox/providers/videos/requests.dart' ;
2426import 'package:flutter/foundation.dart' ;
2527import 'package:flutter_cache_manager/file.dart' ;
2628import 'package:flutter_cache_manager/flutter_cache_manager.dart' ;
@@ -43,26 +45,25 @@ class BrightCove {
4345 String videoId, String ? player, String ? articleChampionship) async {
4446 String championship = Hive .box ('settings' )
4547 .get ('championship' , defaultValue: 'Formula 1' ) as String ;
46- late Map responseAsJson;
47- final String f1BrightCovePlayerId = Constants ().F1_BRIGHTCOVE_PLAYER_ID ;
48- final String fEBrightCovePlayerId = Constants ().FE_BRIGHTCOVE_PLAYER_ID ;
48+ Map responseAsJson;
49+ String playerId;
4950 if (kIsWeb) {
5051 late Uri uri;
5152 if (articleChampionship != null ) {
53+ playerId = VideosRequestProvider ().getBrightCovePlayerId (
54+ articleChampionship,
55+ );
5256 uri = Uri .parse (
53- articleChampionship == 'Formula 1'
54- ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId /videos/$videoId '
55- : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId /videos/$videoId ' ,
57+ 'https://edge.api.brightcove.com/playback/v1/accounts/$playerId /videos/$videoId ' ,
5658 );
5759 } else if (player != null ) {
5860 uri = Uri .parse (
5961 'https://edge.api.brightcove.com/playback/v1/accounts/$player /videos/$videoId ' ,
6062 );
6163 } else {
64+ playerId = VideosRequestProvider ().getBrightCovePlayerId (championship);
6265 uri = Uri .parse (
63- championship == 'Formula 1'
64- ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId /videos/$videoId '
65- : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId /videos/$videoId ' ,
66+ 'https://edge.api.brightcove.com/playback/v1/accounts/$playerId /videos/$videoId ' ,
6667 );
6768 }
6869 Response res = await get (
@@ -79,30 +80,28 @@ class BrightCove {
7980 );
8081 responseAsJson = jsonDecode (res.body);
8182 } else {
82- late String url;
83-
83+ String url;
8484 if (articleChampionship != null ) {
85- url = articleChampionship == 'Formula 1'
86- ? 'https://edge.api.brightcove.com/playback/v1/accounts/$f1BrightCovePlayerId /videos/$videoId '
87- : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId /videos/$videoId ' ;
85+ playerId = VideosRequestProvider ().getBrightCovePlayerId (
86+ articleChampionship,
87+ );
88+ url =
89+ 'https://edge.api.brightcove.com/playback/v1/accounts/$playerId /videos/$videoId ' ;
8890 } else if (player != null ) {
8991 url =
9092 'https://edge.api.brightcove.com/playback/v1/accounts/$player /videos/$videoId ' ;
9193 } else {
92- url = championship == 'Formula 1'
93- ? 'https://edge.api.brightcove.com/playback/v1/accounts/$ f1BrightCovePlayerId /videos/$ videoId '
94- : 'https://edge.api.brightcove.com/playback/v1/accounts/$fEBrightCovePlayerId /videos/$videoId ' ;
94+ playerId = VideosRequestProvider (). getBrightCovePlayerId ( championship);
95+ url =
96+ 'https://edge.api.brightcove.com/playback/v1/accounts/$playerId /videos/$videoId ' ;
9597 }
9698 final Future <File > fileStream = videoCache.getSingleFile (
9799 url,
98100 headers: {
99101 'Accept' : articleChampionship != null
100- ? articleChampionship == 'Formula 1'
101- ? Constants ().F1_BRIGHTCOVE_PLAYER_KEY
102- : Constants ().FE_BRIGHTCOVE_PLAYER_KEY
103- : championship == 'Formula 1'
104- ? Constants ().F1_BRIGHTCOVE_PLAYER_KEY
105- : Constants ().FE_BRIGHTCOVE_PLAYER_KEY
102+ ? VideosRequestProvider ()
103+ .getBrightCovePlayerKey (articleChampionship)
104+ : VideosRequestProvider ().getBrightCovePlayerKey (championship)
106105 },
107106 );
108107 final response = await fileStream;
@@ -116,15 +115,21 @@ class BrightCove {
116115 return responseAsJson;
117116 }
118117
119- Future <Map < String , dynamic > > getVideoLinks (String videoId,
118+ Future <VideoDetails > getVideoLinks (String videoId,
120119 {String ? player, String ? articleChampionship}) async {
121120 Map ? fileData = kIsWeb
122121 ? null
123122 : await DownloadUtils ()
124123 .downloadedFilePathAndNameIfExists ('video_f1_${videoId }' );
125124
126125 if (fileData != null ) {
127- return {'file' : fileData['file' ], 'name' : fileData['name' ]};
126+ return VideoDetails (
127+ '' ,
128+ fileData['name' ],
129+ [],
130+ '' ,
131+ localFilePath: fileData['file' ],
132+ );
128133 } else {
129134 int playerQuality =
130135 Hive .box ('settings' ).get ('playerQuality' , defaultValue: 360 ) as int ;
@@ -159,7 +164,12 @@ class BrightCove {
159164 streamUrls['videos' ].add (streamsData['sources' ][0 ]['src' ]);
160165 }
161166 streamUrls['name' ] = streamsData['name' ];
162- return streamUrls;
167+ return VideoDetails (
168+ streamUrls['name' ],
169+ streamUrls['qualities' ],
170+ streamUrls['videos' ],
171+ streamUrls['poster' ],
172+ );
163173 }
164174 }
165175}
0 commit comments