| 1 | /***************************************************************************** |
| 2 | ** QNapi |
| 3 | ** Copyright (C) 2008-2017 Piotr KrzemiĆski <[email protected]> |
| 4 | ** |
| 5 | ** This program is free software; you can redistribute it and/or modify |
| 6 | ** it under the terms of the GNU General Public License as published by |
| 7 | ** the Free Software Foundation; either version 2 of the License, or |
| 8 | ** (at your option) any later version. |
| 9 | ** |
| 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
| 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | ** |
| 13 | *****************************************************************************/ |
| 14 | |
| 15 | #include "libmediainfomovieinfoprovider.h" |
| 16 | #include <QRegExp> |
| 17 | #include <string> |
| 18 | |
| 19 | #ifndef UNICODE |
| 20 | #define UNICODE |
| 21 | #endif |
| 22 | |
| 23 | #ifdef UNICODE |
| 24 | #define _UNICODE |
| 25 | #endif |
| 26 | |
| 27 | #if defined(Q_OS_WIN) || defined(Q_OS_MAC) |
| 28 | #include "MediaInfoDLL/MediaInfoDLL.h" //Dynamicly-loaded library (.dll or .so) |
| 29 | #define MediaInfoNameSpace MediaInfoDLL; |
| 30 | #else |
| 31 | #include "MediaInfo/MediaInfo.h" //Staticly-loaded library (.lib or .a or .so) |
| 32 | #define MediaInfoNameSpace MediaInfoLib; |
| 33 | #endif |
| 34 | using namespace MediaInfoNameSpace; |
| 35 | |
| 36 | const Maybe<MovieInfo> LibmediainfoMovieInfoProvider::getMovieInfo( |
| 37 | const QString& moviePath) const { |
| 38 | MediaInfo mi; |
| 39 | mi.Option(__T("Internet"), __T("No")); |
| 40 | |
| 41 | mi.Open(moviePath.toStdWString()); |
| 42 | |
| 43 | #define GET_VIDEO_INFO(__streamIdx, __key) \ |
| 44 | QString::fromStdWString( \ |
| 45 | std::wstring(mi.Get(Stream_Video, __streamIdx, __T(__key), Info_Text))) |
| 46 | |
| 47 | QString widthS = GET_VIDEO_INFO(0, "Width"); |
| 48 | QString heightS = GET_VIDEO_INFO(0, "Height"); |
| 49 | QString frameRateS = GET_VIDEO_INFO(0, "FrameRate"); |
| 50 | QString durationS = GET_VIDEO_INFO(0, "Duration"); |
| 51 | |
| 52 | mi.Close(); |
| 53 | |
| 54 | QRegExp rWidth("(\\d+)"); |
| 55 | if (rWidth.indexIn(widthS) == -1) return nothing(); |
| 56 | |
| 57 | QRegExp rHeight("(\\d+)"); |
| 58 | if (rHeight.indexIn(heightS) == -1) return nothing(); |
| 59 | |
| 60 | QRegExp rFrameRate("(\\d+).(\\d+)"); |
| 61 | if (rFrameRate.indexIn(frameRateS) == -1) return nothing(); |
| 62 | long frFloor = rFrameRate.cap(1).toLong(); |
| 63 | long frFrac = rFrameRate.cap(2).toLong(); |
| 64 | |
| 65 | QRegExp rDuration("(\\d+)"); |
| 66 | if (rDuration.indexIn(durationS) == -1) return nothing(); |
| 67 | |
| 68 | MovieInfo info(rWidth.cap(1).toInt(), rHeight.cap(1).toInt(), |
| 69 | (double)frFloor + (double)frFrac / 1000.0, |
| 70 | rDuration.cap(1).toDouble() / 1000.0); |
| 71 | |
| 72 | return just<MovieInfo>(info); |
| 73 | } |